<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Why Can&#8217;t I Switch Around Strings?</title>
	<atom:link href="http://bfish.xaedalus.net/2006/11/why-cant-i-switch-around-strings/feed/" rel="self" type="application/rss+xml" />
	<link>http://bfish.xaedalus.net/2006/11/why-cant-i-switch-around-strings/</link>
	<description>a blog, of sorts</description>
	<lastBuildDate>Wed, 08 Sep 2010 02:23:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Oktal</title>
		<link>http://bfish.xaedalus.net/2006/11/why-cant-i-switch-around-strings/comment-page-1/#comment-568</link>
		<dc:creator>Oktal</dc:creator>
		<pubDate>Sun, 10 Dec 2006 04:17:48 +0000</pubDate>
		<guid isPermaLink="false">http://bfish.xaedalus.net/?p=192#comment-568</guid>
		<description>In C you can only switch on integer types, because I believe it&#039;s implemented as a JMP instruction with a table, or something. *I* know what I&#039;m trying to say, anyway :P

In Java, strings are objects, so you&#039;d need to have some special cunning thing to do it. If it was implemented as loads of isEqual() calls (or whatever it&#039;s called... been too long) then it wouldn&#039;t have any speed benefit over a chain of if/else if&#039;s (the main reason to use switch in C). It could use some sort of tree search, but that would be tough to generalise to classes other than string.

{
option1 =&gt; sub { result1; },
option2 =&gt; sub { result2; }.
option3 =&gt; sub { result3; },
}-&gt;{$inputvalue}-&gt;();

That&#039;s Perl; I think Jonny&#039;s Python thing used basically the same method.</description>
		<content:encoded><![CDATA[<p>In C you can only switch on integer types, because I believe it&#8217;s implemented as a JMP instruction with a table, or something. *I* know what I&#8217;m trying to say, anyway :P</p>
<p>In Java, strings are objects, so you&#8217;d need to have some special cunning thing to do it. If it was implemented as loads of isEqual() calls (or whatever it&#8217;s called&#8230; been too long) then it wouldn&#8217;t have any speed benefit over a chain of if/else if&#8217;s (the main reason to use switch in C). It could use some sort of tree search, but that would be tough to generalise to classes other than string.</p>
<p>{<br />
option1 =&gt; sub { result1; },<br />
option2 =&gt; sub { result2; }.<br />
option3 =&gt; sub { result3; },<br />
}-&gt;{$inputvalue}-&gt;();</p>
<p>That&#8217;s Perl; I think Jonny&#8217;s Python thing used basically the same method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bLaXe</title>
		<link>http://bfish.xaedalus.net/2006/11/why-cant-i-switch-around-strings/comment-page-1/#comment-538</link>
		<dc:creator>bLaXe</dc:creator>
		<pubDate>Fri, 01 Dec 2006 16:01:37 +0000</pubDate>
		<guid isPermaLink="false">http://bfish.xaedalus.net/?p=192#comment-538</guid>
		<description>Well - there&#039;s already a switch statement in Java - but you can only switch around ints (or types which can be cast to ints).

I found that Elharo (the guy who wrote &lt;a href=&quot;http://www.xom.nu&quot; rel=&quot;nofollow&quot;&gt;XOM&lt;/a&gt;) mentioned this when talking about things he would change in Java. At least I&#039;m not the only one :)</description>
		<content:encoded><![CDATA[<p>Well &#8211; there&#8217;s already a switch statement in Java &#8211; but you can only switch around ints (or types which can be cast to ints).</p>
<p>I found that Elharo (the guy who wrote <a href="http://www.xom.nu" rel="nofollow">XOM</a>) mentioned this when talking about things he would change in Java. At least I&#8217;m not the only one :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonny</title>
		<link>http://bfish.xaedalus.net/2006/11/why-cant-i-switch-around-strings/comment-page-1/#comment-535</link>
		<dc:creator>Jonny</dc:creator>
		<pubDate>Fri, 01 Dec 2006 15:17:35 +0000</pubDate>
		<guid isPermaLink="false">http://bfish.xaedalus.net/?p=192#comment-535</guid>
		<description>In all seriousness:  When I was doing some work in python, I was rather upset by its lack of switching and stumbled upon this site:

http://simon.incutio.com/archive/2004/05/07/switch

Simon details how to create switch functionality without a switch function - maybe it&#039;s of help, maybe I&#039;m waaay off on this one :)</description>
		<content:encoded><![CDATA[<p>In all seriousness:  When I was doing some work in python, I was rather upset by its lack of switching and stumbled upon this site:</p>
<p><a href="http://simon.incutio.com/archive/2004/05/07/switch" rel="nofollow">http://simon.incutio.com/archive/2004/05/07/switch</a></p>
<p>Simon details how to create switch functionality without a switch function &#8211; maybe it&#8217;s of help, maybe I&#8217;m waaay off on this one :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bLaXe</title>
		<link>http://bfish.xaedalus.net/2006/11/why-cant-i-switch-around-strings/comment-page-1/#comment-533</link>
		<dc:creator>bLaXe</dc:creator>
		<pubDate>Thu, 30 Nov 2006 17:46:20 +0000</pubDate>
		<guid isPermaLink="false">http://bfish.xaedalus.net/?p=192#comment-533</guid>
		<description>Dude.....lame.....</description>
		<content:encoded><![CDATA[<p>Dude&#8230;..lame&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonny</title>
		<link>http://bfish.xaedalus.net/2006/11/why-cant-i-switch-around-strings/comment-page-1/#comment-532</link>
		<dc:creator>Jonny</dc:creator>
		<pubDate>Thu, 30 Nov 2006 14:11:30 +0000</pubDate>
		<guid isPermaLink="false">http://bfish.xaedalus.net/?p=192#comment-532</guid>
		<description>Not sure what to say, other than this: &lt;a href=&quot;http://youtube.com/watch?v=fhlqY145tpU&quot; rel=&quot;nofollow&quot;&gt;http://youtube.com/watch?v=fhlqY145tpU&lt;/a&gt; should cheer you up :)</description>
		<content:encoded><![CDATA[<p>Not sure what to say, other than this: <a href="http://youtube.com/watch?v=fhlqY145tpU" rel="nofollow">http://youtube.com/watch?v=fhlqY145tpU</a> should cheer you up :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
