<?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: Ardi</title>
    <description>The latest articles on Forem by Ardi (@devardi).</description>
    <link>https://forem.com/devardi</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%2F1059512%2Fd876138d-d733-4828-9875-84cb7df5fdfe.jpg</url>
      <title>Forem: Ardi</title>
      <link>https://forem.com/devardi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/devardi"/>
    <language>en</language>
    <item>
      <title>Don't learn C</title>
      <dc:creator>Ardi</dc:creator>
      <pubDate>Fri, 23 Feb 2024 00:14:57 +0000</pubDate>
      <link>https://forem.com/devardi/dont-learn-c-to-learn-how-computers-work-16ie</link>
      <guid>https://forem.com/devardi/dont-learn-c-to-learn-how-computers-work-16ie</guid>
      <description>&lt;p&gt;There is a murmur in tech twitter lately that you should &lt;em&gt;just learn C&lt;/em&gt; in order to learn how the computer &lt;em&gt;really&lt;/em&gt; works. Don't do that. Read a book.&lt;/p&gt;

&lt;p&gt;It is a well known fact that most programmers have a brittle understanding of their computer. They sit nicely in their ivory tower of abstraction, building very complex systems while completely disregarding all of the tech stack they're sitting on. Thanks to the absolute dominance of programming languages with automatic memory management many of the programmers of this group have never had to think about memory, and then they are surprised when their pretty little nodejs consumes gigabytes of memory.&lt;/p&gt;

&lt;p&gt;Recently there has been discussion that to solve this you should just learn C. C is supposed to be low level, you manage your memory yourself, you code for the hardware - you tell C what to do and it translates nicely to machine code that you can understand and be happy in a rainbow world full of computer candy :)&lt;/p&gt;

&lt;p&gt;WRONG! You don't code for the hardware - you code for the &lt;a href="https://en.wikipedia.org/wiki/Abstract_machine#:~:text=In%20computer%20science%2C%20an%20abstract,outputs%20based%20on%20predefined%20rules."&gt;&lt;em&gt;Abstract Machine&lt;/em&gt;&lt;/a&gt;. What your program does is most definitely not what the hardware does!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What are you talking about?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What do you think happens when you have a char - an 8 bit signed integer - with the value 127 and you add one to it? If you paid attention in class you might know that with &lt;a href="https://en.wikipedia.org/wiki/Two%27s_complement"&gt;2's complement&lt;/a&gt; it should loop around to -126. And you would be right! That is, if C actually cared about the hardware. It turns out that &lt;a href="https://stackoverflow.com/questions/18195715/why-is-unsigned-integer-overflow-defined-behavior-but-signed-integer-overflow-is"&gt;for historical reasons&lt;/a&gt; that is &lt;a href=""&gt;undefined behaviour&lt;/a&gt;(UB), which means that it could actually wrap around, optimize your code, &lt;a href="http://catb.org/jargon/html/N/nasal-demons.html"&gt;or even make demons come out of your nose&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Or if you have an array and you mistakingly access out of bounds, that's also UB. In fact, there are A LOT of &lt;a href="https://gist.github.com/Earnestly/7c903f481ff9d29a3dd1"&gt;behaviours considered undefined&lt;/a&gt; in C that you could code in assembly (probably by mistake though).&lt;/p&gt;

&lt;p&gt;It turns out that what you tell C to do is not what the CPU will end up doing because C has an optimizing compiler. Most of the time it will end up just tweaking what code it outputs keeping its behavior the same but there are times where it will take some liberties. While you are learning C you have to learn about all of these quirks and footguns, and you're not really learning that much about the computer itself.&lt;/p&gt;

&lt;p&gt;There are a lot of web developers that don't understand how memory works and that should be addressed, but telling them to &lt;em&gt;just learn C&lt;/em&gt; is not enough. Having a basic understanding of how the computer works can definitely be achieved by some basic reading and yes - maybe write some C, implement &lt;code&gt;memcpy&lt;/code&gt; and a toy &lt;code&gt;malloc&lt;/code&gt; but C shouldn't be the goal, only the medium.&lt;br&gt;
Read a book that teaches you these concepts, don't &lt;em&gt;just learn C&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The same can be said for operating systems but honestly even Node.js allows you to work with &lt;a href="https://nodejs.org/api/fs.html#filehandlereadbuffer-options"&gt;raw file descriptors and buffers&lt;/a&gt;. There is indeed value in working with low level APIs, I think all programmers at some point in their life should manually read(2) from a file, at least to have an idea of how it works.&lt;/p&gt;

&lt;p&gt;But what do I know? Most programmers don't know and don't care about what goes on when they &lt;code&gt;fetch()&lt;/code&gt; and they seem to be doing fine. I always feel like an old man screaming at the sky but I think it's sad that people have such a shallow and brittle understanding of the systems that they use. But when they venture out to the deep waters, to the prohibited knowledge that lies below they should probably be hand held by a good systems book.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>SVG is a lie.</title>
      <dc:creator>Ardi</dc:creator>
      <pubDate>Sat, 08 Apr 2023 15:55:08 +0000</pubDate>
      <link>https://forem.com/devardi/svg-is-a-lie-29a</link>
      <guid>https://forem.com/devardi/svg-is-a-lie-29a</guid>
      <description>&lt;p&gt;SVG is a lie.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What?" You might ask. "It obviously exists, what are you talking about? Are you stupid?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, SVG exists. What is a lie about it is the mystique it has, the widely spread misconception that SVGs are a small and efficient way to store images. That might have been true at some point in the past, but not anymore, at least most of the time.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"But SVGs are just vector graphics, they should be really small and efficient!"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I would agree, there should be no world where raster images would be smaller than vector graphics but here we are.&lt;/p&gt;

&lt;p&gt;It turns out that SVGs are actually XML and plain text. Fortunately we moved as an industry away from XML, but there are still vestiges, such as HTML or SVG. Plain text is not really the most efficient way to describe images, unless you're doing it by hand, and I'm against editing SVG manually. We got tools for that! &lt;br&gt;
Unless you're doing something really simple like an x of a hamburger menu you should probably stay away from it.&lt;/p&gt;

&lt;p&gt;You can think about SVGs like having O(1) complexity, but with a high baseline cost. Yes, when you scale them up they will be extremely efficient but when they're small, which is almost always, they will lead to increased bundle sizes and if you have a lot of them it might get a bit slow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe11m9eh126pla8uwjwvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe11m9eh126pla8uwjwvk.png" alt="Your network on svg" width="800" height="800"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Your network on svg&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  My findings
&lt;/h2&gt;

&lt;p&gt;The most common use case for SVGs is icons. Most icons get designed and created in vector graphic editors like &lt;a href="https://inkscape.org/"&gt;inkscape&lt;/a&gt; or &lt;a href="https://www.adobe.com/products/illustrator.html"&gt;Adobe Illustrator&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Icons tend to be small, ~16-50px&lt;/p&gt;

&lt;p&gt;Let's run an experiment. For my personal website I downloaded a bunch of icons for the technologies and programming languages I know. Some of them happened to be SVG. Let's see their sizes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ find . -name "*.svg"  -exec ls -lh {} \; | awk '{print $9, $5}' | sort
./css.svg 473
./c.svg 1,4K
./c++.svg 1,6K
./docker.svg 1,4K
./git.svg 703
./go.svg 1,7K
./nodejs.svg 1,7K
./postgres.svg 4,3K
./python.svg 1,1K
./rabbitmq.svg 745
./react.svg 11K
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can see that the average icon is ~1KB, except for a few outliers. It's ironic that the biggest one is react, a framework famous for being bloated and slow. :P&lt;/p&gt;

&lt;p&gt;Let's try now in webp format! The webp folks have done a great job, &lt;a href="https://developers.google.com/speed/webp/docs/webp_lossless_alpha_study"&gt;claiming 25% size decreases over png&lt;/a&gt; and &lt;a href="https://developers.google.com/speed/webp/docs/webp_study"&gt;25/35% over jpeg&lt;/a&gt; The icons used in my page are 50px in height, so let's resize them to the correct size.&lt;/p&gt;

&lt;p&gt;I'm using imagemagick's mogrify for this.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ mogrify -resize x50 -format webp *.svg&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./css.webp 562
./c.webp 588
./c++.webp 712
./docker.webp 596
./git.webp 502
./go.webp 482
./nodejs.webp 578
./postgres.webp 678
./python.webp 478
./rabbitmq.webp 404
./react.webp 800
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WOW! The average here is around ~500B, with some even being 6.8x and 13.8x smaller, while most being 2-3x smaller.&lt;/p&gt;

&lt;p&gt;The first time I saw this I couldn't believe my eyes. All my life I thought that SVGs were amazing, small, efficient... &lt;br&gt;
It's great to see that the image compression world has come this far.&lt;/p&gt;

&lt;p&gt;These are insane gains, let's see what would happen for favicons, which are 16px&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mogrify -resize x16 -format webp *
$ find . -name "*.webp"  -exec ls -lh {} \; | awk '{print $9, $5}' | sort

./css.webp 204
./c.webp 196
./c++.webp 226
./docker.webp 190
./git.webp 186
./go.webp 160
./nodejs.webp 178
./postgres.webp 206
./python.webp 192
./rabbitmq.webp 164
./react.webp 184
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are spectacular gains. The react icon was 60 times smaller!&lt;/p&gt;

&lt;p&gt;In practice this is not very meaningful. You only have one favicon and 800 bytes are not very significant.&lt;/p&gt;

&lt;p&gt;But if it happens that you're sending a large quantity of icons that might start to matter, it's all about the scale.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But Ardi - what if you minify the SVG? &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You're right! Let's try to optimize it using &lt;a href="https://github.com/svg/svgo"&gt;svgo&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ svgo .


Processing directory '.':
c.svg:
1.359 KiB - 31.3% = 0.935 KiB

c++.svg:
1.547 KiB - 33.3% = 1.032 KiB

git.svg:
0.687 KiB - 20.6% = 0.545 KiB

go.svg:
1.64 KiB - 16.8% = 1.364 KiB

css.svg:
0.462 KiB - 13.7% = 0.398 KiB

docker.svg:
1.375 KiB - 9.2% = 1.248 KiB

nodejs.svg:
1.606 KiB - 15.4% = 1.359 KiB

postgres.svg:
4.212 KiB - 10% = 3.789 KiB

rabbitmq.svg:
0.728 KiB - 0% = 0.728 KiB

python.svg:
1.081 KiB - 9.7% = 0.977 KiB

react.svg:
10.592 KiB - 16.6% = 8.836 KiB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, that's underwhelming. What if we gzip them? Most traffic usually gets gzipped to save bandwith anyways!&lt;/p&gt;

&lt;p&gt;(webp of 50px)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./css.svg.gz 276
./css.webp.gz 372
./c.svg.gz 528
./c.webp.gz 400
./docker.svg.gz 668
./docker.webp.gz 389
./git.svg.gz 321
./git.webp.gz 360
./go.svg.gz 564
./go.webp.gz 299
./nodejs.svg.gz 747
./nodejs.webp.gz 367
./postgres.svg.gz 2,0K
./postgres.webp.gz 421
./python.svg.gz 545
./python.webp.gz 397
./rabbitmq.svg.gz 454
./rabbitmq.webp.gz 295
./react.svg.gz 4,1K
./react.webp.gz 406
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's clear that for icons SVGs are bigger than raster images.&lt;br&gt;
However they still have their uses. Mainly CSS animations and larger background images. &lt;br&gt;
If you're doing this SVGs are a fantastically flexible tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclussion
&lt;/h2&gt;

&lt;p&gt;We are engineers at the end of the day. We should understand the trade-offs of the tools we use. &lt;/p&gt;

&lt;p&gt;Most of the time you won't even care about the size of your icons. But if you are, perhaps because you're using a CDN and were considering using a tool such as svgo I hope that at least you consider checking the size of the rastered image. &lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>performance</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Confessions from a Golfer Programmer</title>
      <dc:creator>Ardi</dc:creator>
      <pubDate>Wed, 05 Apr 2023 15:21:40 +0000</pubDate>
      <link>https://forem.com/devardi/confessions-from-a-golfer-programmer-3fb5</link>
      <guid>https://forem.com/devardi/confessions-from-a-golfer-programmer-3fb5</guid>
      <description>&lt;p&gt;I love code. Not all code, just beautiful code.&lt;/p&gt;

&lt;p&gt;One of my favorite activities is to refactor - transmuting a program that works into another that does exactly the same thing, but better: Making it run faster, changing it so that it's shorter or &lt;em&gt;more idiomatic&lt;/em&gt;, whatever that means; removing some nasty duplication, etc.&lt;br&gt;
It makes me happy in the inside to see commits that have more removals than additions, which  is probably the opposite of what the product manager likes to see.&lt;/p&gt;

&lt;p&gt;This is not a good quality to have, however. It's easy for me to get engrossed in the beauty of my own - or someone else's - code, and not get anything done.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Look!" I conceitedly exclaimed. "I've reduced the size of the function to one third its size"&lt;br&gt;
"Nice, have you added the feature already? we really need it" My coworker inquired&lt;br&gt;
"On it..." Realizing that I spent half an hour and it's still unstarted.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;I come from javascript, where every time you try to do something minimally declarative your javascript engine dies a bit on the inside, and the garbage collector wishes you very bad things. &lt;/p&gt;

&lt;p&gt;Let's say that our backend has a function that requests IDs. These IDs can be empty (&lt;code&gt;""&lt;/code&gt;), and we want to ignore those. It gets the users from a dictionary in memory, and then returns the ones that it has found that are validated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getValidatedUsers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userIDs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two ways to achieve this. &lt;/p&gt;

&lt;p&gt;The imperative way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getValidatedUsers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userIDs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]):&lt;/span&gt; &lt;span class="nx"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;userIDs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;UsersDictionary&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValidated&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&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 declarative way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getValidatedUsers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userIDs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]):&lt;/span&gt; &lt;span class="nx"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;userIDs&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;UsersDictionary&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValidated&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Which could even be written more &lt;/span&gt;
&lt;span class="c1"&gt;// concisely with arrow function syntax.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To me the declarative way more beautiful and clear, the steps look simple and ordered...&lt;/p&gt;

&lt;p&gt;...But you would be a fool to use it. &lt;/p&gt;

&lt;p&gt;The engine &lt;strong&gt;copies the array&lt;/strong&gt; 4 times which involves a heap allocation, a memory copy and later on a garbage collection pause that is guaranteed to happen at the worst possible time, all of the time. Not to mention the closures generated too. You won't see me writting javascript that looks like that in code that needs to be even minimally performant, &lt;strong&gt;especially not&lt;/strong&gt; in node, which is single threaded and your pretty little declarative function is slowing down the rest of the server.&lt;/p&gt;




&lt;p&gt;I love Rust (I promise this is not another blog of Rust propaganda), which probably doesn't come as a surprise given that I'm your stereotypical nerd. Rust is great, but it's also my greatest demise. &lt;/p&gt;

&lt;p&gt;My first contact with the expresiveness of Rust blew me away. You can use the declarative way, you can use beautiful declarative code, all without it slowing anything down (it even has the potential to get optimized into being faster!).&lt;/p&gt;

&lt;p&gt;Rust is famous for its error handling. It does not support exceptions, instead opting for returning the errors to the caller. The first time I heard of it I thought that it was a step backwards, a return to C and its error code returning. But I was wrong, rust has exceptional tools for working with errors.&lt;/p&gt;

&lt;p&gt;Here's an example from &lt;a href="https://github.com/SeleniumHQ/selenium/tree/trunk/rust"&gt;selenium-manager, maintained by the selenium project&lt;/a&gt; and a contribution I made&lt;/p&gt;

&lt;p&gt;This calls three functions that can fail: &lt;code&gt;set_timeout&lt;/code&gt;, &lt;code&gt;set_proxy&lt;/code&gt; and &lt;code&gt;resolve_driver&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If any of them fails the program exits with a return code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.set_timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cli&lt;/span&gt;&lt;span class="py"&gt;.timeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;flush_and_exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DATAERR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&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="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.set_proxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cli&lt;/span&gt;&lt;span class="nf"&gt;.proxy&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;flush_and_exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DATAERR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&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="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.resolve_driver&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;driver_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;selenium_manager&lt;/span&gt;
            &lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="nf"&gt;.info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;driver_path&lt;/span&gt;&lt;span class="nf"&gt;.display&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="nf"&gt;flush_and_exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;flush_and_exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DATAERR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&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;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hd58u5vf8f9f0a8askm.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hd58u5vf8f9f0a8askm.jpeg" alt="A programmer playing golf" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is where my golfer self comes in, I want to make this code as concise as I can.&lt;/p&gt;

&lt;p&gt;First, let's use &lt;code&gt;if let Err&lt;/code&gt;, which could translate to javascript's &lt;code&gt;if (my_fn() instanceof Error)&lt;/code&gt; and extract the error to a function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;err_out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;flush_and_exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DATAERR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.set_timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cli&lt;/span&gt;&lt;span class="py"&gt;.timeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;err_out&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.set_proxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cli&lt;/span&gt;&lt;span class="py"&gt;.proxy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;err_out&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.resolve_driver&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;selenium_manager&lt;/span&gt;
            &lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="nf"&gt;.info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;flush_and_exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;err_out&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&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;But Rust has so much more to offer.  Notice that there's a &lt;em&gt;happy path&lt;/em&gt; (continue) and a &lt;em&gt;gutter&lt;/em&gt;, where all of the errors go.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnargaaf4bl5lvfuvracs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnargaaf4bl5lvfuvracs.png" alt="Image description" width="720" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a common pattern, and Rust has really nice tools for working with these in a declarative way. We can use all of the expressiveness of rust to &lt;em&gt;golf this down&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;selenium_manager&lt;/span&gt;
    &lt;span class="nf"&gt;.set_timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cli&lt;/span&gt;&lt;span class="py"&gt;.timeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.and_then&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.set_proxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cli&lt;/span&gt;&lt;span class="py"&gt;.proxy&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;.and_then&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.resolve_driver&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;.and_then&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// If all of them succeed&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="nf"&gt;.info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;flush_and_exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;OK&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="nf"&gt;.unwrap_or_else&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// If any of them fail&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;selenium_manager&lt;/span&gt;&lt;span class="nf"&gt;.get_logger&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="nf"&gt;.error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;flush_and_exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DATAERR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;log&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;This is reminiscent of the code we saw earlier in javascript, this time with errors, which in my eyes makes all of it much easier to read and understand, and most importantly: More beautiful. The only metric that matters.&lt;/p&gt;

&lt;p&gt;All of these changes are cool and all, but they provide no value. The end user doesn't care, the compiler doesn't care either (they're equivalent), but I care. I'm in for the aesthetics, but don't tell my boss.&lt;/p&gt;

&lt;p&gt;When I have to make functional changes they break the perfect aesthetic, but given the time to refactor it will become something even more beautiful than before, complexity that has been tamed into a coherent piece of machinery. &lt;/p&gt;

&lt;p&gt;With no time given to making it look beautiful it will become an ugly mess, but an ugly mess that works. There's value in that.&lt;/p&gt;




&lt;p&gt;One time when I read the code of a junior coworker of mine, I physically shivered, horrified at some of the things I saw, and I felt an urge to fix it (this is one example of such):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;isDebug&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;debug&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;true&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&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;I'm not kidding, that's real code. I emotionally had the need to rewrite it to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;isDebug&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;debug&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;true&lt;/span&gt;&lt;span class="dl"&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;I doesn't make me happy that they save it to localStorage, that's part of a bigger bodge that I don't even want to look at.&lt;/p&gt;

&lt;p&gt;But that was a part of the code that didn't affect me in any way, I just tumbled with it and couldn't look away.&lt;br&gt;
It might not be pretty but their code &lt;strong&gt;worked&lt;/strong&gt;, and at the end of the day that's what matters. I have so much to learn from them :)&lt;/p&gt;




&lt;p&gt;That was it, I hope you liked my first post. &lt;br&gt;
Remember when I said I wasn't going to make Rust propaganda? I kind of lied a bit there :)&lt;/p&gt;

</description>
      <category>rust</category>
      <category>typescript</category>
      <category>refactoring</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
