<?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>DEV Community: kalium.xyz</title>
    <description>The latest articles on DEV Community by kalium.xyz (@kalium).</description>
    <link>https://dev.to/kalium</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%2F171675%2F3c19311e-360d-49d7-82af-bc52e893508b.png</url>
      <title>DEV Community: kalium.xyz</title>
      <link>https://dev.to/kalium</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kalium"/>
    <language>en</language>
    <item>
      <title>Brainf*ck in 5 minutes.</title>
      <dc:creator>kalium.xyz</dc:creator>
      <pubDate>Sun, 11 Aug 2019 15:28:48 +0000</pubDate>
      <link>https://dev.to/kalium/brainf-ck-in-5-minutes-bim</link>
      <guid>https://dev.to/kalium/brainf-ck-in-5-minutes-bim</guid>
      <description>&lt;p&gt;The easiest least readable programming language I’ve written in so far has to be Brainf*ck. Brainf*ck is what I’d call a tacobell programming language, everything is made from the same 8 ingredients. You use the 8 operators to manipulate one datapointer (a number stored somewhere) and to change datapointers (Brainf*ck has 30.000 datapointers). &lt;/p&gt;

&lt;p&gt;The operators are as follows:&lt;br&gt;
“&amp;gt;” moves the datapointer to the right.&lt;br&gt;
“&amp;lt;”  moves the datapointer to the left. &lt;br&gt;
“+” increases the selected datapointer by one.&lt;br&gt;
“-” decreases the selected datapointer by one.&lt;br&gt;
“.” outputs the number in the selected datapointer as an ASCII character.&lt;br&gt;
“,” reads one character from input and writes it to the datapointer.&lt;br&gt;
“[” if the current datapointer is at 0, then skip to the next “]”.&lt;br&gt;
“]” if the current datapointer is not at 0, then go back to the last “[”.&lt;/p&gt;

&lt;p&gt;Take note of the last two being able to form a loop to do clever manipulations.&lt;/p&gt;

&lt;p&gt;So now that you know the commands you want to print the text: “Hello world!” as is traditionally the first thing to do with any new programming language. You start by looking up the ASCII number for every character:&lt;br&gt;
H = 72,&lt;br&gt;
e = 101,&lt;br&gt;
l = 108,&lt;br&gt;
l = 108,&lt;br&gt;
o = 111,&lt;br&gt;
space = 32,&lt;br&gt;
w = 119,&lt;br&gt;
o = 111,&lt;br&gt;
r = 114,&lt;br&gt;
l = 108,&lt;br&gt;
d = 100, &lt;br&gt;
! = 33.&lt;/p&gt;

&lt;p&gt;Now the first datapointer will be used as an index for the loops, the second for the characters, and a third one for the space and exclamation mark. following below is the tutorial. &lt;/p&gt;

&lt;p&gt;First we want 72, we know that 72 = 12 * 6 so we set the index to 6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;++++++
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then we start a loop that increments our second datapointer by 12 for every point it deducts in the first datapointer (making it go up to 72 before our loop stops)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[&amp;gt;++++++++++++&amp;lt;-]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And then we can print the “H”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we need to increment the second datapointer by 101 - 72 = 29, a prime number so the same trick won’t work again. We will use 28 + 1 instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;++++[&amp;gt;+++++++&amp;lt;-]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can now print the “e” and simply do +7, print again twice, +3 and print again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;+.+++++++..+++.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we are going to use the third pointer, put it at 4 * 8 = 32 and print space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;++++[&amp;gt;&amp;gt;++++++++&amp;lt;&amp;lt;-]&amp;gt;&amp;gt;.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Back to the second pointer for the rest of the letters same as before.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;++++++++.--------.+++.------.--------.&amp;gt;+.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our final code will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;++++++[&amp;gt;++++++++++++&amp;lt;-]&amp;gt;.&amp;lt;++++[&amp;gt;+++++++&amp;lt;-]&amp;gt;+.+++++++..+++.&amp;lt;++++[&amp;gt;&amp;gt;++++++++&amp;lt;&amp;lt;-]&amp;gt;&amp;gt;.&amp;lt;++++++++.--------.+++.------.--------.&amp;gt;+.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Easily writeable and understandable.&lt;/p&gt;

&lt;p&gt;Online brainf*ck interpretator:&lt;br&gt;
&lt;a href="https://copy.sh/brainfuck/"&gt;https://copy.sh/brainfuck/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>inclusion</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What made you get into programming?</title>
      <dc:creator>kalium.xyz</dc:creator>
      <pubDate>Sat, 10 Aug 2019 19:50:13 +0000</pubDate>
      <link>https://dev.to/kalium/what-made-you-get-into-programming-3bie</link>
      <guid>https://dev.to/kalium/what-made-you-get-into-programming-3bie</guid>
      <description>&lt;p&gt;Why (and when) did you get into programming?&lt;/p&gt;

&lt;p&gt;Do you feel that the modern "everyone should code" push is what got you into it?&lt;/p&gt;

</description>
      <category>inclusion</category>
      <category>beginners</category>
      <category>career</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Game of monkeys and ladders, how to learn wrong behavior while being rational.</title>
      <dc:creator>kalium.xyz</dc:creator>
      <pubDate>Fri, 09 Aug 2019 01:05:27 +0000</pubDate>
      <link>https://dev.to/kalium/games-of-monkeys-and-ladders-how-to-learn-wrong-behavior-while-being-rational-3hbh</link>
      <guid>https://dev.to/kalium/games-of-monkeys-and-ladders-how-to-learn-wrong-behavior-while-being-rational-3hbh</guid>
      <description>&lt;p&gt;So it starts, people disable swap space on their Linux servers and desktops then much later complain about their computers choking when they use up all their preciously guarded memory. "Why would anyone design an OS like this!" they lament, well its simple. Your home computer is a variable load machine and not some static production server with a known workload, and even then disabling swap space if you do not have perfect knowledge of the system is hardly a sin.&lt;/p&gt;

&lt;p&gt;There is an anecdote I heard a while back that perfectly describes how these situations happen: Scientists set up an observation room with sprinklers in it and a banana on a ladder. They let three monkeys in the room. Whenever a monkey goes to climb the ladder the scientists turn the sprinklers on till the monkeys learn to keep each other from climbing the ladder. Now the scientists switch out one of the monkeys for a fresh one without any memory of the evil cold sprinklers. This new monkey only sees a delicious piece of fruit right for the picking, however whenever he climbs the ladder the other monkeys will become aggressive and beat him till he learns to do to not do so. The scientists observing this replace another one of the original two remaining with a fresh monkey. The cycle repeats with both the oldest and older monkey joining in the beating and the new monkey learns not the climb the ladder. This is when the scientists replace the final monkey and remove the sprinklers. When the final monkey comes in and tries to climb the ladder the other two will stop him from climbing by beating the shit out of him. None of these monkeys know why but they all understand perfectly that you should not climb the ladder.&lt;/p&gt;

&lt;p&gt;Lets think about this, Some credible guy said something and we follow it. This is rational, though its quite likely he gathers his opinions from others (turns out you can only really talk to other people and yourself). Now we should first and foremost go trough the tedious process of asking why he is doing something before we try to do it ourselves. Remember our ability to communicate is about the only thing that sets us apart from the monkeys.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Building a JSON parser for great good</title>
      <dc:creator>kalium.xyz</dc:creator>
      <pubDate>Wed, 17 Jul 2019 10:56:00 +0000</pubDate>
      <link>https://dev.to/kalium/building-a-json-parser-for-great-good-39mo</link>
      <guid>https://dev.to/kalium/building-a-json-parser-for-great-good-39mo</guid>
      <description>&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;A good way to learn more about programming languages is by understanding how they work. The best way to understand something is to have made it in the first place. Today we set out to build a simple JSON parser using the specs on &lt;a href="//json.org"&gt;json.org&lt;/a&gt;. JSON is a fairly straightforward and well documented spec so it is a good target for learning how to write a parser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Process of parsing
&lt;/h2&gt;

&lt;p&gt;JSON gets parsed into a data structure, so we don't have to worry about anything but the translation of a JSON string to the data structure. The first step in the process of translating the JSON file into a more abstract JSON object is called tokenization, lexical analysis or lexing. These terms are often used interchangeably. Lexing and lexical analysis are more often used in natural language processing and have their roots in linguistics. The process is as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;the tokenizer gets called with a string lets say: &lt;code&gt;{ "key": "value"}&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The string gets broken down in units of meaning (e.g. keywords, separators, operators). The way we do this is by simply scanning over every single character and changing our mode of operation to accommodate (see an opening curly brace? we are dealing with a JSON object, opening square bracket? an array). These units of meaning are called tokens or lexemes. We can see that our string starts with an &lt;code&gt;{&lt;/code&gt; indicating its a JSON object, moving on to the next relevant token we see a &lt;code&gt;"key"&lt;/code&gt;, &lt;code&gt;:&lt;/code&gt;, &lt;code&gt;"value"&lt;/code&gt;, and finally the end of the JSON object &lt;code&gt;}&lt;/code&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The tokens get put in the resulting data structure as we identify them. In our case our string becomes a root JSON object in our abstract representation of the JSON. &lt;code&gt;(JSON object)&lt;/code&gt; We create the JSON object as soon as we identify it. If we encounter any malformed token along the way we will panic and the parser will quit, so its save to make assumptions like that the object will be a complete JSON object. Once we see the key we append it in our structure &lt;code&gt;(JSON object (key))&lt;/code&gt; and once we see the value we append it to the key &lt;code&gt;(JSON object (key value))&lt;/code&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You might wonder why we would still need the closing brace, or why we don't just represent it without these symbols if they don't contribute up until this point. Our tokenizer works like a state machine, it switches modes depending on the input it gets called with. The &lt;code&gt;}&lt;/code&gt; means, exit parsing JSON object, where a &lt;code&gt;,&lt;/code&gt; would indicate there to be more key value pairs to follow. &lt;/p&gt;

&lt;p&gt;Once we have the entire string turned to a data structure we are done, because JSON is much simpler than a programming language we do not have to go over the resulting data structure to run any instructions. The program can decide how it will use your resulting JSON data structure. &lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing the tokenizer
&lt;/h2&gt;

&lt;p&gt;the easiest way is to loop trough every character and switch modes depending on the character fed into the parser. You can do this using a switch statement that calls into a the right function for parsing a token. For a string you would see that it starts with &lt;code&gt;"&lt;/code&gt; so any character that is not &lt;code&gt;"&lt;/code&gt; will need to be stored, the latter token indicating that the string has ended and that you should exit the function and return the string to be embedded in the data structure you are creating.&lt;/p&gt;

&lt;h2&gt;
  
  
  understanding how to read the relevant documents for implementing a JSON parser
&lt;/h2&gt;

&lt;p&gt;This excerpt from "how javascript works" is linked on json.org and explains the "McKeeman form", its good to read this trough and use this as a guide when implementing the different modes of the parser as you can see which types include what more clearly than on a syntax diagram:&lt;br&gt;
&lt;a href="https://www.crockford.com/mckeeman.html"&gt;https://www.crockford.com/mckeeman.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have any suggestions or sources that should be linked you can &lt;a href="https://github.com/kaliumxyz/posts/blob/master/JSON.md"&gt;fork this article&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
