    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Afterwood</title>
        <link>https://members.accu.org/index.php/articles/2530</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Design of applications and programs + Overload Journal #146 - August 2018</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c67/">Design</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c389/">o146</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c67-389/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c67+389/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Afterwood</h1>
<p><strong>Author:</strong>&nbsp;Bob Schmidt</p>
<p>
<strong>Date:</strong> 01 August 2018 18:26:35 +01:00 or Wed, 01 August 2018 18:26:35 +01:00</p>
<p><strong>Summary:</strong>&nbsp;Much ado about nothing. Chris Oldwood considers what we have when we have nothing.</p>
<p><strong>Body:</strong>&nbsp;<p>There is a classic puzzle that goes:</p>

<p class="blockquote">The poor have it, the rich need it, and if you eat it youâ€™ll die. What is it?</p>

<p>If you havenâ€™t come across this before and Google is out of reach because youâ€™re reading the printed edition going through a tunnel or an internet blackspot, the answer is â€˜nothingâ€™. I think it would be fairly easy to come up with a programming specific version of this particular puzzle as there appears to be quite a few variants of â€˜nothingâ€™ in our world, many of which seem to occupy a significant amount of our time due to their cunning camouflaged outfits.</p>

<p>It probably seems strange to us now but once upon a time there was no zero. Essentially you had something which was countable or you had nothing. There were no negative numbers either and nothing preceded one (no pun intended, for once). I recently read <em>The Nothing that Is: A Natural History of Zero</em> and it got me thinking about the ways we represent nothingness in programming and the problems it causes.</p>

<p>Zero is almost certainly our â€˜go to choiceâ€™ for representing a lack of something as itâ€™s been with us since our early days of schooling and support for integer values has also been around in programming pretty much since the beginning too whether youâ€™re using assembly or a high-level language. Even most children could tell you <code>numApples = 0</code> means you donâ€™t have any apples.</p>

<p>Where it starts to go astray is when we have to squeeze the concept of â€˜noneâ€™ into a domain that doesnâ€™t really support it because you are no longer representing countable things. A classic example here is representing dates where day zero represents some epoch like 1st January 1970 or 1st January 1900 and negative values stretch backwards in time. Here every value in the domain represents a valid value and so if we want something to accommodate the notion of â€˜no valueâ€™ we probably have to re-purpose one or other end of the spectrum, e.g. <code>INT_MIN</code> or <code>INT_MAX</code>.</p>

<p>What about if weâ€™re searching an array for some value or object and there is nothing to be found? If our array starts at index 1 (e.g. Visual Basic) we could use the value 0, but many languages have adopted the 0-based approach and Stan Kelly-Bootleâ€™s suggestion of using 0.5 has never really received any uptake. For languages like Java and C# that are inherently based on signed integers they can return any negative value for the â€˜none foundâ€™ answer. In C++ where unsigned integers are the preferred choice we have no such luck and instead have concocted a magical value by the name of <code>npos</code> for strings which (implementation-wise) sits within the valid range of values but on the precipice such that youâ€™d probably run out of memory long before it could ever be a valid result.</p>

<p>Sadly the use of -1 (in either of its signed or unsigned guises) as both a perfectly good response to a question and as a way of signalling an error has only succeeded in muddying the waters further. The Windows API for example uses the constants <code>LB_ERR</code> (and <code>CB_ERR</code>) in this way which means you often stumble across code that initialises variables with it, e.g. <code>index = LB_ERR</code>, because it allows us to exploit a duality of semantics (â€˜no value, yetâ€™ and â€˜not foundâ€™) and write less code, irrespective of whether it makes comprehending it any easier. (You might argue not finding it is an error; either way you still have the same type representing two different domains â€“ index and error.)</p>

<p>With enumerated types we often walk right into the same trap with our eyes wide open thinking weâ€™re being clever by adding an explicit value called <code>None</code> or <code>Default</code> (usually with a value of 0 in languages that zero-initialise values and references for â€˜safetyâ€™s sakeâ€™).</p>

<p>Of course when youâ€™re forced to abuse the type system it will get its own back. By masquerading two different result values within the normal course of events you will trick the caller into believing itâ€™s safe to simply compose functions when in reality theyâ€™re just storing up a world of pain in the form of an <code>IndexOutOfBounds</code> exception, access violation or, if really unlucky, undefined behaviour and subsequent data corruption.</p>

<p>The <code>NullPointerException</code>, or â€˜NPEâ€™ as it is commonly referred to in the Java world, is a blight on modern programming caused in part by our use of programming languages which embrace the use of reference types over value types meaning that all of our objects can potentially exist or not exist. Unless the use is entirely local it can be difficult to reason about any objectâ€™s existence and therefore null checks can easily dominate a codebase in an act of overly defensive programming. The introduction of the <code>?.</code> operator in some languages might reduce the noise but itâ€™s just a case of treating the symptoms, not the disease.</p>

<p>This particular foe likes to disguise themselves by changing their name too, but whether they be <code>null</code>, <code>NULL</code>, <code>nullptr</code>, <code>nil</code>, <code>0</code>, <code>end</code>, <code>-1</code>, <code>npos</code>, <code>&quot;&quot;</code>, <code>NaN</code>, <code>None</code>, etc. we should be on our guard and be ready to banish them to computing history or at the very least quarantine them.</p>

<p>But what can be done, surely we canâ€™t undo the past? Well, maybe we can. Over the years the awareness of the Optional (Option, Maybe, etc.) type has grown so that itâ€™s no longer just a niche technique used by Comp Sci purists. The desire to right this wrong is so strong in some circles that there is currently a preview of C# [<a href="#[Github]">Github</a>] where reference types have been given the <code>Nullable</code> makeover thereby allowing us to finally consider deleting our own homebrew variants and deprecating our static analysis annotations in favour of a kosher type annotation. Surprised?</p>

<p>One of Shakespeareâ€™s most famous comedies is titled <em>Much Ado About Nothing</em>. Given the amount of time weâ€™ve lost over the years debugging issues caused by our inability to express â€˜nothingâ€™ in a way that is obvious to our fellow programmers Iâ€™d say it was no laughing matter. We need to realise that failure can indeed be an option and that the type system should be there to help us, nothing more nothing less.</p>

<h2>Reference</h2>

<p class="bibliomixed"><a id="[Github]"></a>[Github] <a href="https://github.com/dotnet/csharplang/wiki/Nullable-Reference-Types-Preview">https://github.com/dotnet/csharplang/wiki/Nullable-Reference-Types-Preview</a></p>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
