<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: A Post About Nothing</title>
	<atom:link href="http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/feed/" rel="self" type="application/rss+xml" />
	<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/</link>
	<description></description>
	<lastBuildDate>Wed, 25 Jan 2012 15:21:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Null, null, Nil, Nothing, None, and Unit in Scala</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-653</link>
		<dc:creator><![CDATA[Null, null, Nil, Nothing, None, and Unit in Scala]]></dc:creator>
		<pubDate>Mon, 01 Nov 2010 18:43:39 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-653</guid>
		<description><![CDATA[[...] by Matt Malone where he has explained all these concepts in depth with examples. Read the blog post here.   Share and [...]]]></description>
		<content:encoded><![CDATA[<p>[...] by Matt Malone where he has explained all these concepts in depth with examples. Read the blog post here.   Share and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-651</link>
		<dc:creator><![CDATA[Aaron]]></dc:creator>
		<pubDate>Mon, 30 Aug 2010 19:51:56 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-651</guid>
		<description><![CDATA[In Scala 2.8, you can use Option.apply like so:

Option(null).getOrElse(&quot;Value to display in case of &#039;null&#039;&quot;)

Option.apply is defined in the same way as Matt&#039;s single-argument Nvl.apply method above.]]></description>
		<content:encoded><![CDATA[<p>In Scala 2.8, you can use Option.apply like so:</p>
<p>Option(null).getOrElse(&#8220;Value to display in case of &#8216;null&#8217;&#8221;)</p>
<p>Option.apply is defined in the same way as Matt&#8217;s single-argument Nvl.apply method above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-611</link>
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Fri, 08 Jan 2010 15:55:33 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-611</guid>
		<description><![CDATA[Options (Some and None) aren’t used this way. They are a way to avoid returning a null value from a function. Returning nulls has two effects: it creates opportunities for NullPointerExceptions and it makes the calling code test for and handle null return values. The time to choose an Option is (primarily) when you are writing a function which sometimes can’t return a sensible value.

It sounds like what you want is an easy way to handle nulls that are returned from Java or from a poorly written Scala function. I don’t know of anything built-in that does this, but here’s a simple object you can use (named in honor of the NVL function from SQL which serves a similar purpose).

scala&gt;object Nvl {
&#124; def apply[T](ref: T, alt: T) =
&#124; if (ref == null) alt else ref
&#124; def apply[T](ref: T) =
&#124; if (ref == null) None else Some(ref)
&#124; }
defined module Nvl

scala&gt; Nvl(&quot;non-null string&quot;)
res0: Option[java.lang.String] = Some(non-null string)

scala&gt; Nvl(null)
res1: Option[Null] = None

scala&gt; Nvl(&quot;original&quot;, &quot;alternate&quot;)
res2: java.lang.String = original

scala&gt; Nvl(null, &quot;alternate&quot;)
res3: java.lang.String = alternate]]></description>
		<content:encoded><![CDATA[<p>Options (Some and None) aren’t used this way. They are a way to avoid returning a null value from a function. Returning nulls has two effects: it creates opportunities for NullPointerExceptions and it makes the calling code test for and handle null return values. The time to choose an Option is (primarily) when you are writing a function which sometimes can’t return a sensible value.</p>
<p>It sounds like what you want is an easy way to handle nulls that are returned from Java or from a poorly written Scala function. I don’t know of anything built-in that does this, but here’s a simple object you can use (named in honor of the NVL function from SQL which serves a similar purpose).</p>
<p>scala&gt;object Nvl {<br />
| def apply[T](ref: T, alt: T) =<br />
| if (ref == null) alt else ref<br />
| def apply[T](ref: T) =<br />
| if (ref == null) None else Some(ref)<br />
| }<br />
defined module Nvl</p>
<p>scala&gt; Nvl(&#8220;non-null string&#8221;)<br />
res0: Option[java.lang.String] = Some(non-null string)</p>
<p>scala&gt; Nvl(null)<br />
res1: Option[Null] = None</p>
<p>scala&gt; Nvl(&#8220;original&#8221;, &#8220;alternate&#8221;)<br />
res2: java.lang.String = original</p>
<p>scala&gt; Nvl(null, &#8220;alternate&#8221;)<br />
res3: java.lang.String = alternate</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marco</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-609</link>
		<dc:creator><![CDATA[Marco]]></dc:creator>
		<pubDate>Fri, 08 Jan 2010 10:22:51 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-609</guid>
		<description><![CDATA[Is there anyway for &quot;wrapping&quot; &#039;null&#039; so that I can test it inline?

I&#039;m thinking of something like

  Some(null).getOrElse(&quot;Value to display in case of &#039;null&#039;&quot;)

^^^^
NOT WORKING CODE]]></description>
		<content:encoded><![CDATA[<p>Is there anyway for &#8220;wrapping&#8221; &#8216;null&#8217; so that I can test it inline?</p>
<p>I&#8217;m thinking of something like</p>
<p>  Some(null).getOrElse(&#8220;Value to display in case of &#8216;null&#8217;&#8221;)</p>
<p>^^^^<br />
NOT WORKING CODE</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-520</link>
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Wed, 26 Aug 2009 16:31:13 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-520</guid>
		<description><![CDATA[I&#039;m starting to come around.  :)  Two reasons: I have some more practice with Option, and I&#039;ve come to appreciate Scala&#039;s aversion to null.

There are better idioms for using Option than the ones I knew about when I wrote this post.  But using Option efficiently and readably takes study and practice. For example, it&#039;s not obvious from flatMap&#039;s signature that your example code will work.  You have to have read the Option object&#039;s source code to know about the implicit conversion to Iterable.  (Perhaps a list of implicit conversions provided by the companion object should appear in a class&#039;s scaladoc?)

Java desensitizes you to nulls.  Nulls are an integral part of standard APIs in Java.  Take a line like &quot;while (reader.readLine() != null)&quot; for example.  Just as the beginning Java programmer would happily use goto and pointer arithmetic if he could but eventually comes to understand he&#039;s better off without them, so should the Scala programmer learn to avoid null.  A null is just a NullPointerException waiting to happen.

So I agree that returning an Option is better than returning a null.  Heck, if Scala one day replaces Java altogether I&#039;d like to see null deprecated.  However, I still prefer a design that avoids Option when possible.  For example:

def even(n: Int): Boolean = n%2 == 0

def getEven(l: List[Int]): List[Int] = l filter even

To me, it&#039;s more readable than the solution using Option.]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m starting to come around.  :)  Two reasons: I have some more practice with Option, and I&#8217;ve come to appreciate Scala&#8217;s aversion to null.</p>
<p>There are better idioms for using Option than the ones I knew about when I wrote this post.  But using Option efficiently and readably takes study and practice. For example, it&#8217;s not obvious from flatMap&#8217;s signature that your example code will work.  You have to have read the Option object&#8217;s source code to know about the implicit conversion to Iterable.  (Perhaps a list of implicit conversions provided by the companion object should appear in a class&#8217;s scaladoc?)</p>
<p>Java desensitizes you to nulls.  Nulls are an integral part of standard APIs in Java.  Take a line like &#8220;while (reader.readLine() != null)&#8221; for example.  Just as the beginning Java programmer would happily use goto and pointer arithmetic if he could but eventually comes to understand he&#8217;s better off without them, so should the Scala programmer learn to avoid null.  A null is just a NullPointerException waiting to happen.</p>
<p>So I agree that returning an Option is better than returning a null.  Heck, if Scala one day replaces Java altogether I&#8217;d like to see null deprecated.  However, I still prefer a design that avoids Option when possible.  For example:</p>
<p>def even(n: Int): Boolean = n%2 == 0</p>
<p>def getEven(l: List[Int]): List[Int] = l filter even</p>
<p>To me, it&#8217;s more readable than the solution using Option.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Sobral</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-517</link>
		<dc:creator><![CDATA[Daniel Sobral]]></dc:creator>
		<pubDate>Wed, 26 Aug 2009 01:34:14 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-517</guid>
		<description><![CDATA[It&#039;s silly to use Option sparingly. You either can guarantee a result, or you can&#039;t. If you can&#039;t, you&#039;ll have to handle it in SOME way. Do you think testing for &quot;null&quot; or having to catch exceptions is any better?

Besides, you can do stuff with Option. For instance:

def even(n: Int): Option[Int] = if (n % 2 == 0) Some(n) else None

def getEven(l: List[Int]): List[Int] = l flatMap even

Did you see any &quot;match&quot;?]]></description>
		<content:encoded><![CDATA[<p>It&#8217;s silly to use Option sparingly. You either can guarantee a result, or you can&#8217;t. If you can&#8217;t, you&#8217;ll have to handle it in SOME way. Do you think testing for &#8220;null&#8221; or having to catch exceptions is any better?</p>
<p>Besides, you can do stuff with Option. For instance:</p>
<p>def even(n: Int): Option[Int] = if (n % 2 == 0) Some(n) else None</p>
<p>def getEven(l: List[Int]): List[Int] = l flatMap even</p>
<p>Did you see any &#8220;match&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2009-08-02 &#171; Dan Creswell&#8217;s Linkblog</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-391</link>
		<dc:creator><![CDATA[links for 2009-08-02 &#171; Dan Creswell&#8217;s Linkblog]]></dc:creator>
		<pubDate>Sun, 02 Aug 2009 12:10:55 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-391</guid>
		<description><![CDATA[[...] A Post About Nothing (tags: scala language) [...]]]></description>
		<content:encoded><![CDATA[<p>[...] A Post About Nothing (tags: scala language) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Null, null, Nil, Nothing, None, and Unit in Scala &#171; Java PitStop</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-226</link>
		<dc:creator><![CDATA[Null, null, Nil, Nothing, None, and Unit in Scala &#171; Java PitStop]]></dc:creator>
		<pubDate>Sun, 12 Jul 2009 17:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-226</guid>
		<description><![CDATA[[...] The above is a breif summary of a wonderful post by Matt Malone where he has explained all these concepts in depth with examples. Read the blog post here. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] The above is a breif summary of a wonderful post by Matt Malone where he has explained all these concepts in depth with examples. Read the blog post here. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik Søe Sørensen</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-188</link>
		<dc:creator><![CDATA[Erik Søe Sørensen]]></dc:creator>
		<pubDate>Sun, 21 Jun 2009 15:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-188</guid>
		<description><![CDATA[&gt; ...but can you imagine a codebase peppered with Option[This] and Option[That] all over the place,
&gt; and all those ensuing match blocks? I say use Option sparingly.

A lot of &quot;all those match blocks&quot; are usually not necessary. Option has a number of useful methods, and much of the time does whatever your match block would do.

The code example, for instance:
   &#124;   getAStringMaybe(num) match {  
   &#124;     case Some(str) =&gt; println(str)  
   &#124;     case None =&gt; println(&quot;No string!&quot;)  
   &#124;   }
could be written as
   println(getAStringMaybe(num).get(&quot;No string!&quot;))
which can&#039;t be said to be very verbose :-)]]></description>
		<content:encoded><![CDATA[<p>&gt; &#8230;but can you imagine a codebase peppered with Option[This] and Option[That] all over the place,<br />
&gt; and all those ensuing match blocks? I say use Option sparingly.</p>
<p>A lot of &#8220;all those match blocks&#8221; are usually not necessary. Option has a number of useful methods, and much of the time does whatever your match block would do.</p>
<p>The code example, for instance:<br />
   |   getAStringMaybe(num) match {<br />
   |     case Some(str) =&gt; println(str)<br />
   |     case None =&gt; println(&#8220;No string!&#8221;)<br />
   |   }<br />
could be written as<br />
   println(getAStringMaybe(num).get(&#8220;No string!&#8221;))<br />
which can&#8217;t be said to be very verbose :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/#comment-131</link>
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Tue, 06 Jan 2009 09:59:26 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=95#comment-131</guid>
		<description><![CDATA[Here is another way to look at Null and Nothing: AnyRef is the top of the reference types and Null the bottom. Any is the top of *all* types and Nothing the bottom. 

See also http://www.scala-lang.org/docu/files/ScalaOverview.pdf on page three for a class diagram.]]></description>
		<content:encoded><![CDATA[<p>Here is another way to look at Null and Nothing: AnyRef is the top of the reference types and Null the bottom. Any is the top of *all* types and Nothing the bottom. </p>
<p>See also <a href="http://www.scala-lang.org/docu/files/ScalaOverview.pdf" rel="nofollow">http://www.scala-lang.org/docu/files/ScalaOverview.pdf</a> on page three for a class diagram.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

