<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rwec.co.uk &#187; switch</title>
	<atom:link href="http://rwec.co.uk/blog/tag/switch/feed/" rel="self" type="application/rss+xml" />
	<link>http://rwec.co.uk/blog</link>
	<description>Rowan&#039;s World, Et Cetera</description>
	<lastBuildDate>Wed, 25 Apr 2012 08:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>The Case for a better Switch</title>
		<link>http://rwec.co.uk/blog/2009/08/the-case-for-a-better-switch/</link>
		<comments>http://rwec.co.uk/blog/2009/08/the-case-for-a-better-switch/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 17:29:34 +0000</pubDate>
		<dc:creator>Rowan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://rwec.co.uk/blog/?p=26</guid>
		<description><![CDATA[The C-style switch-case construct - used in various programming languages, including PHP - is a curious beast. Most commonly used as a streamlined form of if-elseif-else, it actually has more in common with the oldest of control statements, the goto, since control jumps to the first match and carries on until you tell it to [...]]]></description>
			<content:encoded><![CDATA[<p>The C-style <code>switch-case</code> construct - used in various programming languages, including PHP - is a curious beast. Most commonly used as a streamlined form of <code>if-elseif-else</code>, it actually has more in common with the oldest of control statements, the <code>goto</code>, since control jumps to the first match <em>and carries on until you tell it to stop</em>.</p>
<p>Firstly, am I the only person in the world who thinks that the <code>break</code> should be indented to the same level as the <code>case</code>, not the level of the commands between? If you <strong>are</strong> using it as a series of separate <code>elseif</code> blocks, then surely the two form a matching pair, with the code block "enclosed" within them. Of course, you can generally <code>break</code> early inside the code, just like you can <code>return</code> early from a function, which is hard to make stand out - but that's just an argument not to do it too often!</p>
<p>And, of course, the fact that another <code>case</code> comes along <strong>does not</strong> mean that the code won't carry on. Which brings me neatly to my next thought: is there any language that insists you declare when you're falling through to the next case - and if not, why not? What if every time you put a <code>case</code>, you had to end it with either a <code>break</code> or a <code>continue</code>? It seems to me it would prevent a lot of bugs caused by cases <em>inadvertently</em> falling through and running completely the wrong code. And if overloading an existing term like <code>continue</code> is too confusing, lets just have a <code>fallthrough</code> - anyone got a case against? [No pun intended; probably...]</p>
]]></content:encoded>
			<wfw:commentRss>http://rwec.co.uk/blog/2009/08/the-case-for-a-better-switch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

