<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jonathan Böcker</title>
    <description>The latest articles on Forem by Jonathan Böcker (@schwusch).</description>
    <link>https://forem.com/schwusch</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F228474%2Fc86f6a65-5c2f-4c15-bf80-21256cea74e2.jpeg</url>
      <title>Forem: Jonathan Böcker</title>
      <link>https://forem.com/schwusch</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/schwusch"/>
    <language>en</language>
    <item>
      <title>Drawing arrows in Flutter, or anything else, based on widget positions</title>
      <dc:creator>Jonathan Böcker</dc:creator>
      <pubDate>Fri, 07 Aug 2020 07:19:32 +0000</pubDate>
      <link>https://forem.com/charliefoxtrot/drawing-arrows-in-flutter-or-anything-else-based-on-widget-positions-2883</link>
      <guid>https://forem.com/charliefoxtrot/drawing-arrows-in-flutter-or-anything-else-based-on-widget-positions-2883</guid>
      <description>&lt;p&gt;I recently made a Flutter package called &lt;code&gt;widget_arrows&lt;/code&gt; which caught some attention on the &lt;a href="https://www.reddit.com/r/FlutterDev/comments/i2dv6o/i_made_a_package_for_drawing_arrows_between_any/" rel="noopener noreferrer"&gt;FlutterDev subreddit&lt;/a&gt;.&lt;br&gt;
I thought I'd take a minute to explain how it works, since the technique can be applied to other things, such as a &lt;a href="https://www.flutterclutter.dev/flutter/tutorials/how-to-cut-a-hole-in-an-overlay/2020/510/" rel="noopener noreferrer"&gt;tutorial hole overlay&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Schwusch" rel="noopener noreferrer"&gt;
        Schwusch
      &lt;/a&gt; / &lt;a href="https://github.com/Schwusch/widget_arrows" rel="noopener noreferrer"&gt;
        widget_arrows
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Draw arrows between widgets in Flutter
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;widget_arrows&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;Draw arrows between widgets&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/a39a90347114bed6311a26c3fb0e1516551ced9cceb9b61aa7063a947d2cf7eb/68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f6769764665446f504c62574c6e5a637651522f67697068792e676966"&gt;&lt;img src="https://camo.githubusercontent.com/a39a90347114bed6311a26c3fb0e1516551ced9cceb9b61aa7063a947d2cf7eb/68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f6769764665446f504c62574c6e5a637651522f67697068792e676966" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Schwusch/widget_arrows" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;Using it is fairly straight forward, wrap the Widgets you want to draw arrows between with an &lt;a href="https://pub.dev/documentation/widget_arrows/latest/widget_arrows/ArrowElement-class.html" rel="noopener noreferrer"&gt;&lt;code&gt;ArrowElement&lt;/code&gt;&lt;/a&gt; and wrap both with an &lt;a href="https://pub.dev/documentation/widget_arrows/latest/widget_arrows/ArrowContainer-class.html" rel="noopener noreferrer"&gt;&lt;code&gt;ArrowContainer&lt;/code&gt;&lt;/a&gt; higher up in the Widget hierarchy .&lt;/p&gt;

&lt;p&gt;In this case I wrap the whole &lt;code&gt;MaterialApp&lt;/code&gt; in an &lt;code&gt;ArrowContainer&lt;/code&gt; in order to display the arrows while dragging an element:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/schwusch/embed/yLemBZQ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The core Widget is the &lt;code&gt;ArrowContainer&lt;/code&gt;, which is the one drawing the arrows on a canvas layered on top of the child, using a &lt;code&gt;Stack&lt;/code&gt;.&lt;br&gt;
Here's an example: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;span class="n"&gt;ArrowContainer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nl"&gt;children:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="n"&gt;ArrowElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;id:&lt;/span&gt; &lt;span class="s"&gt;'top'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;targetId:&lt;/span&gt; &lt;span class="s"&gt;'bottom'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Text1'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="n"&gt;ArrowElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;show:&lt;/span&gt; &lt;span class="n"&gt;showArrows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;id:&lt;/span&gt; &lt;span class="s"&gt;'bottom'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Text2'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;During &lt;code&gt;initState()&lt;/code&gt;, the &lt;code&gt;_ArrowElementState&lt;/code&gt; looks up the widget hierarchy and finds the closest &lt;code&gt;_ArrowContainerState&lt;/code&gt; and registers itself by calling &lt;code&gt;addArrow(this)&lt;/code&gt; on the container. The &lt;code&gt;_ArrowContainerState&lt;/code&gt; will then trigger a repaint on the &lt;code&gt;CustomPainter&lt;/code&gt; that draws on top of &lt;code&gt;ArrowContainer&lt;/code&gt;s child, which in this case is a &lt;code&gt;Column&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkakpxhetb19tfjxqm1we.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkakpxhetb19tfjxqm1we.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How does the &lt;code&gt;_ArrowElementState&lt;/code&gt; find the &lt;code&gt;_ArrowContainerState&lt;/code&gt;? By calling this method on the &lt;code&gt;BuildContext&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findAncestorStateOfType&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_ArrowContainerState&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since &lt;code&gt;ArrowContainer&lt;/code&gt; is a &lt;code&gt;StatefulWidget&lt;/code&gt;, it has its associated &lt;code&gt;_ArrowContainerState&lt;/code&gt;. It's a relatively expensive lookup, but the good news is that it is only needed once per &lt;code&gt;ArrowElement&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;_ArrowContainerState&lt;/code&gt; has &lt;code&gt;ChangeNotifier&lt;/code&gt; mixed in, in its class declaration. That means that it can be passed in as an argument to the &lt;code&gt;CustomPainter&lt;/code&gt; constructor, and it will repaint every time &lt;code&gt;_ArrowContainerState&lt;/code&gt; calls &lt;code&gt;notifyListeners()&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;_ArrowContainerState.notifyListeners()&lt;/code&gt; is called every time an arrow element is added or removed, which means it is always kept in sync with all &lt;code&gt;ArrowElement&lt;/code&gt;s currently mounted in its child &lt;code&gt;Widget&lt;/code&gt; subtree.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;_ArrowContainerState&lt;/code&gt; build method look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;span class="nd"&gt;@override&lt;/span&gt;
&lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Stack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;children:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="n"&gt;widget&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;child&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;IgnorePointer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;CustomPaint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nl"&gt;foregroundPainter:&lt;/span&gt; &lt;span class="n"&gt;_ArrowPainter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="n"&gt;_elements&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="n"&gt;Directionality&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
          &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;CustomPaint&lt;/code&gt; is wrapped with an &lt;code&gt;IgnorePointer&lt;/code&gt;, to let through touch events to &lt;code&gt;widget.child&lt;/code&gt;, which is the users real UI. The &lt;code&gt;_ArrowPainter&lt;/code&gt; is a custom class extending &lt;code&gt;CustomPainter&lt;/code&gt; to draw the Arrows. It takes the &lt;code&gt;_ArrowElementState&lt;/code&gt;s as a first argument, the &lt;code&gt;TextDirection&lt;/code&gt; as the second argument (we will cover why later), and a &lt;code&gt;Listenable&lt;/code&gt; as the third argument. The &lt;code&gt;_ArrowContainerState&lt;/code&gt; is a &lt;code&gt;Listenable&lt;/code&gt;, due to having &lt;code&gt;ChangeNotifier&lt;/code&gt; mixed in.&lt;/p&gt;

&lt;p&gt;What happens in &lt;code&gt;_ArrowPainter.paint()&lt;/code&gt; is the real magic. It loops through all &lt;code&gt;_ArrowElementState&lt;/code&gt;s, and calls this method:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;renderBox&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arrowElementState&lt;/span&gt;
                    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;context&lt;/span&gt;
                    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findRenderObject&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;RenderBox&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;RenderBox&lt;/code&gt; is the key to finding the position of the start and end of the arrows we're about to draw.&lt;br&gt;
By calling this method:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;Offset&lt;/span&gt; &lt;span class="n"&gt;upperLeftCorner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;renderBox&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;localToGlobal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Offset&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;zero&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We get an &lt;code&gt;Offset&lt;/code&gt; of where it is relative to the top-left corner of the screen. The &lt;code&gt;RenderBox&lt;/code&gt; also has &lt;code&gt;RenderBox.size&lt;/code&gt; which gives us its dimensions, which is used to describe the rectangle in which the child is drawn. &lt;/p&gt;

&lt;p&gt;This is where &lt;code&gt;TextDirection&lt;/code&gt; comes in. The &lt;code&gt;ArrowElement&lt;/code&gt; has a &lt;code&gt;sourceAnchor&lt;/code&gt; and a &lt;code&gt;targetAnchor&lt;/code&gt; argument which takes an &lt;a href="https://api.flutter.dev/flutter/painting/AlignmentGeometry-class.html" rel="noopener noreferrer"&gt;&lt;code&gt;AlignmentGeometry&lt;/code&gt;&lt;/a&gt;. This allows us to specify where in the child &lt;code&gt;Widget&lt;/code&gt; we like the arrow to start or end from, and is &lt;code&gt;Alignment.centerLeft&lt;/code&gt; by default. You can pass an &lt;a href="https://api.flutter.dev/flutter/painting/AlignmentDirectional-class.html" rel="noopener noreferrer"&gt;&lt;code&gt;AlignmentDirectional&lt;/code&gt;&lt;/a&gt; to make it adapt to whether the text is right-to-left or left-to-right. To adapt to the text direction, this method is called on the &lt;code&gt;AlignmentGeometry&lt;/code&gt; object:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;Offset&lt;/span&gt; &lt;span class="n"&gt;startPosition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sourceAnchor&lt;/span&gt;
  &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;textDirection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;withinRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/*child widget rectangle*/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;From there, all that's left is to draw a &lt;code&gt;Path&lt;/code&gt; or whatever you like on the canvas at that position.&lt;/p&gt;

&lt;p&gt;Happy Fluttering!&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
    </item>
    <item>
      <title>Does null safety (really) bring any value to businesses?</title>
      <dc:creator>Jonathan Böcker</dc:creator>
      <pubDate>Tue, 17 Sep 2019 10:09:52 +0000</pubDate>
      <link>https://forem.com/schwusch/does-null-safety-really-bring-any-value-to-businesses-39m7</link>
      <guid>https://forem.com/schwusch/does-null-safety-really-bring-any-value-to-businesses-39m7</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FWTDnnwE.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FWTDnnwE.gif" alt="Beating a dead horse"&gt;&lt;/a&gt;&lt;em&gt;Here goes another article about null&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &amp;lt;TL;DR&amp;gt;
&lt;/h4&gt;

&lt;p&gt;It seems to me that including nullability in type systems is an obvious technical step forward in operational security and cost effectiveness. The market is either lagging behind or I am overestimating its value. Perhaps I am part of a daring but naive minority that gives too much credit to safer type systems.&lt;/p&gt;

&lt;h4&gt;
  
  
  &amp;lt;/TL;DR&amp;gt;
&lt;/h4&gt;

&lt;p&gt;Null safety has become quite fashionable in mainstream platforms. Languages such as Swift and Kotlin is endorsed by Apple and Google for use in their platforms. Rust is all the hype in systems programming and WebAssembly. C# received non-nullable types in its 8th edition and TypeScript is gaining traction as a replacement for JavaScript. The Dart team is working hard to make a similar journey in what they call &lt;a href="https://github.com/dart-lang/language/issues/110" rel="noopener noreferrer"&gt;Non-Null By Default(NNBD)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the same time, I have encountered development teams where this topic is not spoken of, almost as if this &lt;em&gt;null problem&lt;/em&gt; that so many language creators is working on is a non-issue. Many developers go about in their Java/C++/JavaScript code base, adding value to their company as intended, not adopting this &lt;em&gt;null-safe fad&lt;/em&gt;. Null safe languages is rarely in the top 10 when measuring most used/most popular languages such as &lt;a href="https://www.tiobe.com/tiobe-index/" rel="noopener noreferrer"&gt;TIOBE index&lt;/a&gt; and &lt;a href="https://octoverse.github.com/projects#languages" rel="noopener noreferrer"&gt;Github Octoverse&lt;/a&gt;, with the exception of C# (not measuring the usage of C#8 and onward) and TypeScript (measured in open source projects).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We manage to build software very well without null safety, thank you very much." - Mr Straw Man, for the sake of this argument&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is a million reasons not to solve this theoretical issue, and I sympathize with a lot of them. Introducing new technical decisions is always a risk, and there has to be equal or larger benefit balancing out the risk-reward scale. It might be a good idea to compare this paradigm leap to paradigm shifts of similar magnitude. The object-oriented paradigm brought a &lt;a href="https://en.wikipedia.org/wiki/Nominal_type_system" rel="noopener noreferrer"&gt;nominal type system&lt;/a&gt; which has been widely adopted and brings many benefits when statically typed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Java&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;meow&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;bark&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="n"&gt;doggie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;doggie&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;meow&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Compiler error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example might be obvious and intuitive as to why it will not, and should not, work. It is hard to quantify how much value the nominal type system has brought to businesses, but the popularity is statistically clear. The object-oriented languages has won the market with a landslide.&lt;/p&gt;

&lt;p&gt;It is harder to reason about, and explain why this should be able to compile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Java&lt;/span&gt;
&lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="n"&gt;doggie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;doggie&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;bark&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Compiles but explodes at runtime&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is seemingly no good reason for this to be allowed, but it just is the way most popular languages work. It can seem a bit disorderly for a newcomer that a type system made to protect the programmer from common mistakes allows for this "shadow" type system. An extra dimension, where you as a programmer has to act as a compiler and find these programmatic landmines. Landmines that plague applications in production everyday, since humans are not as competent as compilers at finding type system errors.&lt;/p&gt;

&lt;p&gt;"But &lt;code&gt;null&lt;/code&gt; is a value and not a type, and should be evaluated at runtime", someone might add. True in a sense, but most type systems does not allow an instance of &lt;code&gt;Cat&lt;/code&gt; to be assigned to a &lt;code&gt;Dog&lt;/code&gt;-typed variable. I would argue the instantiated &lt;code&gt;Cat&lt;/code&gt; is a value, at least when assigned to a &lt;code&gt;Cat&lt;/code&gt;-typed variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tony Hoare says it is a bad idea, and it is his invention
&lt;/h3&gt;

&lt;p&gt;Most people have heard or read &lt;a href="https://en.wikipedia.org/wiki/Tony_Hoare" rel="noopener noreferrer"&gt;Tony Hoare&lt;/a&gt; declaring null references as his "billion dollar mistake", and it deserves to be repeated. There is a reason why so many languages deals with this. A weak but colorful analogy would be firearms, which in most cases has what is called a &lt;a href="https://en.wikipedia.org/wiki/Safety_(firearms)" rel="noopener noreferrer"&gt;&lt;em&gt;safety catch&lt;/em&gt;&lt;/a&gt; to somewhat reduce the risk of an accidental discharge. It is questionable whether a safety catch is a good idea when the user needs to fire the weapon as fast as possible in a threatening situation. Still most, if not all, military and police weapons implement some kind of safety catch. This could seem unproductive if the human factor were not accounted for, but it is indubitably a good idea when considering the users, probably stressed and maybe even sleep deprived.&lt;/p&gt;

&lt;p&gt;When push comes to shove we need to compensate the human factor through the safety of their tools. A classic &lt;a href="https://en.wikipedia.org/wiki/Risk_assessment" rel="noopener noreferrer"&gt;risk vs consequence analysis&lt;/a&gt; has to be made before deciding on the tool to be used by the many.&lt;br&gt;
This leaves me wondering about the rationale behind the choice of a programming language without a null safety catch. Is the probability of a programmer forgetting a manual null check dismissably low, or is the eventual consequences considered tolerable?&lt;/p&gt;

&lt;h3&gt;
  
  
  Not all accidents can be prevented
&lt;/h3&gt;

&lt;p&gt;Stray bullets still fire despite weapon safeties and applications crash or break even when implemented with type-safe languages. Why do language creators still bother creating these complex compiler heuristics, offering us these implied senses of security?&lt;br&gt;
One could argue it gives the programmer a peace of mind while focusing on the main task at hand. Why doing cognitive work that can be offloaded to a compiler, says the pragmatist. The compiler can never catch all bugs, so it is better to check it properly yourself, the cynic would argue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Return_on_investment" rel="noopener noreferrer"&gt;Return of investment (ROI)&lt;/a&gt; is a central concept to businesses, and technical decisions is no exempt to this reasoning. If the price of the safety catch quadruples the price of the gun, an argument can be made to just train the soldier to be more careful. If the price of development would rise in disproportion to the gains of security by choosing a type-safe language, it would be no wonder why Java and C++ is still popular. It is however not as easy to measure alternative development costs as it is to measure the costs of different weapon configurations.&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>swift</category>
      <category>dart</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
