<?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>default &#8211; Software, Fitness, and Gaming &#8211; Jesse Warden</title>
	<atom:link href="https://jessewarden.com/tag/default/feed" rel="self" type="application/rss+xml" />
	<link>https://jessewarden.com</link>
	<description>Software &#124; Fitness &#124; Gaming</description>
	<lastBuildDate>Sun, 14 Jul 2019 18:33:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://jessewarden.com/wp-content/uploads/2016/08/cropped-Lambda2-32x32.png</url>
	<title>default &#8211; Software, Fitness, and Gaming &#8211; Jesse Warden</title>
	<link>https://jessewarden.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Maybe a Default Good Idea</title>
		<link>https://jessewarden.com/2019/07/maybe-a-default-good-idea.html</link>
		
		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Sun, 14 Jul 2019 18:24:07 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[elm]]></category>
		<category><![CDATA[functionalprogramming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[maybe]]></category>
		<guid isPermaLink="false">http://jessewarden.com/?p=5834</guid>

					<description><![CDATA[Introduction You&#8217;ve learned that using Maybe&#8216;s allows you to get rid of null pointer exceptions (i.e. &#8220;undefined is not a function&#8221;). However, now your application fails and gives no indication as to why. At least errors would leave a stack trace that may provide a hint as to where the problem originated. How does this [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>You&#8217;ve learned that using <code>Maybe</code>&#8216;s allows you to get rid of null pointer exceptions (i.e. &#8220;undefined is not a function&#8221;). However, now your application fails and gives no indication as to why. At least errors would leave a stack trace that may provide a hint as to where the problem originated. How does this happen and what should you be doing instead?</p>



<span id="more-5834"></span>



<h2 class="wp-block-heading">Null Pointers in Python vs Ruby, Lua, and JavaScript</h2>



<p>Let&#8217;s define what we mean by null pointers first, and how you usually encounter them. Most null pointers you&#8217;ll run into as a developer are from either accessing a property of an Object to show on the screen or calling a method on an Object or <code>class</code> instance. </p>



<h3 class="wp-block-heading">Python&#8217;s Strict</h3>



<p>Accessing Objects (Dictionaries in Python) is very strict. If the dictionary exists but the name doesn&#8217;t or you spell it wrong, you&#8217;ll get an exception:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># Python</span>
cow = { <span class="hljs-string">"firstName"</span> : <span class="hljs-string">"Jesse"</span> }
<span class="hljs-keyword">print</span>(cow&#91;<span class="hljs-string">"fistName"</span>])
KeyError: <span class="hljs-string">'firstNam'</span></code></span></pre>


<h3 class="wp-block-heading">Ruby, Lua, and JavaScript are Not Strict</h3>



<p>Ruby, Lua, and JavaScript, however, will return a <code>nil</code> or <code>undefined</code> if you access a property that doesn&#8217;t exist on the Hash/Table/Object:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-comment">// JavaScript</span>
cow = { <span class="hljs-attr">firstName</span>: <span class="hljs-string">"Jesse"</span> }
<span class="hljs-built_in">console</span>.log(cow&#91;<span class="hljs-string">"fistName"</span>]) <span class="hljs-comment">// undefined</span></code></span></pre>


<h3 class="wp-block-heading">Benefits of Getting Null/Nil vs. Exceptions</h3>



<p>All 3 languages will return their version of &#8220;nothing&#8221;. For some applications, this works out quite well:</p>



<ul class="wp-block-list"><li>UI applications when displaying data</li><li>API&#8217;s that are for orchestrating many API&#8217;s or solely exist to get around CORS</li><li>any code dealing with NoSQL type of data</li></ul>



<p>For UI&#8217;s, you typically do not control your data; you&#8217;re often loading it form some API. Even if you write this yourself, the names can get out of sync with the UI if you change things.</p>



<p>For API&#8217;s, you&#8217;ll often write <a href="https://samnewman.io/patterns/architectural/bff/">orchestration API&#8217;s for UI&#8217;s</a> to access 1 or many API&#8217;s to provide a simpler API for your UI. Using yours, you&#8217;ll make 1 request with efficient, formatted data how your UI needs it vs. 3 where you have to do all the error handling and data formatting on the client. Other times you want to use an API, but it has no support for CORS. The only way your website can access it is if you build your own API to call since API&#8217;s are not prevented from accessing data out of their domains like UI applications are.</p>



<p>For NoSQL type data, you&#8217;ll often have many Objects with the same or similar type fields, but either it&#8217;s low quality, inconsistent, or both. Often this is user entered and thus there is no guarantee that a record has &#8220;firstName&#8221; as a property.</p>



<h3 class="wp-block-heading">Careful For What You Wish For</h3>



<p>However, this has downstream effects. Sometimes code will be expecting a <code>String</code> or a <code>Number</code> and instead get <code>undefined</code> and blow up. Worse, the exceptions it throws are indicating the wrong place; the error occurred upstream but the stacktrace might not show that. The reverse can happen without a type system where it returns a String but the downstream is expecting an Array and queries length getting weird results&#8230;</p>



<p>While the benefits to being flexible are good, using a <code>Maybe</code> to force a developer to handle the case where <code>undefined</code> is returned instead is better.</p>



<h2 class="wp-block-heading">Maybe&#8217;s To the Rescue</h2>



<p>The way to solve this to use the Algebraic Data Type, <code>Maybe</code>. This gives you 2 ways to deal with null data. You can either get a default value:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-comment">// Lodash/fp's getOr</span>
getOr(<span class="hljs-string">'unknown name'</span>, <span class="hljs-string">'fistName'</span>, cow) <span class="hljs-comment">// unknown name</span></code></span></pre>


<p> Or you can match, whether using a <a href="https://folktale.origamitower.com/api/v2.3.0/en/folktale.maybe.html">match syntax</a> provided by a library, or a switch statement using <a href="https://www.typescriptlang.org/">TypeScript</a> in strict-mode which ensures you&#8217;ve handled all possible values:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-comment">// Folktale's Maybe</span>
cowsFirstNameMaybe.matchWith({
  <span class="hljs-attr">Just</span>: <span class="hljs-function">(<span class="hljs-params">{ value }</span>) =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"First name is:"</span>, value),
  <span class="hljs-attr">Nothing</span>: <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"unknown name"</span>)
})</code></span></pre>


<p>This, in theory, is one of the keys to ensuring you don&#8217;t get null pointer exceptions because you ensure in any case you normally would, you now get a type, and force your code to handle what happens if it gets a null value, even if that so happens to be throwing a custom error.</p>



<h2 class="wp-block-heading">Downstream Still Suffers</h2>



<p>However, <code>Maybe</code>&#8216;s can still causing suffering downstream just like <code>undefined</code> can. They do this via default values. In the <code>getOr</code> example above, we just provided &#8220;unknown name&#8221;. If we get nothing back, we just default to &#8220;unknown name&#8221; and handle the problem later, or don&#8217;t if it&#8217;s a database data quality issue we can&#8217;t fix. For a UI developer, that&#8217;s often perfect as they can usually blame the back-end developers for the problem, and their code is working perfectly, and thus fire-drill averted, blame diverted.</p>



<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="315" height="180" src="http://jessewarden.com/wp-content/uploads/2019/07/nan.png" alt="" class="wp-image-5835" srcset="https://jessewarden.com/wp-content/uploads/2019/07/nan.png 315w, https://jessewarden.com/wp-content/uploads/2019/07/nan-300x171.png 300w" sizes="(max-width: 315px) 100vw, 315px" /><figcaption>Hey, at least it didn&#8217;t explode, right? I mean, the user finished the test, their results were submitted, and they can ignore the weird score&#8230;</figcaption></figure>



<p>However, other times, it ends up hiding bugs. For non-FP codebases, a downstream function/class method will get null data and break.</p>



<figure class="wp-block-image"><img decoding="async" width="522" height="108" src="http://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.05.41-PM.png" alt="" class="wp-image-5836" srcset="https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.05.41-PM.png 522w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.05.41-PM-300x62.png 300w" sizes="(max-width: 522px) 100vw, 522px" /></figure>



<p>For FP codebases, they&#8217;ll get default data which often the developer never intended, and something goes awry. This is what we&#8217;ll focus on below.</p>



<h2 class="wp-block-heading">Examples of Default Value Causing UI Drama</h2>



<p>Let&#8217;s define what we mean by default value as there is the imperative version where function arguments have default values for arguments if the user doesn&#8217;t supply a value, or a <code>Maybe</code> which will often come with a default value through <code>getOr</code> in Lodash, <code>getOrElse</code> in Folktale, or <code>withDefault</code> in Elm.</p>



<h3 class="wp-block-heading">Default Values For Function Parameters</h3>



<p>Default values are used by developers when methods have a common value they use internally. They&#8217;ll expose the parameter in the function, but give it a default value if the user doesn&#8217;t supply anything.</p>



<p>The date library moment does this. If you supply a date, it&#8217;ll format it:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">moment(<span class="hljs-string">'2019-02-14'</span>).format(<span class="hljs-string">'MMM Do YY'</span>)
<span class="hljs-comment">// Feb 14th 19</span></code></span></pre>


<p>However, if you supply no date, they&#8217;ll default to &#8220;now&#8221;, aka <code>new Date()</code>:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">moment().format(<span class="hljs-string">'MMM Do YY'</span>)
<span class="hljs-comment">// Jul 14th 19</span></code></span></pre>


<p>Think of the function definition something like this. If they don&#8217;t supply a maybeDate parameter, JavaScript will just default that parameter to now.</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">moment</span><span class="hljs-params">(maybeDate=new Date<span class="hljs-params">()</span>)</span> </span>{</code></span></pre>


<h3 class="wp-block-heading">Default Values for Maybes</h3>



<p>While useful, things can get dangerous when you don&#8217;t know what the default values are, or if there are more than one, or what their relationship to each other is.  In Moment&#8217;s case, it&#8217;s very clear what no input means: now. Other times, however, it&#8217;s not clear at all. Let&#8217;s revisit our default value above:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">getOr(<span class="hljs-string">'unknown name'</span>, <span class="hljs-string">'fistName'</span>, cow) <span class="hljs-comment">// unknown name</span></code></span></pre>


<p>What could possibly be the reason we put default value &#8220;unknown name&#8221;? Is it a passive aggressive way for the developer to let Product know the back-end data is bad? Is it a <a href="https://www.snopes.com/fact-check/brown-out/">brown M&amp;M</a> for the developer to figure out later? The nice thing about string is you have a lot of freedom to be very verbose in why that string is there.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">getOr(<span class="hljs-string">'Bad Data - our data is user input without validation plus some of it is quite old being pulled from another database nightly so we cannot guarantee we will ever have first name'</span>, <span class="hljs-string">'fistName'</span>, cow)</code></span></pre>


<p>Oh&#8230; ok. Much more clear why. However, that clarity suddenly spurs ideas and problem solving. If you don&#8217;t get a name, the Designer can come up with a way to display that vs &#8220;unknown name&#8221; which could actually be the wrong thing to show a user. We do know, for a fact, the downstream database never received a first name inputted by the user. It&#8217;s not our fault there is no first name, it&#8217;s the user&#8217;s. Perhaps a read-only UI element that lets the user know this? It doesn&#8217;t matter if that&#8217;s correct, the point here is you are investing your team&#8217;s resources to solve these default values. You all are proactively attacking what would usually be a reaction to a null pointer.</p>



<h3 class="wp-block-heading">Downstream Functions Not Properly Handling the Default Value</h3>



<p>Strings for UI elements won&#8217;t often cause things to break per say, but other data types where additional code later expects to work with them will.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> phone = getOr(<span class="hljs-string">'no default phone number'</span>, <span class="hljs-string">'address.phoneNumber&#91;0]'</span>, person)
<span class="hljs-keyword">const</span> formatted = formatPhoneNumber(phone)
<span class="hljs-comment">// TypeError</span></code></span></pre>


<p>The code above fails because <code>formatPhoneNumber</code> is not equipped to handle strings that aren&#8217;t phone numbers. Types in <a href="https://www.typescriptlang.org/">TypeScript</a> or <a href="https://elm-lang.org/">Elm</a> or perhaps property tests using <a href="https://github.com/jsverify/jsverify">JSVerify</a> could have found this earlier.</p>



<h3 class="wp-block-heading">Default Values for Maybes Causing Bugs</h3>



<p>Let&#8217;s take a larger example where even super strong types and property tests won&#8217;t save us. We have an application for viewing many accounts. Notice the pagination buttons at the bottom.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="658" src="http://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.31.20-PM-1024x658.png" alt="" class="wp-image-5837" srcset="https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.31.20-PM-1024x658.png 1024w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.31.20-PM-300x193.png 300w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.31.20-PM-768x493.png 768w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.31.20-PM.png 1650w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>We have 100 accounts, and can view 10 at a time. We&#8217;ve written 2 functions to handle the pagination, both have bugs. We can trigger the bug by going to page 11.</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="497" src="http://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.55.51-PM-1024x497.png" alt="" class="wp-image-5838" srcset="https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.55.51-PM-1024x497.png 1024w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.55.51-PM-300x146.png 300w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.55.51-PM-768x373.png 768w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-12.55.51-PM.png 1702w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>I thought you just said we have 10 pages, not 11? Why is the screen blank? How does it say 11 of 10? I thought strong types and functional programming meant no bugs?</p>



<p>The first bug, allowing you to page beyond the total pages, is an easy fix. Below is the Elm code and equivalent JavaScript code:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">-- Elm
nextPage currentPage totalPages =
  <span class="hljs-keyword">if</span> currentPage &lt; totalPages then
    currentPage + <span class="hljs-number">1</span>
  <span class="hljs-keyword">else</span>
    currentPage</code></span></pre>

<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-comment">// JavaScript</span>
<span class="hljs-keyword">const</span> nextPage = <span class="hljs-function">(<span class="hljs-params">currentPage, totalPages</span>) =&gt;</span> {
  <span class="hljs-keyword">if</span>(currentPage &lt; totalPages) {
    <span class="hljs-keyword">return</span> currentPage + <span class="hljs-number">1</span>
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">return</span> currentPage
  }
}</code></span></pre>


<p>We have 100 accounts <a href="https://lodash.com/docs/4.17.11#chunk">chunked</a> into an Array containing 9 child Arrays, or our &#8220;pages&#8221;. We&#8217;re using that <code>currentPage</code> as an Array index. Since Array&#8217;s in JavaScript are 0 based, we get into a situation where <code>currentPage</code> gets set to 10. Our Array only has 9 items. In JavaScript, that&#8217;s <code>undefined</code>:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">accountPages&#91;<span class="hljs-number">9</span>] <span class="hljs-comment">// &#91;account91, account92, ...]</span>
accountPages&#91;<span class="hljs-number">10</span>] <span class="hljs-comment">// undefined</span></code></span></pre>


<p>If you&#8217;re using <code>Maybe</code>&#8216;s, then it&#8217;s <code>Nothing</code>:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">accountPages&#91;<span class="hljs-number">9</span>] <span class="hljs-comment">// Just &#91;account91, account92, ...]</span>
accountPages&#91;<span class="hljs-number">10</span>] <span class="hljs-comment">// Nothing</span></code></span></pre>


<p>Ok, that&#8217;s preventable, just ensure currentPage can never be higher than the total pages? Instead, just subtract one from <code>totalPages</code>:</p>


<pre class="wp-block-code"><span><code class="hljs">-- Elm
if currentPage &lt; totalPages - 1 then</code></span></pre>

<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-comment">// JavScript</span>
<span class="hljs-keyword">if</span>(currentPage &lt; totalPages - <span class="hljs-number">1</span>) {</code></span></pre>


<p>Great, that fixes the bug; you can&#8217;t click next beyond page 10, which is the last page.</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="712" src="http://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-1.11.28-PM-1024x712.png" alt="" class="wp-image-5839" srcset="https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-1.11.28-PM-1024x712.png 1024w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-1.11.28-PM-300x209.png 300w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-1.11.28-PM-768x534.png 768w, https://jessewarden.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-14-at-1.11.28-PM.png 1602w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>&#8230; but what about that 2nd bug? How did you get a blank page? Our UI code, if it gets an empty Array, won&#8217;t render anything. Cool, so empty Array == blank screen, but why did we get an empty Array? Here&#8217;s the offending, abbreviated Elm or JavaScript code:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">-- Elm
getCurrentPage totalPages currentPage accounts =
  chunk totalPages accounts
  |&gt; <span class="hljs-built_in">Array</span>.get currentPage
  |&gt; Maybe.withDefault &#91;]</code></span></pre>

<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-comment">// JavaScript</span>
<span class="hljs-keyword">const</span> getCurrentPage = <span class="hljs-function">(<span class="hljs-params">totalPages, currentPage, accounts</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> pages = chunk(totalPages, accounts)
  <span class="hljs-keyword">const</span> currentPageMaybe = pages&#91;currentPage]
  <span class="hljs-keyword">if</span>(currentPageMaybe) {
      <span class="hljs-keyword">return</span> currentPageMaybe
  }
  <span class="hljs-keyword">return</span> &#91;]
}</code></span></pre>


<p>Both provide an empty Array as a default value if you get <code>undefined</code>. It could be either bad data the index <code>currentPage</code> but in our case, we were out of bounds; accessing index 10 in an Array that only has 9 items. </p>



<p>This is where lazy thought,  as to how a <code>Nothing</code> could happen results in downstream pain. This is also where types, even in JavaScript which doesn&#8217;t have them but can be enhanced with libraries, really can help prevent these situations. I encourage you to watch <a href="https://www.youtube.com/watch?v=IcgmSRJHu_8">Making Impossible States Impossible by Richard Feldman</a> to get an idea of how to do this.</p>



<h2 class="wp-block-heading">Conclusions</h2>



<p>Really think about 4 things when you&#8217;re using Maybes and you&#8217;re returning a Nothing.</p>



<p>If it truly is something you cannot possibly control, it truly requires someone upstream to handle it, then that is the perfect use case, and why Object property access, and Array index access are the 2 places you see it used most. </p>



<p>Second, have you thought enough about how the <code>Nothing</code> can occur? The below is obvious:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-keyword">const</span> <span class="hljs-keyword">list</span> = &#91;]
console.log(<span class="hljs-keyword">list</span>&#91;<span class="hljs-number">2</span>]) <span class="hljs-comment">// undefined</span></code></span></pre>


<p>But what about this one?</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> listFromServerWith100Items = <span class="hljs-keyword">await</span> getData()
<span class="hljs-built_in">console</span>.log(list&#91;<span class="hljs-number">34</span>]) <span class="hljs-comment">// undefined</span></code></span></pre>


<p>If accessing data is truly integral to how your application works, then you are probably better served being more thorough in your data parsing, and surfacing errors when the data comes in incorrectly. Having a parse error clearly indicate where data is missing is much more preferable than having an unexpected <code>Nothing</code> later but &#8220;hey, everything says it parsed ok&#8230;.&#8221;</p>



<p>Third, be cognizant about your default values. If you&#8217;re not going to use a <code>Result</code>, which can provide a lot more information about why something failed, then you should probably use a better data type instead that comes embedded with information. Watch  <a href="https://www.youtube.com/watch?v=6TDKHGtAxeg">&#8220;Solving the Boolean Identity Crisis&#8221; by Jeremy Fairbank</a> to get a sense at how primitive data types don&#8217;t really help us understand what methods are doing and how creating custom types can help. Specifically, instead of <code>[]</code> for our <code>getCurrentPage</code> functions above, use types to describe how you could even have empty pages. Perhaps instead you should return a <code>Result</code> Error that describes accessing a page that doesn&#8217;t exist, or an <code>EmptyPage</code> type vs. an empty Array leaving us to wonder if our parsing is broke, we have a default value somewhere like above, or some other problem.</p>



<p>Fourth, this default values will have downstream effects. Even if you aren&#8217;t practicing Functional Programming, using default values means your function will assume something. This function will then be used in many other functions/class methods. She&#8217;ll provide some default value others further down the function call stack won&#8217;t expect. Your function is part of a whole machine, and it&#8217;s better to be explicit about what the default value is you&#8217;re returning. Whether that&#8217;s a verbose String explaining the problem, or a Number that won&#8217;t negatively affect math (such as 0 instead of the common -1), or a custom type like <code>DataDidntLoadFromServer</code>.</p>



<p>Making assumptions to help yourself or other developers is powerful, but be sure to take responsibility with that power and think through the downstream affects of those default values. </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
