<?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/"
	xmlns:series="http://organizeseries.com/"
		>
<channel>
	<title>Comments on: Always Return Something</title>
	<atom:link href="http://www.brandonsavage.net/always-return-something/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandonsavage.net/always-return-something/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=always-return-something</link>
	<description>The personal blog of Brandon Savage. Contains entries of a personal and professional nature focusing on PHP, Apple, LAMP, MySQL and Washington, DC.</description>
	<lastBuildDate>Wed, 15 May 2013 14:54:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.2-alpha</generator>
	<item>
		<title>By: Hikari</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-12877</link>
		<dc:creator>Hikari</dc:creator>
		<pubDate>Wed, 10 Apr 2013 01:45:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-12877</guid>
		<description><![CDATA[I know you already said this article is wrong and I&#039;m commenting before reading the other article.

But SRSLY, a function return should NEVER be used to test if it worked in production code. For that, we have Exceptions!!

In the same way a function consumer may not know if a bad developed function worked if it has no return value, a bad developer may also not bother to test it and use the &quot;error sign value&quot; as if workable data. With Exception we assure consumer will know that something bad happened and there&#039;s no returned data to use, or that his function will also return with the same Exception.

If you expect to do something and it fails, and you know that (an expected error, handled by the software!), and it can&#039;t be bypassed, just throw a meaningful Exception and document it. PHP is bad on handling Exceptions because it doesn&#039;t allow functions to enforce exceptions they may throw and it&#039;s not compiled, therefore we lose a valuable moment to be warned if we don&#039;t catch or rethrow them.

Recently I had to work on a software that was developed by outsource team. It was total junk, even though developed in Java+Servlet, it was full of errors and all Exceptions were being presented by Tomcat to user. It&#039;s VERY frustrating when noobs let unhandled Exceptions show unformatted to users.]]></description>
		<content:encoded><![CDATA[<p>I know you already said this article is wrong and I&#8217;m commenting before reading the other article.</p>
<p>But SRSLY, a function return should NEVER be used to test if it worked in production code. For that, we have Exceptions!!</p>
<p>In the same way a function consumer may not know if a bad developed function worked if it has no return value, a bad developer may also not bother to test it and use the &#8220;error sign value&#8221; as if workable data. With Exception we assure consumer will know that something bad happened and there&#8217;s no returned data to use, or that his function will also return with the same Exception.</p>
<p>If you expect to do something and it fails, and you know that (an expected error, handled by the software!), and it can&#8217;t be bypassed, just throw a meaningful Exception and document it. PHP is bad on handling Exceptions because it doesn&#8217;t allow functions to enforce exceptions they may throw and it&#8217;s not compiled, therefore we lose a valuable moment to be warned if we don&#8217;t catch or rethrow them.</p>
<p>Recently I had to work on a software that was developed by outsource team. It was total junk, even though developed in Java+Servlet, it was full of errors and all Exceptions were being presented by Tomcat to user. It&#8217;s VERY frustrating when noobs let unhandled Exceptions show unformatted to users.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Devon H. O'Dell</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-9133</link>
		<dc:creator>Devon H. O'Dell</dc:creator>
		<pubDate>Wed, 13 Mar 2013 20:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-9133</guid>
		<description><![CDATA[I&#039;d only point out that exceptions were not created to detect errors and should not be used for error handling. They were created to abort in unrecoverable situations. Using exceptions as an error-handling mechanism can be horribly error prone, especially in a language that does not enforce catching exceptions (and PHP does not).

Case in point, in case you&#039;ve not read this yet:

http://blogs.msdn.com/b/oldnewthing/archive/2004/04/22/118161.aspx
http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/352949.aspx

Exceptions do not help your method chaining example. If I call $inst-&gt;foo()-&gt;bar()-&gt;bat()-&gt;baz(), and I catch an exception, where did it occur? I have to do a significant amount of work reading the data held in the exception instance to find out what failed. (This is one reason I really don&#039;t like methods returning instances, *especially* when those methods might throw an exception.)

In fact, the only times I&#039;ve heard people complain about return values from functions is because they don&#039;t want to do error handling. This crops up on the Go mailing list every so often: people get unexpected behavior, they paste their code, and they handle no errors. In fact, I find the Go error handling solution rather elegant: http://blog.golang.org/2011/07/error-handling-and-go.html

Fundamentally, if you are not following the documented API and checking for possible errors, you deserve what you get. If a function or method can return null, don&#039;t complain when your code breaks because you didn&#039;t check for it. That&#039;s *your* fault.]]></description>
		<content:encoded><![CDATA[<p>I&#8217;d only point out that exceptions were not created to detect errors and should not be used for error handling. They were created to abort in unrecoverable situations. Using exceptions as an error-handling mechanism can be horribly error prone, especially in a language that does not enforce catching exceptions (and PHP does not).</p>
<p>Case in point, in case you&#8217;ve not read this yet:</p>
<p><a href="http://blogs.msdn.com/b/oldnewthing/archive/2004/04/22/118161.aspx" rel="nofollow">http://blogs.msdn.com/b/oldnewthing/archive/2004/04/22/118161.aspx</a><br />
<a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/352949.aspx" rel="nofollow">http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/352949.aspx</a></p>
<p>Exceptions do not help your method chaining example. If I call $inst-&gt;foo()-&gt;bar()-&gt;bat()-&gt;baz(), and I catch an exception, where did it occur? I have to do a significant amount of work reading the data held in the exception instance to find out what failed. (This is one reason I really don&#8217;t like methods returning instances, *especially* when those methods might throw an exception.)</p>
<p>In fact, the only times I&#8217;ve heard people complain about return values from functions is because they don&#8217;t want to do error handling. This crops up on the Go mailing list every so often: people get unexpected behavior, they paste their code, and they handle no errors. In fact, I find the Go error handling solution rather elegant: <a href="http://blog.golang.org/2011/07/error-handling-and-go.html" rel="nofollow">http://blog.golang.org/2011/07/error-handling-and-go.html</a></p>
<p>Fundamentally, if you are not following the documented API and checking for possible errors, you deserve what you get. If a function or method can return null, don&#8217;t complain when your code breaks because you didn&#8217;t check for it. That&#8217;s *your* fault.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sven</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-9085</link>
		<dc:creator>Sven</dc:creator>
		<pubDate>Wed, 13 Mar 2013 11:05:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-9085</guid>
		<description><![CDATA[I cannot resist commenting, because &quot;someone is wrong on the internet&quot;. :)

1. &quot;A return value can be used to tell if the function behaved properly.&quot;

Well, yes, but usually a return value is used to return the result of a function. And it is up to the developer to decide which value should be returned if something went wrong. PHP functions usually return FALSE instead of something like a resource or integer values, and it can be hard to differentiate (strpos() == false is wrong).

On the other hand, if it isn&#039;t a function, then it has no return value. These things used to be called procedures in other languages.

2. &quot;A null return value can’t easily be tested.&quot;

Wrong. 

if (is_null($returnValue)) { /* failure code */ }
if (isset($returnValue)) { /* works as well */ }

$this-&gt;assertNull($returnValue); // unit testing

Testing for NULL is as easy as testing for FALSE. If the developer decides that instead of a usable value the function will return NULL in case of errors, this can easily be used.

3. &quot;Returning a null value breaks fluent interfaces.&quot;

This is no valid argument because any method inside fluent interfaces always must return it&#039;s own object again. There simply is no decision whether or not NULL is the return value for failure. Reporting errors in OOP usually is done by throwing exceptions. Reporting emptiness is done by using empty or nonfunctional objects of the same interface.


I think this article needs more updating. The last part on what to return is ok, but the introductory discussion is misleading and presents the wrong arguments. 

The question is: &quot;What is a proper return value in case there is no obvious return value?&quot; And the cases are a) dealing with errors, b) dealing with emptiness and c) default behavior when unconfigured.]]></description>
		<content:encoded><![CDATA[<p>I cannot resist commenting, because &#8220;someone is wrong on the internet&#8221;. :)</p>
<p>1. &#8220;A return value can be used to tell if the function behaved properly.&#8221;</p>
<p>Well, yes, but usually a return value is used to return the result of a function. And it is up to the developer to decide which value should be returned if something went wrong. PHP functions usually return FALSE instead of something like a resource or integer values, and it can be hard to differentiate (strpos() == false is wrong).</p>
<p>On the other hand, if it isn&#8217;t a function, then it has no return value. These things used to be called procedures in other languages.</p>
<p>2. &#8220;A null return value can’t easily be tested.&#8221;</p>
<p>Wrong. </p>
<p>if (is_null($returnValue)) { /* failure code */ }<br />
if (isset($returnValue)) { /* works as well */ }</p>
<p>$this-&gt;assertNull($returnValue); // unit testing</p>
<p>Testing for NULL is as easy as testing for FALSE. If the developer decides that instead of a usable value the function will return NULL in case of errors, this can easily be used.</p>
<p>3. &#8220;Returning a null value breaks fluent interfaces.&#8221;</p>
<p>This is no valid argument because any method inside fluent interfaces always must return it&#8217;s own object again. There simply is no decision whether or not NULL is the return value for failure. Reporting errors in OOP usually is done by throwing exceptions. Reporting emptiness is done by using empty or nonfunctional objects of the same interface.</p>
<p>I think this article needs more updating. The last part on what to return is ok, but the introductory discussion is misleading and presents the wrong arguments. </p>
<p>The question is: &#8220;What is a proper return value in case there is no obvious return value?&#8221; And the cases are a) dealing with errors, b) dealing with emptiness and c) default behavior when unconfigured.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tjorriemorrie</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-9067</link>
		<dc:creator>Tjorriemorrie</dc:creator>
		<pubDate>Wed, 13 Mar 2013 07:29:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-9067</guid>
		<description><![CDATA[Would it be viable to use trigger_error in some places instead of throwing an exception?]]></description>
		<content:encoded><![CDATA[<p>Would it be viable to use trigger_error in some places instead of throwing an exception?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-9017</link>
		<dc:creator>Christian</dc:creator>
		<pubDate>Tue, 12 Mar 2013 20:18:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-9017</guid>
		<description><![CDATA[ouch.. all points already covered.. and you want to be my latex salesman?]]></description>
		<content:encoded><![CDATA[<p>ouch.. all points already covered.. and you want to be my latex salesman?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathias Verraes</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-9011</link>
		<dc:creator>Mathias Verraes</dc:creator>
		<pubDate>Tue, 12 Mar 2013 19:41:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-9011</guid>
		<description><![CDATA[@beberlei and most other commenters hit the nail on the head. 

I only want to add (slightly off topic):

- Fluent interfaces for setters are bad practice because they encourage anaemic models. When you see $thing-&gt;setFoo($foo)-&gt;setBar($bar) , it often means you may need to encapsulate those as one operation doSomething($foo, $bar), where &#039;doSomething&#039; is a verb that has actual meaning in your domain.

- Fluent interfaces are very useful though for builders. The Doctrine QueryBuilder or the PHPUnit MockBuilder for example would be very annoying without fluent interfaces.]]></description>
		<content:encoded><![CDATA[<p>@beberlei and most other commenters hit the nail on the head. </p>
<p>I only want to add (slightly off topic):</p>
<p>- Fluent interfaces for setters are bad practice because they encourage anaemic models. When you see $thing-&gt;setFoo($foo)-&gt;setBar($bar) , it often means you may need to encapsulate those as one operation doSomething($foo, $bar), where &#8216;doSomething&#8217; is a verb that has actual meaning in your domain.</p>
<p>- Fluent interfaces are very useful though for builders. The Doctrine QueryBuilder or the PHPUnit MockBuilder for example would be very annoying without fluent interfaces.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eduardo Casas</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-9005</link>
		<dc:creator>Eduardo Casas</dc:creator>
		<pubDate>Tue, 12 Mar 2013 18:18:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-9005</guid>
		<description><![CDATA[@KingCrunch
Well, I don&#039;t agree. :)

1. Fluent interfaces are much more than method chaining and, despite your opinion, they are widely used to improve the readability of the code.

2. Said that, it doesn&#039;t mean we must use them everywhere. But sometimes they&#039;re pretty useful:

“Can you give me the sugar?” — “Anything else?” — “And a cup?” — “Anything else?”

I think this is a better approach, which makes sense.]]></description>
		<content:encoded><![CDATA[<p>@KingCrunch<br />
Well, I don&#8217;t agree. :)</p>
<p>1. Fluent interfaces are much more than method chaining and, despite your opinion, they are widely used to improve the readability of the code.</p>
<p>2. Said that, it doesn&#8217;t mean we must use them everywhere. But sometimes they&#8217;re pretty useful:</p>
<p>“Can you give me the sugar?” — “Anything else?” — “And a cup?” — “Anything else?”</p>
<p>I think this is a better approach, which makes sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rasmus Schultz</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-8996</link>
		<dc:creator>Rasmus Schultz</dc:creator>
		<pubDate>Tue, 12 Mar 2013 16:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-8996</guid>
		<description><![CDATA[In my experience, these issues most often occur in models, with objects that have optional relations - for example, $user-&gt;country-&gt;name could fail if the country relation is optional.

In my opinion, solutions to this problem range from bad to worse. The real issue is &quot;old school&quot; domain modeling - like many domain-related issues, this one largely disappears when you stick to modern DDD practices. That, is don&#039;t model $user-&gt;country as a relation, because the Country object isn&#039;t part of the User aggregate in the first place - it&#039;s outside the transaction boundary of any reasonable User transaction, so only the Country ID is part of the actual User aggregate, and should be modeled as such.

So now instead of $user-&gt;country-&gt;name, you get something like $countries-&gt;getOrDefault($user-&gt;country_id)-&gt;name, where $countries is your Country repository. You&#039;re now explicitly saying &quot;give me the Country or a Country null-object&quot;, which is what you want in a scenario where you&#039;re displaying the Country name. In some other scenario (e.g. business logic rather than display purposes) you may want a NULL rather than a null-object, or you may even want an Exception thrown - you indicate this in consumer-code by explicitly calling get(), getOrDefault(), getOrNull(), or whatever is appropriate in each case.

Classic domain modeling (and for that matter most modern ORM) teaches us to ignore transaction boundaries and model everything as monolithic graphs - issues like this one is just one of many issues that go away when you model your domain strictly respecting transaction boundaries. Yes, it takes a little more code - but model-consumer code becomes a lot more transparent, and you can more elegantly handle necessary deviations from the way you generally treat relations, on a case-by-case basis.

DDD practices desperately need to gain footing in the PHP world.]]></description>
		<content:encoded><![CDATA[<p>In my experience, these issues most often occur in models, with objects that have optional relations &#8211; for example, $user-&gt;country-&gt;name could fail if the country relation is optional.</p>
<p>In my opinion, solutions to this problem range from bad to worse. The real issue is &#8220;old school&#8221; domain modeling &#8211; like many domain-related issues, this one largely disappears when you stick to modern DDD practices. That, is don&#8217;t model $user-&gt;country as a relation, because the Country object isn&#8217;t part of the User aggregate in the first place &#8211; it&#8217;s outside the transaction boundary of any reasonable User transaction, so only the Country ID is part of the actual User aggregate, and should be modeled as such.</p>
<p>So now instead of $user-&gt;country-&gt;name, you get something like $countries-&gt;getOrDefault($user-&gt;country_id)-&gt;name, where $countries is your Country repository. You&#8217;re now explicitly saying &#8220;give me the Country or a Country null-object&#8221;, which is what you want in a scenario where you&#8217;re displaying the Country name. In some other scenario (e.g. business logic rather than display purposes) you may want a NULL rather than a null-object, or you may even want an Exception thrown &#8211; you indicate this in consumer-code by explicitly calling get(), getOrDefault(), getOrNull(), or whatever is appropriate in each case.</p>
<p>Classic domain modeling (and for that matter most modern ORM) teaches us to ignore transaction boundaries and model everything as monolithic graphs &#8211; issues like this one is just one of many issues that go away when you model your domain strictly respecting transaction boundaries. Yes, it takes a little more code &#8211; but model-consumer code becomes a lot more transparent, and you can more elegantly handle necessary deviations from the way you generally treat relations, on a case-by-case basis.</p>
<p>DDD practices desperately need to gain footing in the PHP world.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KingCrunch</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-8986</link>
		<dc:creator>KingCrunch</dc:creator>
		<pubDate>Tue, 12 Mar 2013 14:57:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-8986</guid>
		<description><![CDATA[@eduardo_cases
Well one can add, that fluent-interfaces are crap :)]]></description>
		<content:encoded><![CDATA[<p>@eduardo_cases<br />
Well one can add, that fluent-interfaces are crap :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eduardo Casas</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-8984</link>
		<dc:creator>Eduardo Casas</dc:creator>
		<pubDate>Tue, 12 Mar 2013 14:41:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-8984</guid>
		<description><![CDATA[I totally agree with @yunosh. I think that nothing else is needed to add.]]></description>
		<content:encoded><![CDATA[<p>I totally agree with @yunosh. I think that nothing else is needed to add.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KingCrunch</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-8982</link>
		<dc:creator>KingCrunch</dc:creator>
		<pubDate>Tue, 12 Mar 2013 14:21:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-8982</guid>
		<description><![CDATA[Oh, please don&#039;t ...

If a method doesn&#039;t have to tell something, it _shouldn&#039;t_ tell something.

This fluent-interface just provokes messy code, because it leads to longest method call chains, where nobody can follow, which method returns what and why. Especially &quot;why&quot;. I say &quot;setSomething()&quot; and the method returns itself? Do you always say youre name, when something tells you something.

&quot;Can you give me the sugar?&quot; -- &quot;Brandon&quot; -- &quot;And a cup?&quot; -- &quot;Brandon&quot;

And exactly this is how a fluent-interface looks like ;)]]></description>
		<content:encoded><![CDATA[<p>Oh, please don&#8217;t &#8230;</p>
<p>If a method doesn&#8217;t have to tell something, it _shouldn&#8217;t_ tell something.</p>
<p>This fluent-interface just provokes messy code, because it leads to longest method call chains, where nobody can follow, which method returns what and why. Especially &#8220;why&#8221;. I say &#8220;setSomething()&#8221; and the method returns itself? Do you always say youre name, when something tells you something.</p>
<p>&#8220;Can you give me the sugar?&#8221; &#8212; &#8220;Brandon&#8221; &#8212; &#8220;And a cup?&#8221; &#8212; &#8220;Brandon&#8221;</p>
<p>And exactly this is how a fluent-interface looks like ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mongolito404</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-8981</link>
		<dc:creator>mongolito404</dc:creator>
		<pubDate>Tue, 12 Mar 2013 14:12:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-8981</guid>
		<description><![CDATA[And to be pedantic, NULL is a value in PHP as stated in the documentation: &quot;The special NULL &lt;strong&gt;value&lt;/strong&gt; represents a variable with no value. NULL is the only possible &lt;strong&gt;value&lt;/strong&gt; of type null.&quot; (ref. http://php.net/manual/en/language.types.null.php)]]></description>
		<content:encoded><![CDATA[<p>And to be pedantic, NULL is a value in PHP as stated in the documentation: &#8220;The special NULL <strong>value</strong> represents a variable with no value. NULL is the only possible <strong>value</strong> of type null.&#8221; (ref. <a href="http://php.net/manual/en/language.types.null.php" rel="nofollow">http://php.net/manual/en/language.types.null.php</a>)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mongolito404</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-8980</link>
		<dc:creator>mongolito404</dc:creator>
		<pubDate>Tue, 12 Mar 2013 14:10:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-8980</guid>
		<description><![CDATA[NULL is the proper return value when there is no value to return. For instance, when querying the database for a nullable column of for a row that does not exists (and does not need to exist).

The return value of a method (or a function) should not be used for error conditions. If you can&#039;t and don&#039;t want to use exceptions, use a by-reference parameter for either the &quot;returned value&quot; ($error = foo($arg1, $arg2, $value)) or the error ($value = foo($arg1, $arg2, $error)). This allow you to detect errors without checking the &quot;returned value&quot;.]]></description>
		<content:encoded><![CDATA[<p>NULL is the proper return value when there is no value to return. For instance, when querying the database for a nullable column of for a row that does not exists (and does not need to exist).</p>
<p>The return value of a method (or a function) should not be used for error conditions. If you can&#8217;t and don&#8217;t want to use exceptions, use a by-reference parameter for either the &#8220;returned value&#8221; ($error = foo($arg1, $arg2, $value)) or the error ($value = foo($arg1, $arg2, $error)). This allow you to detect errors without checking the &#8220;returned value&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Spabby</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-8977</link>
		<dc:creator>Gary Spabby</dc:creator>
		<pubDate>Tue, 12 Mar 2013 13:39:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-8977</guid>
		<description><![CDATA[I can&#039;t agree that a function should never return null; sometimes null exactly the correct thing to return. Imagine the following function where the database column allows nulls.

function getCommentLinkById($id) {
    $row = $db-&gt;find($id);
    if(!$row) {
        return false;
    }
    return $row[&#039;link&#039;];
}]]></description>
		<content:encoded><![CDATA[<p>I can&#8217;t agree that a function should never return null; sometimes null exactly the correct thing to return. Imagine the following function where the database column allows nulls.</p>
<p>function getCommentLinkById($id) {<br />
    $row = $db-&gt;find($id);<br />
    if(!$row) {<br />
        return false;<br />
    }<br />
    return $row['link'];<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jory Geerts</title>
		<link>http://www.brandonsavage.net/always-return-something/#comment-8976</link>
		<dc:creator>Jory Geerts</dc:creator>
		<pubDate>Tue, 12 Mar 2013 13:32:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=2274#comment-8976</guid>
		<description><![CDATA[First you say that &quot;A null return value can’t easily be tested.&quot;, but the same is true for a fluent interface - if your getter always returns &#039;$this&#039;, the return value doesn&#039;t tell anybody if it worked either.

In my opinion, using exceptions is often a much easier way to indicate a &#039;failure&#039;.]]></description>
		<content:encoded><![CDATA[<p>First you say that &#8220;A null return value can’t easily be tested.&#8221;, but the same is true for a fluent interface &#8211; if your getter always returns &#8216;$this&#8217;, the return value doesn&#8217;t tell anybody if it worked either.</p>
<p>In my opinion, using exceptions is often a much easier way to indicate a &#8216;failure&#8217;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using disk: enhanced (User agent is rejected)
Object Caching 646/679 objects using apc
Content Delivery Network via Amazon Web Services: S3: brandonsavage-net-files.s3.amazonaws.com

 Served from: www.brandonsavage.net @ 2013-05-22 05:15:33 by W3 Total Cache -->