<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>W's blag</title>
	<link>http://blag.w-wins.com</link>
	<description>Synergizer of the blagohypersphere, enterprise edition.</description>
	<pubDate>Sat, 01 Aug 2009 13:22:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>
	<language>en</language>
			<item>
		<title>Good mail client wanted</title>
		<link>http://blag.w-wins.com/?p=53</link>
		<comments>http://blag.w-wins.com/?p=53#comments</comments>
		<pubDate>Sat, 01 Aug 2009 13:22:59 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>How the world should be</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=53</guid>
		<description><![CDATA[I&#8217;m looking for a mail client to use, that has a bare minimum of features;

The ability to retrieve mail from POP3 (while leaving the mail on the server) and IMAP.
Display of plain-text email, ability to save attachments.
The ability to enter the from-address in a text field (and not a drop-down from a list, even if [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m looking for a mail client to use, that has a bare minimum of features;</p>
<ul>
<li>The ability to retrieve mail from POP3 (while leaving the mail on the server) and IMAP.</li>
<li>Display of plain-text email, ability to save attachments.
<li>The ability to enter the from-address in a text field (and not a drop-down from a list, even if that list is editable) when sending email.</li>
<li>The ability to display mail in a graphical table view, sortable on received date, sender, topic.</li>
<li>The ability to store mail client-side in a tree-like/directory structure, with rules to decide which mail goes to which node.</li>
<li>The ability to see, and filter on, the actual target email from the trusted Received: header (IE the email address used in the RCPT command to the trusted SMTP, not the envelope target) preferably without having to manually eyeball it out of the headers of the emails.</li>
<li>The ability to block/ HTML and images in incoming mail.</li>
</ul>
<p>Please suggest to me mail clients that fulfil ALL of these requirements. Register and comment on this post, or send suggestions to <a href="mailto:mailclients@w-wins.com"></p>
<address>mailclients@w-wins.com</address>
<p></a> (or let me know on IRC or Facebook if you know me there).</p>
<p>Things that would be nice to have in addition:</p>
<ul>
<li>Free and open source.</p>
<ul>
<li>Written in Java</li>
</ul>
</li>
<li>Listed with each mail: the server, protocol, and username used to download it.</li>
<li>Simple scripting interface.</li>
<li>RSS support</li>
<li>User-friendly encrypted and signed email support.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=53</wfw:commentRss>
		</item>
		<item>
		<title>Obama the liar</title>
		<link>http://blag.w-wins.com/?p=52</link>
		<comments>http://blag.w-wins.com/?p=52#comments</comments>
		<pubDate>Fri, 15 May 2009 22:05:23 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>IRC</category>

		<category>I win</category>

		<category>Civil liberties</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=52</guid>
		<description><![CDATA[One morning on IRC;

[06:56] [_W_] Bjorn, but who cares if you get to remove one liar if you&#8217;re just replacing him with another?
[06:56] &#60;Bjorn&#62; I don&#8217;t think obama is a liar
[06:57] &#60;Bjorn&#62; I think clinton was a liar but that didn&#8217;t bother me then
[06:57] &#60;Bjorn&#62; he bothers me now though
[06:57] [_W_] Bjorn, are you really [...]]]></description>
			<content:encoded><![CDATA[<p>One morning on IRC;</p>
<blockquote><p>
[06:56] [_W_] Bjorn, but who cares if you get to remove one liar if you&#8217;re just replacing him with another?<br />
[06:56] &lt;Bjorn&gt; I don&#8217;t think obama is a liar<br />
[06:57] &lt;Bjorn&gt; I think clinton was a liar but that didn&#8217;t bother me then<br />
[06:57] &lt;Bjorn&gt; he bothers me now though<br />
[06:57] [_W_] Bjorn, are you really that blind?<br />
[06:57] &lt;Bjorn&gt; see we settled for clinton then because there wasn&#8217;t anything better<br />
[06:57] &lt;Bjorn&gt; _W_: blind to what?<br />
[06:57] &lt;Bjorn&gt; you think Obama is a liar?<br />
[06:58] [_W_] absolutely<br />
[06:58] &lt;Bjorn&gt; well, I disagree<br />
[06:58] &lt;Bjorn&gt; whole heartedly<br />
[06:58] [_W_] as is anyone likely to get even close to a presidential nomination<br />
[06:58] &lt;Bjorn&gt; I think anyone who thinks he is a liar is either ignorant or jaded<br />
[06:58] [_W_] Bjorn, you&#8217;ll see
</p>
</blockquote>
<p>One of Obama&#8217;s pledges (<a href="http://www.barackobama.com/2007/08/01/the_war_we_need_to_win.php">http://www.barackobama.com/2007/08/01/the_war_we_need_to_win.php</a>)</p>
<blockquote><p>
As President, I will close Guantanamo, reject the Military Commissions Act, and adhere to the Geneva Conventions. Our Constitution and our Uniform Code of Military Justice provide a framework for dealing with the terrorists.
</p>
</blockquote>
<p><a href="http://en.wikipedia.org/wiki/Habeas_corpus">http://en.wikipedia.org/wiki/Habeas_corpus</a></p>
<p>Obama on prosecuting for torture (<a href="http://www.philly.com/philly/blogs/attytood/Barack_on_torture.html">http://www.philly.com/philly/blogs/attytood/Barack_on_torture.html</a>)</p>
<blockquote><p>
&#8230;if crimes have been committed, they should be investigated.
</p>
</blockquote>
<p><a href="http://en.wikipedia.org/wiki/Nuremberg_Principles">http://en.wikipedia.org/wiki/Nuremberg_Principles</a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=52</wfw:commentRss>
		</item>
		<item>
		<title>Gay rights, and rational debate</title>
		<link>http://blag.w-wins.com/?p=50</link>
		<comments>http://blag.w-wins.com/?p=50#comments</comments>
		<pubDate>Wed, 06 May 2009 22:29:17 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>How the world should be</category>

		<category>Sexuality</category>

		<category>Civil liberties</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=50</guid>
		<description><![CDATA[I feel the need to address a couple of stupid irrational ideas that keep popping up when it comes to debates about gay marriage and gay rights. I use &#8220;gay&#8221; and &#8220;homosexual&#8221; as simplified terms for anyone with preferences outside plain heterosexuality, including bisexuals, transgenders, and so on.
First the idea gay rights depends on sexual [...]]]></description>
			<content:encoded><![CDATA[<p>I feel the need to address a couple of stupid irrational ideas that keep popping up when it comes to debates about gay marriage and gay rights. I use &#8220;gay&#8221; and &#8220;homosexual&#8221; as simplified terms for anyone with preferences outside plain heterosexuality, including bisexuals, transgenders, and so on.</p>
<p>First the idea gay rights depends on sexual preference being a determined trait and not a choice. &#8220;It&#8217;s not a choice&#8221; is sometimes used as a blanket defense against homosexuality being a sin, or being immoral. If you suggest that sexual preference might be a choice, or that the evidence isn&#8217;t compelling either way, you are often opposed by people that assume you are going to argue that since it might be a choice, we should try to decrease the number of homosexuals, or are told to not promote that line of thinking to give religious fundamentalists more fuel for their arguments. But this is dishonest thinking. Whether sexual preference is a choice or not doesn&#8217;t affect what rights homosexuals should have. So what if it is a choice? Homosexuality harms no one. It is not something to be fought or eliminated. I would rather Christian and Muslim fundamentalists thought I were doing wrong, and engaged me in rational debate to try to convince me, rather than think me ill or damaged, to be fixed, rather than reasoned with. Gay rights stands on its own merits, and homosexuality does not need excuses.</p>
<p>Next the slippery slope argument. And this goes both ways. There&#8217;s a lot of people saying that if we allow gay marriage, we must allow polygamy, and acts of bestiality, incest, pedophilia, and so on. That many of the arguments for gay rights are at their core arguments for sexual freedom of many kinds. On that last, <em>they are right!</em> But that in and of itself is not an argument against gay rights. If an argument seems to apply to both gay marriage and polygamy, that does not mean that all the arguments that might exist against polygamy are applicable to gay marriage. If you think polygamy is wrong and should be fought against, and someone makes an argument for gay marriage that might also apply to polygamy, you should not fight the argument on that basis, but find your arguments against polygamy, and see if they are applicable to gay marriage as well! But more importantly, gay rights proponents should not shy away from other sexual freedoms merely because they don&#8217;t want public opinion against themselves. Rational debate must come first, and using dishonest and irrational argumentation only hurts the cause in the long run. If someone says &#8220;if we allow gay marriage, why not pedophilia as well?&#8221; a good answer is &#8220;because children can&#8217;t consent, while homosexuals can&#8221;, not vague or misleading arguments like &#8220;there is no slippery slope&#8221; &#8220;those are two different things&#8221; or emotive arguments like &#8220;are you comparing me do a pedophile?!&#8221; At the same time we have to be open to the idea that if society is (or have been) wrong about homosexuality, it might be wrong about incest, or polygamy, as well. Each step has to be argued on its own, without conflating the various liberties into one.</p>
<p>And last one that is unique to gay rights opponents. Parenting, and a child&#8217;s rights. There&#8217;s a lot of arguments these days that a child needs both a mother and a father, and that just two parents of the same gender isn&#8217;t enough. Or that we don&#8217;t know enough about how same-gendered parents affect children, so we shouldn&#8217;t experiment. There are several problems with this kind of thinking. The first is that all these arguments apply equally to either single parents, be it divorced parents, an unknown father, or even a widow or widower; economically poor parents; or foster or adopting parents. There is no argument for allowing these kind of parents that does not equally argue for allowing same-sexed parents. The other is that <em>all</em> parenting is a gamble. There is <em>never</em> any guarantee that parents will raise their kid well. I bet every single parent feel the fear that they won&#8217;t be doing right by child, and an uncertainty of how their child will turn out despite their efforts. There is no deterministic &#8220;good parent&#8221; button, and especially not one that heterosexual couples have exclusive access to. Every single child raised is an experiment.
</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=50</wfw:commentRss>
		</item>
		<item>
		<title>Beware of Google Chrome, for it owns all your content</title>
		<link>http://blag.w-wins.com/?p=49</link>
		<comments>http://blag.w-wins.com/?p=49#comments</comments>
		<pubDate>Tue, 02 Sep 2008 23:36:24 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>Google</category>

		<category>Intellectual property rights</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=49</guid>
		<description><![CDATA[Some hate it, some love it, but almost everyone is blogging about Google Chrome, released today. Personally, I can&#8217;t run it. For one, the &#8220;open source&#8221; variant, Chromium, requires build tools from Microsoft, specifically Visual Studio. I&#8217;m told that it &#8220;almost&#8221; compiles under VC++ express edition, the free variant with just C++ from Microsoft, but [...]]]></description>
			<content:encoded><![CDATA[<p>Some hate it, some love it, but almost everyone is blogging about Google Chrome, released today. Personally, I can&#8217;t run it. For one, the &#8220;open source&#8221; variant, Chromium, requires build tools from Microsoft, specifically Visual Studio. I&#8217;m told that it &#8220;almost&#8221; compiles under VC++ express edition, the free variant with just C++ from Microsoft, but I&#8217;m not about to do two huge downloads just to see what &#8220;almost&#8221; really entails.</p>
<p>So why not just use the windows build, you ask? Well, there&#8217;s the small detail of an EULA you have to agree to. A fairly nasty EULA, in fact. One which grants Google the right to use any of your content that you transmit through, or display on, Google Chrome.</p>
<p>Don&#8217;t believe me? Read the following carefully, quoted from http://www.google.com/chrome/intl/en-GB/eula_text.html</p>
<blockquote><p>
Google Chrome Terms of Service</p>
<p>These Terms of Service apply to <em class="quoteemphasis">the executable code version of Google Chrome</em>. Source code for Google Chrome is available free of charge under open source software licence agreements at http://code.google.com/chromium/terms.html.</p>
<p>1. Your relationship with Google</p>
<p>1.1 Your use of Google’s products, <em class="quoteemphasis">software</em>, services and websites (referred to collectively as <em class="quoteemphasis">the “Services”</em> in this document and excluding any services provided to you by Google under a separate written agreement) is subject to the terms of a legal agreement between you and Google. “Google” means Google Inc., whose principal place of business is at 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States. This document explains how the agreement is made up and sets out some of the terms of that agreement.</p>
<hr />
<p>2. Accepting the Terms</p>
<p>2.1 In order to use the Services, you must first agree to the Terms. You may not use the Services if you do not accept the Terms.</p>
<p>2.2 You can accept the Terms by:</p>
<p>(A) clicking to accept or agree to the Terms, where this option is made available to you by Google in the user interface for any Service; or</p>
<p>(B) by actually using the Services. In this case, you understand and agree that Google will treat your use of the Services as acceptance of the Terms from that point onwards.</p>
<hr />
<p>9. Proprietary rights</p>
<hr />
<p>9.4 <em class="quoteemphasis">Other than the limited licence set forth in Section 11</em>, Google acknowledges and agrees that it obtains no right, title or interest from you (or your licensors) under these Terms in or to any Content that you submit, post, transmit or display on, or through, the Services, including any intellectual property rights that subsist in that Content (whether those rights happen to be registered or not, and wherever in the world those rights may exist). Unless you have agreed otherwise in writing with Google, you agree that you are responsible for protecting and enforcing those rights and that Google has no obligation to do so on your behalf.</p>
<hr />
<p>11. Content licence from you</p>
<p>11.1 You retain copyright and any other rights that you already hold in Content that you submit, post or display on or through the Services. <em class="quoteemphasis">By submitting, posting or displaying the content, you give Google a perpetual, irrevocable, worldwide, royalty-free and non-exclusive licence to reproduce, adapt, modify, translate, publish, publicly perform, publicly display and distribute any Content that you submit, post or display on or through the Services</em>. This licence is for the sole purpose of enabling Google to display, distribute and promote the Services and may be revoked for certain Services as defined in the Additional Terms of those Services.</p>
<p>11.2 You agree that this licence includes a right for Google to make such Content available to other companies, organisations or individuals with whom Google has relationships for the provision of syndicated services and to use such Content in connection with the provision of those services.</p>
<p>11.3 You understand that Google, in performing the required technical steps to provide the Services to our users, may (a) transmit or distribute your Content over various public networks and in various media; and (b) make such changes to your Content as are necessary to conform and adapt that Content to the technical requirements of connecting networks, devices, services or media. You agree that this licence shall permit Google to take these actions.</p>
<p>11.4 You confirm and warrant to Google that you have all the rights, power and authority necessary to grant the above licence.</p>
</blockquote>
<p>Emphasis mine. Seems fairly clear cut to me&#8230; Artists, authors, developers etc. should beware of using Google Chrome for any of their work, even just test-viewing it.</p>
<p>Now, what Google can actually do with their licence, or how they will know what content they actually have a right to, I don&#8217;t know. If I could run their software without agreeing to this EULA, I could probably detect any attempt to call home, and so could thousands of other people, so I doubt they&#8217;re quite that brash about it. But the legal right alone is disturbing.</p>
<h3>Update</h3>
<p>Google has now adknowledged that this was a mistake in adapting an existing EULA, and have removed the offending 11.1 paragraph.</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=49</wfw:commentRss>
		</item>
		<item>
		<title>The chilling effects of copyleft</title>
		<link>http://blag.w-wins.com/?p=48</link>
		<comments>http://blag.w-wins.com/?p=48#comments</comments>
		<pubDate>Sun, 18 May 2008 04:53:40 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>Coding</category>

		<category>How the world should be</category>

		<category>Intellectual property rights</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=48</guid>
		<description><![CDATA[I&#8217;m a programmer. I enjoy writing code, especially reusable software components. I don&#8217;t believe in copyrights, certainly not on software. Code may be written by someone, but it can not, should not, be owned by anyone. Code is maths, and owning code is akin to owning pi, or e, and restricting what kind of thinking [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a programmer. I enjoy writing code, especially reusable software components. I don&#8217;t believe in copyrights, certainly not on software. Code may be written by someone, but it can not, should not, be owned by anyone. Code is maths, and owning code is akin to owning pi, or e, and restricting what kind of thinking other people can do. I think we are way past the point where copyrights hinders innovation, rather than encourage it as originally intended.</p>
<p><a href="http://www.gnu.org/copyleft/copyleft.html"><strong>Copyleft</strong></a> is an idea popularized by GNU and the Free Software Foundation, that claims to work towards ensuring certain freedoms when it comes to software, by publishing software under the GNU General Public License (GPL), that has as one of its main points that <em>derivative works</em> can only be distributed under the same or a compatible license.</p>
<p><strong>The problem</strong> is that people might want to release their source code under a <em>freer</em> license, but also wish to not reinvent code already released under the GPL. The GPL thus cause extra work for the principled  programmer, who will have to laboriously write new code to do exactly the same that the GPL code does, while being careful not to copy, or base the design of the new library, on the old one. In the worst case such a task is too much, and innovation that would otherwise happen fails to come about, and everyone is impoverished as a result.</p>
<p><strong>Richard Stallman</strong> raves against &#8220;software hoarding&#8221;; companies that take some free product, adds in their own innovations, and releases the result with a more restrictive license, commercially. He writes that this makes software less free. Which is just plain wrong. Because if someone takes free software A, improves it, and releases unfree software B, the world has <strong>more freedom</strong>. Software A does not go away, everyone can still use and base their improvements on that piece, ignoring B, but <em>in addition</em> they also have the choice of using B. The company that makes B might not be very nice, they are accepting a gift, and not giving back in turn. But they are still doing some good, they are still innovating. Their ideas, if not their code, can be utilized in free software. (Granted that software patents, an even greater evil than copyrights, don&#8217;t apply.)</p>
<p>The GNU GPL works within current law. It strongly relies on copyrights. To enforce it, the laws and law enforcement mechanisms are utilized. If the copyright laws were weakened, the GPL would lose some of its power. The GPL thus gives programmers who have released under the license an incentive to work towards upholding copyright laws. But copyright laws are inherently dangerous; the law essentially dictates what Joe Hacker and Bob Hacker can do with their own personal property, their own computers. To enforce such a thing, law enforcement must be able to detect when Joe distributes some piece of information to Bob. The transfer might be encrypted for privacy, so now law enforcement has to have a way to force encryption keys from suspects, or encryption must be banned entirely. The transfer might be on a completely private network, so now law enforcement has to have a way to tell when any person is communicating with any other through privately owned equipment, or networks must be forced to register its traffic with authorities, and hidden networks banned. Giving law enforcement such powers, or banning such things, violates basic civil and human rights.</p>
<p>An ethical programmer will avoid assist in maintaining copyrights. He will release the code he writes on his own into the public domain. He will help write libraries that duplicate what GPL and proprietary libraries do, but this time, make them <em>really free</em>. And he will be free to lobby for weakening copyright laws and the enforcement thereof, free to acts of civil disobedience that undermines copyrights, and free to stand up for the basic rights of privacy and presumption of innocence.</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=48</wfw:commentRss>
		</item>
		<item>
		<title>Minimal Pythagorean circles</title>
		<link>http://blag.w-wins.com/?p=46</link>
		<comments>http://blag.w-wins.com/?p=46#comments</comments>
		<pubDate>Sun, 27 Apr 2008 08:22:01 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>Coding</category>

		<category>Maths</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=46</guid>
		<description><![CDATA[Let us define a Pythagorean circle, as a circle in the plane, centered at origin, with one or more points of the circle having both x and y coordinates as integers. Given the symmetry of the situation, the number of such points is divisible by four, so let us divide the number of points by [...]]]></description>
			<content:encoded><![CDATA[<p>Let us define a <em>Pythagorean circle</em>, as a circle in the plane, centered at origin, with one or more points of the circle having both x and y coordinates as integers. Given the symmetry of the situation, the number of such points is divisible by four, so let us divide the number of points by four and call this the <em>degree</em> of the Pythagorean circle. If we have a Pythagorean circle of degree X, where there are no Pythagorean circles with a smaller radius and degree X, we call that a <em>minimal Pythagorean circle</em> for that degree. The radius of such a circle might not be integer, but its radius squared will always be (to find the radius squared, take one of the points with integer x and y, and calculate x^2+y^2, and this will be the radius squared, by simple trigonometry.)</p>
<p>Let us list a few minimal Pythagorean circles, and their radius squared:</p>
<table>
<tr>
<th>R^2</th>
<th>Degree</th>
<th>Points in the first quadrant</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>(0,1)</td>
</tr>
<tr>
<td>5</td>
<td>2</td>
<td>(1,2) (2,1)</td>
</tr>
<tr>
<td>25</td>
<td>3</td>
<td>(0,5) (3,4) (4,3)</td>
</tr>
<tr>
<td>65</td>
<td>4</td>
<td>(1,8) (4,7) (7,4) (8,1)</td>
</tr>
<tr>
<td>625</td>
<td>5</td>
<td>(0,25) (7,24) (15,20) (20,15) (24,7)</td>
</tr>
<tr>
<td>325</td>
<td>6</td>
<td>(1,18) (6,17) (10,15) (15,10) (17,6) (18,1)</td>
</tr>
</table>
<p>Now looking at R^2 you might notice a pattern. Lets see the factorizations of the radius squared of these minimal Pythagorean circles:</p>
<table>
<tr>
<th>Degree</th>
<th>R^2 factorized</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>5</td>
</tr>
<tr>
<td>3</td>
<td>5^2</td>
</tr>
<tr>
<td>4</td>
<td>5*13</td>
</tr>
<tr>
<td>5</td>
<td>5^4</td>
</tr>
<tr>
<td>6</td>
<td>5^2*13</td>
</tr>
<tr>
<td>7</td>
<td>5^6</td>
</tr>
<tr>
<td>8</td>
<td>5*13*17</td>
</tr>
<tr>
<td>9</td>
<td>5^2*13^2</td>
</tr>
<tr>
<td>10</td>
<td>5^4*13</td>
</tr>
<tr>
<td>12</td>
<td>5^2*13*17</td>
</tr>
<tr>
<td>14</td>
<td>5^6*13</td>
</tr>
</table>
<p>Now, the challenges: What is the next prime factor to show itself in this kind of factorization? What is the minimal Pythagorean circle for degree 11 and 13? What is the complete pattern, and is there a formula for finding the minimal Pythagorean circle for a given degree?
</p>
<p>Update: added this diagram of a pythagorean circle of degree 3, with radius squared 25 (and radius 5): <a href="http://blag.w-wins.com/wp-content/uploads/2008/04/pyth.png" class="attachmentlink"><img src="http://blag.w-wins.com/wp-content/uploads/2008/04/pyth.thumbnail.png" title="Pythagorean circle" alt="Pythagorean circle" /></a>
</p>
<p>Update2: a hint is that no sum of two square numbers can be written as 4x+3, where x is integer</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=46</wfw:commentRss>
		</item>
		<item>
		<title>FizzBuzz object oriented</title>
		<link>http://blag.w-wins.com/?p=45</link>
		<comments>http://blag.w-wins.com/?p=45#comments</comments>
		<pubDate>Tue, 15 Apr 2008 16:41:27 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>Coding</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=45</guid>
		<description><![CDATA[An approach I didn&#8217;t use in my last post (well, I did, somewhat, with the enum method) is the object oriented approach. Of course, if we&#8217;re going to make it object oriented, we should strive to write reusable components for any part of it, and to use interfaces when possible. So here it is, in [...]]]></description>
			<content:encoded><![CDATA[<p>An approach I didn&#8217;t use in my last post (well, I did, somewhat, with the enum method) is the object oriented approach. Of course, if we&#8217;re going to make it object oriented, we should strive to write reusable components for any part of it, and to use interfaces when possible. So here it is, in all its glory:</p>
<pre>
<code>
/*
 * This code is written by W (aka Raymond Wold) and is released into the public domain.
 *  - It's not my code, I just wrote it.
 */
package com.w_wins.fizzbuzz;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

public class FizzBuzz implements Runnable{
    private final Facilitator&lt;Integer, String&gt; facilitator;

    public FizzBuzz(){
        final List&lt;ConditionalAdaptor&lt;Integer, String&gt;&gt; list=new ArrayList&lt;ConditionalAdaptor&lt;Integer, String&gt;&gt;();
        final FizzBuzzConditionFactory fizzBuzzConditions=new FizzBuzzConditionFactory();
        list.add(fizzBuzzConditions.generateFizzBuzzAdaptor());
        list.add(fizzBuzzConditions.generateFizzAdaptor());
        list.add(fizzBuzzConditions.generateBuzzAdaptor());
        facilitator=new Facilitator&lt;Integer, String&gt;(list, new ToStringAdaptor&lt;Integer&gt;());
    }

    @Override
    public void run(){
        facilitator.runOn(new IntegerRangeGenerator(1, 100), new Outputter());
    }
}

interface Adaptor&lt;F, T&gt;{
    public T convert(F value);
}

interface Condition&lt;V&gt;{
    public boolean matches(V value);
}

interface ConditionalAdaptor&lt;F, T&gt; extends Adaptor&lt;F, T&gt;,Condition&lt;F&gt;{
}

interface Handler&lt;T&gt;{
    public void handle(T value);
}

class Facilitator&lt;F, T&gt;{
    final List&lt;ConditionalAdaptor&lt;F, T&gt;&gt; conditionalAdaptors;
    final Adaptor&lt;F, T&gt; finalAdaptor;

    public Facilitator(final List&lt;ConditionalAdaptor&lt;F, T&gt;&gt; conditionalAdaptors, final Adaptor&lt;F, T&gt; finalAdaptor){
        this.conditionalAdaptors=conditionalAdaptors;
        this.finalAdaptor=finalAdaptor;
    }

    public void runOn(final Iterator&lt;F&gt; iterator, final Handler&lt;T&gt; handler){
        while(iterator.hasNext())
            handler.handle(runAdaptors(iterator.next()));
    }

    public T runAdaptors(final F value){
        for(ConditionalAdaptor&lt;F, T&gt; adaptor : conditionalAdaptors)
            if(adaptor.matches(value)) {
                return adaptor.convert(value);
            }
        return finalAdaptor.convert(value);
    }
}

class ConditionConditionalAdaptor&lt;F, T&gt; implements ConditionalAdaptor&lt;F, T&gt;{
    private final Condition&lt;F&gt; condition;
    private final Adaptor&lt;F, T&gt; adaptor;

    public ConditionConditionalAdaptor(final Condition&lt;F&gt; condition, final Adaptor&lt;F, T&gt; adaptor){
        this.condition=condition;
        this.adaptor=adaptor;
    }

    @Override
    public boolean matches(F value){
        return condition.matches(value);
    }

    @Override
    public T convert(F value){
        return adaptor.convert(value);
    }
}

class AndCondition&lt;V&gt; implements Condition&lt;V&gt;{
    final List&lt;Condition&lt;V&gt;&gt; conditions;

    public AndCondition(final Condition&lt;V&gt; a, final Condition&lt;V&gt; b){
        conditions=new ArrayList&lt;Condition&lt;V&gt;&gt;();
        conditions.add(a);
        conditions.add(b);
    }

    public AndCondition(final List&lt;Condition&lt;V&gt;&gt; conditions){
        this.conditions=conditions;
    }

    public AndCondition(final Condition&lt;V&gt;[] conditions){
        this.conditions=Arrays.asList(conditions);
    }

    @Override
    public boolean matches(V value){
        for(Condition&lt;V&gt; condition : conditions)
            if(!condition.matches(value)){
                return false;
            }
        return true;
    }
}

class FizzBuzzConditionFactory{
    private static final String FIZZ="Fizz",  BUZZ="Buzz";
    private final Condition&lt;Integer&gt; fizzCondition,  buzzCondition;

    public FizzBuzzConditionFactory(){
        fizzCondition=new IntegerDivisibleBy(3);
        buzzCondition=new IntegerDivisibleBy(5);
    }

    public ConditionalAdaptor&lt;Integer, String&gt; generateFizzBuzzAdaptor(){
        return new ConditionConditionalAdaptor&lt;Integer, String&gt;(new AndCondition&lt;Integer&gt;(fizzCondition, buzzCondition), new FixedStringAdaptor&lt;Integer&gt;(FIZZ+BUZZ));
    }

    public ConditionalAdaptor&lt;Integer, String&gt; generateFizzAdaptor(){
        return new ConditionConditionalAdaptor&lt;Integer, String&gt;(fizzCondition, new FixedStringAdaptor&lt;Integer&gt;(FIZZ));
    }

    public ConditionalAdaptor&lt;Integer, String&gt; generateBuzzAdaptor(){
        return new ConditionConditionalAdaptor&lt;Integer, String&gt;(buzzCondition, new FixedStringAdaptor&lt;Integer&gt;(BUZZ));
    }
}

class FixedStringAdaptor&lt;T&gt; implements Adaptor&lt;T, String&gt;{
    private final String string;

    public FixedStringAdaptor(String string){
        this.string=string;
    }

    @Override
    public String convert(T value){
        return string;
    }
}

class IntegerDivisibleBy implements Condition&lt;Integer&gt;{
    private final int modulo;

    public IntegerDivisibleBy(final int modulo){
        this.modulo=modulo;
    }

    @Override
    public boolean matches(Integer value){
        return value%modulo==0;
    }
}

class ToStringAdaptor&lt;T&gt; implements Adaptor&lt;T, String&gt;{
    @Override
    public String convert(T value){
        return value.toString();
    }
}

class IntegerRangeGenerator implements Iterator&lt;Integer&gt;{
    private int current;
    private final int end;

    public IntegerRangeGenerator(final int fromInclusive, final int toInclusive){
        this.current=fromInclusive;
        this.end=toInclusive;
    }

    @Override
    public boolean hasNext(){
        return current&lt;=end;
    }

    @Override
    public Integer next(){
        if(!hasNext()) {
            throw new NoSuchElementException();
        }
        return current++;
    }

    @Override
    public void remove(){
        throw new UnsupportedOperationException("The integers are a fixed set");
    }
}

class Outputter implements Handler&lt;String&gt;{
    @Override
    public void handle(final String value){
        System.out.println(value);
    }
}
</code>
</pre>
</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=45</wfw:commentRss>
		</item>
		<item>
		<title>FizzBuzz code</title>
		<link>http://blag.w-wins.com/?p=43</link>
		<comments>http://blag.w-wins.com/?p=43#comments</comments>
		<pubDate>Sat, 12 Apr 2008 11:37:19 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>Coding</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=43</guid>
		<description><![CDATA[And no, it&#8217;s not to be taken seriously.
package&#160;com.w_wins.fizzbuzz;
import&#160;java.util.HashMap;
import&#160;java.util.Map;
import&#160;java.util.concurrent.Callable;
import&#160;java.util.concurrent.ExecutionException;
import&#160;java.util.concurrent.ExecutorService;
import&#160;java.util.concurrent.Executors;
import&#160;java.util.concurrent.Future;
import&#160;java.util.concurrent.FutureTask;
/**
&#160;*&#160;@author&#160;W
&#160;*/
public&#160;class&#160;Main&#160;{
&#160;&#160;&#160;&#160;public&#160;static&#160;void&#160;main(String[]&#160;args)&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;try&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;fizzbuzz1();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;fizzbuzz2();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;fizzbuzz3();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;fizzbuzz4();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;fizzbuzz5();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}&#160;catch&#160;(Exception&#160;ex)&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ex.printStackTrace();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;public&#160;static&#160;void&#160;fizzbuzz1()&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;final&#160;String[]&#160;fizzBuzz=new&#160;String[15];
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;fizzBuzz[0]="FizzBuzz";
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for(int&#160;t=1;t]]></description>
			<content:encoded><![CDATA[<p>And no, it&#8217;s not to be taken seriously.<br />
<code>package&nbsp;com.w_wins.fizzbuzz;</p>
<p>import&nbsp;java.util.HashMap;<br />
import&nbsp;java.util.Map;<br />
import&nbsp;java.util.concurrent.Callable;<br />
import&nbsp;java.util.concurrent.ExecutionException;<br />
import&nbsp;java.util.concurrent.ExecutorService;<br />
import&nbsp;java.util.concurrent.Executors;<br />
import&nbsp;java.util.concurrent.Future;<br />
import&nbsp;java.util.concurrent.FutureTask;</p>
<p>/**<br />
&nbsp;*&nbsp;@author&nbsp;W<br />
&nbsp;*/<br />
public&nbsp;class&nbsp;Main&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fizzbuzz1();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fizzbuzz2();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fizzbuzz3();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fizzbuzz4();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fizzbuzz5();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(Exception&nbsp;ex)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ex.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;fizzbuzz1()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;String[]&nbsp;fizzBuzz=new&nbsp;String[15];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fizzBuzz[0]="FizzBuzz";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;t=1;t<5;++t)fizzBuzz[t*3]="Fizz";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;t=1;t<3;++t)fizzBuzz[t*5]="Buzz";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;t=1;t<=100;++t)System.out.println(fizzBuzz[t%15]==null?Integer.toString(t):fizzBuzz[t%15]);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;fizzbuzz2()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;t=1;t<=100;++t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;boolean&nbsp;number=true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(t%3==0){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;number=false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print("Fizz");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(t%5==0){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;number=false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print("Buzz");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(number?t:"");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;fizzbuzz3()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;t=1;t<=100;++t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(t%15){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;2:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;4:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;7:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;8:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;11:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;13:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;14:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(t);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;6:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;9:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;12:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Fizz");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print("Fizz");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;5:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;10:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Buzz");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;fizzbuzz4()&nbsp;throws&nbsp;InterruptedException,&nbsp;ExecutionException&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;ExecutorService&nbsp;service=Executors.newCachedThreadPool();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;Map<Integer,Future<String>>&nbsp;futures=new&nbsp;HashMap<Integer,Future<String>>(100);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;d=1;d<=100;++d){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;int&nbsp;t=d;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;FutureTask<String>&nbsp;future=new&nbsp;FutureTask<String>(new&nbsp;Callable<String>()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;String&nbsp;call()&nbsp;throws&nbsp;Exception&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(t%15==0)return&nbsp;&#8221;FizzBuzz&#8221;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(t%3==0)return&nbsp;&#8221;Fizz&#8221;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(t%5==0)return&nbsp;&#8221;Buzz&#8221;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;Integer.toString(t);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service.submit(future);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;futures.put(t,future);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;t=1;t<=100;++t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(futures.get(t).get());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;boolean&nbsp;isEmpty=service.shutdownNow().isEmpty();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert(isEmpty);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;enum&nbsp;FizzBuzz{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FIZZBUZZ(true,true,false){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;boolean&nbsp;matches(final&nbsp;int&nbsp;t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;t%15==0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},FIZZ(true,false,false){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;boolean&nbsp;matches(final&nbsp;int&nbsp;t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;t%3==0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},BUZZ(false,true,false){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;boolean&nbsp;matches(final&nbsp;int&nbsp;t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;t%5==0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},NUMBER(false,false,true){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;boolean&nbsp;matches(final&nbsp;int&nbsp;t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;final&nbsp;boolean&nbsp;fizz,buzz,number;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;abstract&nbsp;boolean&nbsp;matches(int&nbsp;t);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FizzBuzz(final&nbsp;boolean&nbsp;fizz,final&nbsp;boolean&nbsp;buzz,final&nbsp;boolean&nbsp;number){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.fizz=fizz;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.buzz=buzz;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.number=number;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;printNumber(final&nbsp;int&nbsp;t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(fizz)System.out.print("Fizz");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(buzz)System.out.print("Buzz");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(number)System.out.print(t);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;FizzBuzz&nbsp;getFizzBuzz(final&nbsp;int&nbsp;t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(FizzBuzz&nbsp;fizzBuzz:FizzBuzz.values()){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(fizzBuzz.matches(t)){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;fizzBuzz;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;Error("Can't&nbsp;happen");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;fizzbuzz5()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;t=1;t<=100;++t){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FizzBuzz.getFizzBuzz(t).printNumber(t);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</code><br />
<a href="http://blag.w-wins.com/wp-content/uploads/2008/04/profiled.png" class="attachmentlink"><img src="http://blag.w-wins.com/wp-content/uploads/2008/04/profiled.thumbnail.png" title="Profiling results of FizzBuzz" alt="fizzbuzz4() 52.4ms, fizzbuzz5() 29.0ms, fizzbuzz3() 25.7ms, fizzbuzz2() 19.6ms, fizzbuzz1() 19.5ms" /></a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=43</wfw:commentRss>
		</item>
		<item>
		<title>Extemporanea</title>
		<link>http://blag.w-wins.com/?p=40</link>
		<comments>http://blag.w-wins.com/?p=40#comments</comments>
		<pubDate>Mon, 26 Nov 2007 06:10:44 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>Life</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=40</guid>
		<description><![CDATA[As quoted in the latest book I&#8217;m reading &#8220;A princess of Roumania&#8221;:

Comment

Oh life is a glorious cycle of song,
A medley of extemporanea;
And love is a thing that can never go wrong:
And I am Marie of Roumania.

--Dorothy Parker
]]></description>
			<content:encoded><![CDATA[<p>As quoted in the latest book I&#8217;m reading &#8220;A princess of Roumania&#8221;:<br/></p>
<pre>
Comment

Oh life is a glorious cycle of song,
A medley of extemporanea;
And love is a thing that can never go wrong:
And I am Marie of Roumania.

--Dorothy Parker</pre>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=40</wfw:commentRss>
		</item>
		<item>
		<title>Cargo cult prefixes</title>
		<link>http://blag.w-wins.com/?p=39</link>
		<comments>http://blag.w-wins.com/?p=39#comments</comments>
		<pubDate>Mon, 03 Sep 2007 21:31:55 +0000</pubDate>
		<dc:creator>W</dc:creator>
		
		<category>Coding</category>

		<category>How the world should be</category>

		<guid isPermaLink="false">http://blag.w-wins.com/?p=39</guid>
		<description><![CDATA[XML is neat. I like it very much, and get to use it quite a bit at work. I especially like JAXB, Java&#8217;s binding system, which has a very useful tool, XJC, the XML to Java Compiler. What it does is take an XSD, that is, a W3C XML Schema file, describing the structure and [...]]]></description>
			<content:encoded><![CDATA[<p>XML is neat. I like it very much, and get to use it quite a bit at work. I especially like JAXB, Java&#8217;s binding system, which has a <em>very</em> useful tool, XJC, the XML to Java Compiler. What it does is take an XSD, that is, a W3C XML Schema file, describing the structure and data types of an XML document format, and turns it into annotated Java classes. These classes can then be used by JAXB&#8217;s unmarshalling system to turn any XML file matching this document format, into a set of instance of these classes.</p>
<p>With some utility classes to wrap things up neatly, the code to read in, say, an XML configuration file, is as easy as this:</p>
<pre><code>
public void main(String[] args){
    Configuration config=new Unmarshaller&lt;Configuration&gt;("config.xsd",Config.class).unmarshall();
    Socket socket=new Socket(config.getHostname(),config.getPort());
    for(Configuration.User user:config.getUser()){
        // Do something with the user object....
    }
}
</code></pre>
<p><em>Anyway</em>, Java was not what I was going to write about. It&#8217;s just that coding Java, and being reliant on XSD files, I get into contact with some of them written by others. Whether it&#8217;s people wanting help on IRC channels I frequent, or a partner system at work that my code has to interface with, I have to read the schema and try to understand it. To get to my point, let me show you two examples.</p>
<h3>First example</h3>
<pre><code>
&lt;?xml version="1.0"?&gt;
&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified"&gt;

&lt;xs:element name="note"&gt;
    &lt;xs:complexType&gt;
      &lt;xs:sequence&gt;
	&lt;xs:element name="to" type="xs:string"/&gt;
	&lt;xs:element name="from" type="xs:string"/&gt;
	&lt;xs:element name="heading" type="xs:string"/&gt;
	&lt;xs:element name="body" type="xs:string"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
&lt;/xs:element&gt;

&lt;/xs:schema&gt;
</code></pre>
<h3>Second example</h3>
<pre><code>
&lt;?xml version="1.0"?&gt;
&lt;schema xmlns             ="http://www.w3.org/2001/XMLSchema"
        targetNamespace   ="http://www.w3schools.com"
        elementFormDefault="qualified"&gt;
  &lt;element name="note"&gt;
    &lt;complexType&gt;
      &lt;sequence&gt;
	&lt;element name="to" type="string"/&gt;
	&lt;element name="from" type="string"/&gt;
	&lt;element name="heading" type="string"/&gt;
	&lt;element name="body" type="string"/&gt;
      &lt;/sequence&gt;
    &lt;/complexType&gt;
  &lt;/element&gt;
&lt;/schema&gt;
</code></pre>
<p>The first example is from <a href="http://www.w3schools.com/schema/schema_howto.asp">W3schools schema howto</a>, the second is my improved version. Now, besides the better indentation, what was my main improvement? I removed the prefix for the XMLSchema namespace! This is something I see all over the place. Guides and tutorials all over the net do the same, and newbies mimic it.</p>
<p>XML has <a href="http://www.w3.org/TR/REC-xml-names/#ns-decl">some attributes that start with xmlns</a>; these have a special meaning. xmlns:something=&#8221;http://something.else/&#8221; defines a namespace prefix, &#8220;something&#8221; that is an alias for the namespace &#8220;http://something.else/&#8221;. This is a way to specify what namespace a tag belongs to. When you later write &lt;something:a/&gt; (given that that a is a descendant of the element where you defined the prefix), that declares that the a tag belongs to the &#8220;http://something.else/&#8221; namespace. But it is only <em>a</em> way to specify namespaces. Typing prefixes everywhere gets tiresome, and it makes the text harder to read. And having the text easy to read for a human is one of the key goals of XML, and a great benefit of it. So there&#8217;s an alternative method. You can just say xmlns=&#8221;http://something.else/&#8221; and that tag and <em>every tag within it</em> is of the namespace &#8220;http://something.else/&#8221;! Of course, if you need to mix namespaces, you typically use prefixes. But you can use xmlns for the most prevalent namespace, and the prefixes for the exceptions, or if one namespace set is nested wholly within another, just use the xmlns attribute twice.</p>
<p>So why do people keep asking for help with overly ugly schemas, with documents with a prefix on every single tag? Why do tutorials and guides do the same? I think the problems is merely a lack of understanding of namespaces. People are just doing what the people before them did, without an understanding of WHY those special attributes are what they are, or what those letters before the tag mean. Like the cults that have given cargo cult programming their name, they are merely copying the visible efforts that seem to give the right results, without an understanding of what makes them work.</p>
<p>Don&#8217;t be that way. Namespaces might be more complex than the simplicity of tags and attributes, but they aren&#8217;t <em>that</em> hard to use. Take the time to learn how they work, and how you declare them. Not only will your documents be much more readable and you&#8217;ll be typing less, but you will have learned an important part of what makes XML tick, gained a better understanding of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.w-wins.com/?feed=rss2&amp;p=39</wfw:commentRss>
		</item>
	</channel>
</rss>
