<?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>Paul Osman &#187; Rants</title>
	<atom:link href="http://blog.eval.ca/category/rants/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.eval.ca</link>
	<description>Thoughts on Software and Other Things</description>
	<lastBuildDate>Wed, 07 Jul 2010 18:56:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Bad Signs &#8211; PHP&#8217;s &#8220;Shut Up&#8221; (@) Operator</title>
		<link>http://blog.eval.ca/2009/01/04/bad-signs-phps-shut-up-operator/</link>
		<comments>http://blog.eval.ca/2009/01/04/bad-signs-phps-shut-up-operator/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 03:22:21 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://blog.paulosman.com/?p=40</guid>
		<description><![CDATA[Derick Rethans has a post about PHP&#8217;s &#8220;shut-up&#8221; operator (@) and why it should be avoided. He outlines a fairly common debugging scenario and gives some &#8220;under-the-hood&#8221; explanations on why that particular operator sucks. I couldn&#8217;t agree more (that it should be avoided) and I want to go further and talk about something that has [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://derickrethans.nl">Derick Rethans</a> has a <a href="http://derickrethans.nl/five_reasons_why_the_shutop_operator_@_should_be_avoided.php">post</a> about PHP&#8217;s &#8220;shut-up&#8221; operator (@) and why it should be avoided. He outlines a fairly common debugging scenario and gives some &#8220;under-the-hood&#8221; explanations on why that particular operator sucks. I couldn&#8217;t agree more (that it should be avoided) and I want to go further and talk about something that has always bugged me about that operator. In my opinion, it&#8217;s a hackish, band-aid fix to a much larger, much more worrisome problem: horrendous API design.</p>
<p>First, a disclaimer. I know that there are some historical reasons for a lot of these things (i.e. Exceptions not appearing until PHP5) but that doesn&#8217;t change the current reality. Consider for instance filesystem functions in the standard extension:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/tmp/file.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If the file &#8220;/tmp/file.txt&#8221; does not exist, depending on your php.ini settings (because display_errors should always be &#8216;Off&#8217; on production systems), you may get something similar to the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">Warning: file(/tmp/file.txt) [function.file]: failed to open stream: No such file or directory in /path/to/your/docroot/test.php on line 3</pre></div></div>

<p>Now the proper thing to do of course would be to verify up front that the file exists and is readable with a call to <a href="http://php.net/is_readable">is_readable()</a> or something similar, but imagine this is a case where there is no way to determine ahead of time if a warning or error will be generated (Derick mentions silencing network errors with <a href="http://php.net/stream_socket_client">stream_socket_client()</a> as one example). In this case, you might be tempted to use the shut-up operator and depend on the return value as the one true way to see if something was succesful or not.</p>
<p>Now compare this with what languages like Python (for example) do, If you were to write similar code in Python:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">fp = <span style="color: #008000;">file</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/tmp/file.txt&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>If the file did not exist, you&#8217;ll get an IOError which, if left uncaught, will result in the following being written to standard error:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">Traceback (most recent call last):
  File &quot;test.py&quot;, line 1, in &lt;module&gt;
IOError: [Errno 2] No such file or directory: '/tmp/test.txt'</pre></div></div>

<p>The difference here of course is that an IOError can be caught, ignored or whatever best suits your needs. It&#8217;s a part of the language, the API is not just spewing out garbage to standard output or standard error. More importantly, having a function (or technically a constructor) like file() throw an exception follows a consistent design philosophy whereas PHP&#8217;s error system always leaves me guessing or consulting the docs.</p>
<p>I guess what I&#8217;m saying is that I think the shut-up operator is just one of those signs that PHP is suffering from some serious cruft and I don&#8217;t think those kinds of things bode well for a language.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eval.ca/2009/01/04/bad-signs-phps-shut-up-operator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What drove me away from Apple</title>
		<link>http://blog.eval.ca/2008/11/30/what-drove-me-away-from-apple/</link>
		<comments>http://blog.eval.ca/2008/11/30/what-drove-me-away-from-apple/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 17:32:39 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://blog.paulosman.com/?p=38</guid>
		<description><![CDATA[I recently replaced my Macbook Pro with a Thinkpad x200 running Arch Linux and Windows Vista. After 5 years of using Apple products I decided to switch &#8211; to borrow one of their marketing terms &#8211; because frankly, I was sick of being abused as a customer and the lock-in was making me less and [...]]]></description>
			<content:encoded><![CDATA[<p>I recently replaced my Macbook Pro with a Thinkpad x200 running Arch Linux and Windows Vista. After 5 years of using Apple products I decided to switch &ndash; to borrow one of their marketing terms &ndash; because frankly, I was sick of being abused as a customer and the lock-in was making me less and less comfortable. Here&#8217;s a list of the things that really did it for me:</p>
<ul>
<li>Pricing the Macbook Air so high with such low specs.</li>
<li>Releasing an pitiful update to the air along with a nice $100 price increase.</li>
<li>Doing away with the matte screen option.</li>
<li>Pulling the remotes from being included with laptops (admittedly not a huge deal, but felt like salt on a wound).</li>
</ul>
<p>Is it just me or is Apple becoming a little too arrogant? Anyway, I know Lenovo won&#8217;t be saints either, but at least in the non-Mac OS X world I can easily switch vendors down the road if I ever need to.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eval.ca/2008/11/30/what-drove-me-away-from-apple/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
