<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by CodingPains on Medium]]></title>
        <description><![CDATA[Stories by CodingPains on Medium]]></description>
        <link>https://medium.com/@codingpains?source=rss-2b6e9eee4890------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fAaMe9mpbiyMS_RXwyRdRA.jpeg</url>
            <title>Stories by CodingPains on Medium</title>
            <link>https://medium.com/@codingpains?source=rss-2b6e9eee4890------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 02:02:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codingpains/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why We Should Improve Our QWAN-Foo]]></title>
            <link>https://medium.com/@codingpains/why-we-should-improve-our-qwan-foo-6cc52176f3b2?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cc52176f3b2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Thu, 31 Mar 2016 18:53:02 GMT</pubDate>
            <atom:updated>2016-03-31T18:53:02.533Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*llojxv73m4ZaxB-W14v-kQ.png" /></figure><p>This past Friday March 11th I was sitting at what became one of my favourite talks of the Erlang Factory 2016. It was delivered by <a href="https://en.wikipedia.org/wiki/Bruce_Tate">Bruce Tate</a> and <a href="https://en.wikipedia.org/wiki/Dave_Thomas_(programmer)">Dave Thomas</a>, it basically covered some of their own history along with some ideas about the community of programmers and how we help each other out by contributing with our work.</p><p>When Dave Thomas started delivering the second half of his talk, which you can watch by clicking <a href="https://youtu.be/fklep3sUSWo?t=13m55s">HERE</a>, he showed a picture of Christopher Alexander and this quote.</p><blockquote>There is a central quality which is the root criterion of life and spirit in a man, a town, a building, or a wilderness. This quality is objective and precise, but it cannot be named.</blockquote><blockquote>— Christopher Alexander in The Timeless Way of Building.</blockquote><p>The Quality Without A Name, QWAN for short. He continued on how some languages have QWAN in them, but this is as far as I will go with that idea, because being as I am, always looking for concepts that help me improve as a professional in a behavioural way more than in skills, I got the message in a different way. I got the idea of giving QWAN to my work, ideally in every aspect.</p><p>Let me elaborate.</p><p>Beside these ideas I also got this beautiful message from Dave.</p><blockquote>QWAN is two way, we are inspired in the presence of quality, we behave differently in the presence of quality.</blockquote><blockquote>— Dave Thomas in The Climb, Erlang Factory SF 2016</blockquote><p>That was it! That was when I went “Aha!!!”. It was suddenly so clear for me that the best way to help our teammates be better programmers, is by writing code that has QWAN, because once they find this beautiful, elegant code that you created, they will feel compelled to do the same. When new programmers come in to work on a beautiful code base they will, by all means, keep it beautiful, they will get inspired and keep it that way.</p><p><a href="https://github.com/orlando">Orlando del Aguila,</a> a good friend of mine, recently told me of an experience he had working with ruby code that was originally written by someone at <a href="https://thoughtbot.com/">thoughtbot</a>, he said:</p><blockquote>That code was pristine, like nothing I have ever seen before, it made my job so easy. Either adding new stuff or just changing things a bit, I could get it done in no time.</blockquote><p>That is what I am talking about, code that has QWAN will give this exact result. Here is another example, one that is so much closer to me: Where I work we have a project that has basically two code bases, a part that we call “Legacy Code” that we wrote in a rush and got complex and somewhat ugly, and the new “Core” that was built with extra care and trying to make it as simple, readable and consistent in style as possible.</p><p>What I have noticed is that when any of us add code to the “Core” code base, we always deliver a quality similar to the one already present there and even better, also it is impossible to tell which one of us wrote which line of code without a “git blame” command, because it looks like one person wrote the entire code. On the other hand, when we have to modify or change something in “Legacy” we don’t do the same, we follow what we perceive as the conventions there and not even try to improve it.</p><p>So lets all do ourselves, coworkers and future maintainers of our work a big favor, lets all do our best to put QWAN into our deliverables, all of them: code, documentation, tech designs you name it, whatever it is you need to deliver. It will make everyones work so much easier and in the long run, who knows, it may even reduce costs of production and keep your boss or investors happy but if nothing else, at least do it for your self and your own satisfaction.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cc52176f3b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Wrote a JavaScript In-Memory Streams Library.]]></title>
            <link>https://medium.com/@codingpains/why-i-wrote-an-in-memory-streams-library-d418f06792b6?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/d418f06792b6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Mon, 21 Sep 2015 12:49:58 GMT</pubDate>
            <atom:updated>2015-09-22T11:12:21.699Z</atom:updated>
            <content:encoded><![CDATA[<p>A few weeks ago I wrote a library called <a href="http://github.com/codingpains/oenyi">oenyi</a>. It wraps a small subset of <a href="https://github.com/codingpains/oenyi/wiki/Oenyi%20Technical%20Spec">Image Processing commands</a> and exposes them with a consistent API. It also implements resizing by 3 different methods: fit, cover and contain. I wrote <a href="https://github.com/codingpains/oenyi">oenyi</a> as part of a big refactor we are doing at <a href="http://voxfeed.com/">VoxFeed</a> to make our code base much more readable and maintainable.</p><p>The reason why I wrote <a href="https://github.com/codingpains/oenyi">oenyi</a> was to remove all image processing specific logic from our platform and put it in a library that met the interface we wanted, thus inverting the dependency line and replacing hundreds of lines of code to just about 10.</p><p>This Friday night I made a test coverage analysis on it and realised that I was missing many branches of code including all logic related to “stream behaviour”. So I wrote some tests for the “pipe” method using Node’s native streams in <a href="https://nodejs.org/api/fs.html">File System</a> and fixed a few problems but then I thought:</p><h3>Tests Should Run In Memory</h3><p>When writing automated tests, we have to make sure they run super fast, each case in a few milliseconds; the full suite in a couple of seconds at most. <strong>To achieve this speed is important to keep things small and in memory </strong>but I was using File System.</p><p>I started by looking into existing node libraries for in memory streams, found a few but after looking at their documentation and code I discarded all but <a href="https://www.npmjs.com/package/memory-streams">one</a>, however it didn’t have any tests or badges of anything that would speak for its stability.</p><p>I changed my methods and tests from using file system streams to use <a href="https://www.npmjs.com/package/memory-streams"><em>memory-streams</em></a> but struggled to make it work, in fact I failed. I spent about 4 hours trying before giving up thinking:</p><blockquote>I am using these streams the same way as I would use node’s native streams, why is this not working? Oh, the library must be the problem.</blockquote><h3>I Better Write My Own Library</h3><p>The Prototype goes first. I wrote a very fast implementation of Memory Streams and wrote just 2 tests, exactly for the 2 cases I needed:</p><pre>TAP version 13<br># should read from readable stream<br>ok 1 should be equal<br># should pipe result<br>ok 2 should be equal</pre><pre>1..2<br># tests 2<br># pass 2</pre><p>I did all this in no more than 15 minutes, something had to be wrong with the library I was using before. So I decided to go forward and implement my own in-memory streams package for node.</p><h3>Crispy Stream</h3><p>A few hours later I finished writing <a href="https://github.com/codingpains/crispy-stream">Crispy Stream</a>, an in-memory stream implementation that allows you to do everything that node’s native file system streams allow, and since its compliant with the <a href="https://nodejs.org/api/stream.html#stream_api_for_stream_implementors">api of the abstract interface</a> it works cross implementations or, from crispy to crispy.</p><p><strong>Native Readable to Crispy Writable</strong></p><pre>var crispyStream = require(&#39;crispy-stream&#39;);<br>var fs = require(&#39;fs&#39;);<br>var input = &#39;/path/to/input&#39;;<br>var pipable = fs.createReadStream(input);<br>var writable = crispyStream.createWriteStream();</pre><pre>pipable.pipe(writable);</pre><p><strong>Crispy Readable to Native Writable</strong></p><pre>var crispyStream = require(&#39;crispy-stream&#39;);<br>var fs = require(&#39;fs&#39;);<br>var input = &#39;pipe this&#39;;<br>var filename = &#39;/path/to/output&#39;;<br>var pipable = crispyStream.createReadStream(input);<br>var writable = fs.createWriteStream(filename);</pre><pre>pipable.pipe(writable);</pre><p>After I integrated <a href="https://github.com/codingpains/crispy-stream">crispy-stream</a> in <a href="https://github.com/codingpains/oenyi">oenyi</a>, my tests started to pass with no effort. Great success.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d418f06792b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Dominating AI Spaceship With JavaScript]]></title>
            <link>https://medium.com/@codingpains/creating-a-dominating-ai-spaceship-with-javascript-4cc2223594ce?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cc2223594ce</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[games]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Fri, 28 Aug 2015 02:34:38 GMT</pubDate>
            <atom:updated>2015-08-28T16:42:31.991Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a Dominating AI Spaceship With JavaScript</h3><p>When my friend and colleague <a href="https://github.com/javierbyte">javierbyte</a> told me about his idea of building a video game, in JavaScript using React for the rendering process, where all the players where AI spaceships (also written in JavaScript) by different programmers (the real players), I was instantly hooked and thrilled by the idea, so much that I would bug him about putting the game up every day. When he finally finished it (<a href="http://javierbyte.github.io/clashjs/">demo here</a>) and presented it <a href="https://www.youtube.com/watch?v=mdHvVGtDRrQ">during a talk</a> in the third session of <a href="https://www.gdljs.com/">GdlJS</a>, and announced a challenge for the fourth session I knew I had to be part of it.</p><p>I am a very competitive person, almost everything feels like a competition to me and I always want to win. This was no exception. I was determined to build a dominating spaceship and win the contest, so I forked the <a href="https://github.com/javierbyte/clashjs">repository</a> and started reading the rules and the code of the ships he programmed for the demo. The rules of the game go as follows:</p><ol><li>The game is turn based, when your turn activates means that your move is next, no one can kill you before you run your action once you hit your turn. Your ai function will be executed in this turn and for that you will get your current state, an array with the states of all your living enemies and the state of the map.</li><li>Player states (your state included) tells you if that player has ammunition, where the player is standing in the grid (y, x) and the direction the player is facing. A player will never go out of bounds and the directions are limited to north, east, south and west just like a compass.</li><li>The state of the map includes an array of ammunition positions (y, x) and the grid size as an integer.</li><li>Your ai function must return one of the following actions: “move” one step in your current direction, turn to another direction “north”, “east”, “south”, “west” or “shoot”. You can also choose to stay still, to do so you can return any value different from the ones mentioned above, but I recommend “stay”, “still” or “stop” just to make it explicit and readable.</li><li>Your spaceship must collect ammo because you don’t have any, all players start unarmed, so you have to move towards it and step on it. A new single unit of ammo may spawn at any moment of the game on a different position of the map. (Currently a random position, soon it will spawn at the most neutral position in the grid)</li></ol><h3>The first prototype — aka Old1.</h3><p>The code reading of the existing AI spaceships revealed that a whole set of utils were already coded and that not many spaceships had strategy. Most of them were doing just random moves and a few had some actual intelligence. One ship called “Yuno” was by far the most effective and aggressive, it was the third generation of ai functions produced by Javier and it follows a very simple, yet effective pattern: Get the first ammo in the map and move to kill the closest enemy. This girl would kick my ass for the next three generations of my AI.</p><p>At this point I already had my strategy formulated, but it was very flawed. My first two thoughts where cliché phrases:</p><blockquote>the best defence is good offensive.</blockquote><p>And</p><blockquote>if you have the ball, the opponent can’t score.</blockquote><p>So my first AI had 3 priorities that I turned into directives:</p><ol><li>Do not die.</li><li>Get as much ammo as posible.</li><li>Kill players after enough ammo is acquired. (About 5 units)</li></ol><p>I thought that getting to the ammunition before my enemies would ensure my safety, and I wrote my ai to get there as fast as possible. My theory proved wrong when I realised that I can’t always get there first and trying was getting my ship killed by stupid “Yuno”. I also found that there were some situations in which I was going to be killed before I could react like when an enemy ship was approaching from my back, still unarmed but then some ammunition spawned one or two positions ahead of the enemy so it just grabbed it and killed me. But the most annoying thing was that many decisions I made brought me to my own doom by getting me in front of an armed enemy.</p><p>So I found that there was a bit of a luck factor that was getting me killed, but most of it was my own fault so I moved on to my next idea.</p><h3>The second prototype — Old2</h3><p>I stopped working on the first prototype and tried something different, it was in fact an evolution of the first AI, this one would try to determine if the planned move was safe to execute before committing to it and this was supposed to reduce the amount of deaths.</p><p>It didn’t. It made my AI even dumber. I came to think that the more decisions my ai tried to make the more it was getting them wrong so I figured that I needed a fallback move when all the strategy based moves where unsafe, a directive that would tell what the safest move was. This turned to be the most valuable thing in this second prototype but still flawed.</p><p>I defined the safest move as one that:</p><ul><li>Makes me survive this round.</li><li>Makes me survive next round.</li></ul><p>Surviving the current round was easy if I was not on the crosshairs from the front or the back. The difficult one was finding the move that is safe now and on the next move. To get that I designed a small algorithm that emulated my future position with each move and test if it was safe or not.</p><pre>1. Let directions be an array like [&#39;n&#39;, &#39;e&#39;, &#39;s&#39;, &#39;w&#39;]<br>2. For each direction mock my future position.<br>3. Mocking a position includes moving forward or turning if it was the case (if direction = current direction, move).<br>4. If I can die in this new position, mark as unsafe and go to next direction.<br>5. If new position is safe then return this move.</pre><p>Implementing this code made my second ai a bit stronger, but then I decided to try something very different and reduce the amount of decisions I had to make.</p><h3>The coward and lazy prototype — Old3, now ericku_</h3><p>The newest code in the master branch of the repository has an improved battleship called “ericku_”. This ship is in fact the third evolution of my ai and I pushed it to provide better competition for other programmers working on their own ai functions.</p><p>This prototype does almost everything the last one did, except that it stayes still after getting ammunition instead of chasing. It will just try to safely get ammo, stay still unless it is necessary to move in order to survive and shoot anyone vulnerable. When on attack mode this spaceship just spins looking for someone to destroy, and does that pretty well. Even my 9th ai can’t beat this one when they end up 1v1 and they both have ammo, this produces a stalemate every time. This ai gets a very descent 35% win rate versus older ai ships.</p><h3>The hunter, gatherer. — Old4.</h3><p>For this ai I decided to inherit from the second prototype and wrap my different modes into independent functions that would execute when a mode was active. I turned off the survival mode because it was buggy and getting me killed a lot. So I narrowed it to hunter mode for the times when I had ammo and gatherer mode for the times when I was searching for it.</p><p>The previous methods to evaluate if a position was safe and the safest move available came in handy as I used them in both modes.</p><p>The gatherer mode stayed pretty much the same, but now it was a lot more cautious, it would just stay still, trying to dodge possible attacks instead of rushing towards the closest ammo to get it. Instead, Old4 waits until a unit of ammo spawns in a position that no one else can get before it does, this change alone boosted my win rate to 40%.</p><p>The hunter mode still got active as soon as one unit of ammo was picked up and still hunted the closest enemy as the second prototype did, but I included a new directive called ‘getBackPosition’ and it was meant to catch enemies off-guard by approaching from behind. This change gave me an additional 6% of win rate and a lot more kills than before.</p><h3>6 prototypes and 9 journal pages later, HGE-7 ai is born.</h3><p>I decided to name this ship as HGE-7 because of its behaviour modes hunter, gatherer and elusive and because it is the seventh version of this ai.</p><p>You can see it in the image above as the red ship that just got a sweet double kill. This new ai got a nice 67% win rate which was completely ridiculous so I chose to remove all the weakest ships from my playground and replaced them with my strongest prototypes: Old1, Old2, Old4 and ericku_ (or Old3). This reduced my win rate to a variable 29–33%, still being the best ai around and getting a nice amount of kills. This newest ai has four upgrades:</p><h4>Increased change of safe ammo pickup.</h4><p>If HGE-7 can not get to any ammo faster than the enemies it will look for a safe position in the center of the map, increasing its chances to get future ammunition.</p><h4>Smart hunt</h4><p>When HGE-7 has ammo it hunts the most dangerous enemy instead of just the closest enemy. The most dangerous enemy is the the closest one from the subset of enemies that have ammo.</p><h4>Setup freeze to kill</h4><p>After these two changes where implemented I decided to make one extra change to make it a bit better. HGE-7 catches passing enemies by waiting in place when an enemy is approaching, it turns and shoots just in time to get the kill.</p><h4>Panic when aligned with dangerous enemy.</h4><p>Elusive mode used to activate just when an enemy had my ship in the crosshairs, by then 50% of the time it was too late. Now I activate this elusive mode as soon as HGE-7 gets in the same row or column as an armed enemy and instantly gets out. This change reduced my amount of deaths by a lot and replaced them with more tolerable ties.</p><p>After this changes HGE-7 started getting a variable win rate from 69% to 83% . Insane and absolutely dominating! I was very happy so I made a pull request with my little baby and waited for the contest.</p><h3>The result.</h3><p>After 18 rounds of chasing each other around, my ship lost, disappointing I know but I’ve got to admit that I lost to a better ai and it was a close match. Here is a video of the whole event but it will start playing when the match starts, it was a lot of fun.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FbQvjttETB8A%3Ffeature%3Doembed%26start%3D5319&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbQvjttETB8A%26feature%3Dyoutu.be%26t%3D1h28m39s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FbQvjttETB8A%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1ec8bb0d125270be552821e5a8a40ee/href">https://medium.com/media/e1ec8bb0d125270be552821e5a8a40ee/href</a></iframe><p>A total of 6 battleships were submitted including mine and Javier’s “Yuno” which surprisingly got the second place even when my AI constantly defeated it!</p><p>It was <a href="https://github.com/manuelmhtr">Manuel</a> (the green ship), another friend of mine who took the glory with a smart and simple approach. He gave a lot of weight to the not dying part (chicken!), so much that is practically imposible to kill his ship on a 1v1, I’ve only seen it get killed when a setup is made between 2 or more ships and most of the 1v1 between my ship and his finishes with a stalemate, a few end up with my ship dying, poor thing.</p><p>HGE-7 is still very weak when it has no ammunition and the funny part is that the very same feature that made it strong vs “Yuno” during my test runs was the feature that made me it weak in the real contest because I remain too much time with no ammo and that is when my ship makes the most mistakes. So I tried to make a correction to that by removing some decisions and simplifying the decision tree. The result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UvQb1EyPKpqlMtvHvXeLPw.png" /><figcaption>Result of another round with simplified ai.</figcaption></figure><p>The score is a lot better and the win rate is closer, the end result always depend a lot on what the other 4 ships do, but I still lost.</p><p>Just to finish this story I would like to invite you to make your own AI for the game, the <a href="https://github.com/javierbyte/clashjs">repo</a> is open to the world and I promise you will have a lot of fun.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cc2223594ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How my Journal Solved a 4 Hour Problem in just 5 Minutes.]]></title>
            <link>https://medium.com/@codingpains/how-my-journal-solved-a-4-hour-problem-in-just-5-minutes-b13f439dd540?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/b13f439dd540</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Thu, 23 Jul 2015 19:19:30 GMT</pubDate>
            <atom:updated>2015-07-23T19:19:30.048Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42bof4Mtz5nB3CxbjUpKyQ.jpeg" /></figure><p>Some people say that “<em>a dog is man’s best friend</em>”, well, I say “<em>a journal is a programmer’s best friend</em>”. A few days ago I was working on the setup of the servers that will hold the production environment of the platform that I’ve been working on all this year.</p><p>I finished all the details and the NGINX configuration for the instance that will be our Load Balancer, and then I tried it. Type in the ip of the Load Balancer, hit enter and saw this horrid message.</p><h3>502 Bad Gateway</h3><p>Dang! I was so sure that everything was properly configured, I checked again my config file and that all instances where running. The security groups where ok so it was not a permissions problem, it all just seemed to be a bad joke from NGINX. I then remembered that a few months ago, back in May, when I was working on the prototype I ran into similar problems and that a friend of mine and former co-worker named Adrian helped me with the diagnose.</p><h3>He used nmap to determine if the ports on the app server instances where running.</h3><p>So I installed the tool in the app servers, typed nnap localhost, hit enter. Everything perfect, all the needed ports where open.</p><p>Then I logged into my Load Balancer server and installed the tool. Typed nmap this time with the IP of the app server to check if the port in the app server was visible from the Load Balancer. Of course it wasn’t. The port was completely closed. At this point I remembered that I had the exact same problem all those weeks ago, but I just couldn’t remember how I solved it. What I could remember is that it took me and Adrian a few hours to determine what was causing the problem and solve it, and that I took notes!</p><h3>Luckily I had everything written down in my journal.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o7lVWh15k_qLDRjkMRsSHA.jpeg" /></figure><p>All I had to do was a quick search in the index to find the page ranges where I took those notes. Oh yes, my journal has an index and page numbers.</p><p>I had to read about 2 pages and then I found the winner note on page 120.</p><p>It was the last note in the page.</p><blockquote>3.- He saw all was good internally and pinpointed the bug in server.js listen(port, “127.0.0.1”) ← “0.0.0.0” is the solution.</blockquote><p>This note says that Adrian told me to change the listen address from 127.0.0.1 to 0.0.0.0, that solved my problem and it just took 5 minutes to locate the pages where the solution was and implement the fix.</p><p>My advice: You should keep a journal, it is fun and can save you hours of re-work and re-research.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b13f439dd540" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Abstraction Trilogy. — ADTs]]></title>
            <link>https://medium.com/@codingpains/the-abstraction-trilogy-adts-35008d9402ab?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/35008d9402ab</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Sat, 18 Jul 2015 22:29:19 GMT</pubDate>
            <atom:updated>2015-08-18T01:01:33.148Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*M4AsHjHjcwGga_WOZyCbZQ.jpeg" /><figcaption>This painting is named Blue Poles, painted by Jackson Pollock in 1952. Abstract Expression.</figcaption></figure><blockquote>“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — Martin Fowler in <a href="http://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Technology-ebook/dp/B007WTFWJ6">Refactoring: Improving the Design of Existing Code, 1999</a></blockquote><p>Lately I have been all about abstraction, there are just so many interesting ideas and aspects to it that makes the concept too compelling for me, this lead me to spend a few months reading material on abstraction and applying it in my daily work. I am now convinced that making good abstractions is one of the most important skills that a programmer can develop, yet it is probably one of the hardest to come by.</p><p>Programming is a difficult and complex task, but trust me, <strong>as</strong> <strong>programmers our job is not to solve the hardest problems in the world</strong> <strong>and create the most complex computer programs</strong>. I know sometimes (more like always) we like to brag about how we do exactly that, but our job is in fact the opposite. Our job really consists solving simple and easy problems by breaking the bigger problems into smaller problems so that we can solve this small, simple, easy one instead of the big, complex one. In other words, <strong>our job as programmers is to turn complex into simple</strong>.</p><p>Abstraction is extremely closely related to simplicity, that is why it is so important, I would even go as far as to say that you can make your code 60% simpler just by making good abstractions, a bold statement I know, but it is just an opinion.</p><p>I can see three big ideas around abstraction that I would like to share. The first one, that I will be covering in this article is “<em>Abstract Data Types or ADTs</em>”, I see these guys as the bricks that provide the foundation of our properly abstracted and simple programs. Then I will talk about “<em>layering</em>” that means building a new level of abstraction on top the other. Finally I will be talking about <em>“black boxes”</em>, that is about problem solving by breaking your big problem into smaller ones and ignoring the details of the other boxes.</p><p>For now, lets jump into the first big idea.</p><h4>Abstract Data Types.</h4><p>One of the most interesting things I came across while reading about abstraction is the concept of Abstract Data Types or ADTs for short. An ADT according to Barbara Liskov and Stephen Zilles is defined as:</p><blockquote>A class of abstract objects which is completely characterized by the operations available on those objects. — Barbara Liskov &amp; Stephen Zilles in the paper Programming with Abstract Data Types, 1974.</blockquote><p>We can also see an ADT simply as:</p><blockquote>A set of data that is wrapped and hidden by an object that provides operations in the shape of functions or methods to access the data. — Gustavo Ortiz in… well… here, 2015</blockquote><p>I usually understand better an abstract concept if I can relate it to something real and ordinary. Enter the wrist watch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PHGtw5-S91mZI11NgQPwQ.jpeg" /><figcaption>The machine inside a wrist watch is a good example of data that is hidden and only accessible through specific operations</figcaption></figure><p>In the real world, a wrist watch is an example of an ADT. It has <em>data</em> in the shape of a mechanical engine that keeps track of time and provides <em>read</em> operations through the “hands” and <em>write</em> operations through the “crown”. If in order to tell the current time, we had to take a look into the current state of the gears in the machinery it would be hell to tell the hour, instead we check the position of the hands and see where they are pointing, a simpler task.</p><p>In computing we have more examples of ADTs; a File object is usually an ADT that provides <em>read</em> and <em>write</em> operations, a Semaphore is an ADT with operations <em>wait</em> and <em>signal</em>. Another example is a Hash Table that provides <em>insert</em>, <em>delete</em> and <em>access</em> operations. There are many possible implementations for all these ADTS, for instance a Hash Table could be a simple array, or a linked list, or an array of linked lists, or a binary tree. The one thing that will remain the same through all the different implementations is the data access through its operations <em>insert</em>, <em>delete</em> and <em>access</em>. This is a big piece of advice: <strong>think of your programs in terms of their operations</strong>. By the way I will be referring to functions, methods, classes, modules, libraries, etc. simply as “programs”.</p><p>Those examples in addition to the previous formal and casual definitions give us the key guidelines to use ADTs concepts in our everyday coding and why it helps us in getting maintainable and readable code, these points are:</p><ol><li><strong>We focus on the operations.</strong> This is the most important thing when designing ADTs. By focusing on the operations we can deliver the best API possible for our program or close to it. This will be reflected in good and intuitive operation names that make clear what they do, thus they will not be prone to change and they will not do a lot of things, they will all be operations that do one task and that do it well. That’s the dream isn’t it?</li><li><strong>We hide the data and implementation.</strong> This is the second most important thing. Do not let details of implementation leak to a higher layer. A claim made by Steve McConnell in the book Code Complete says something like “we can say that we are good programmers as the portion of the code we can ignore when working on other portion is maximised”. Now that is exactly what I am talking about, you should not be burdened by the details of implementation of one program when you are using it to build another. Do you really care if that collection of data called <em>usersTable</em> is really a table or an array or a list or a BST or a blah? What if you can just wrap it in an object and give it <em>insert</em>, <em>modify</em>, <em>delete</em> and <em>access </em>operations properly named and change the collection name to <em>users.</em></li></ol><pre><em>// Add user<br>users.insert(newUser);<br>//or<br>users.add(newUser);</em></pre><pre><em>//Remove user<br>users.delete(userId);<br></em>//or<br><em>users.remove(userId);</em></pre><pre><em>//Chain of meaningful methods<br>users.find(userId).setName(“Gus”).save();</em></pre><p>If we do it right we will get, at least, the following benefits.</p><h4><strong>1.- We do changes in just one place.</strong></h4><p>Say you have a program with a big JSON configuration file. This configuration holds the settings for many things like your database connection, and cache and the behaviour of some modules like fees to external services, credentials, etc. Maybe you have your credentials to <a href="http://aws.amazon.com/s3/">S3</a> there and the names for the buckets you use. You can access these buckets settings by calling the complete path, e.g:</p><pre><em>myApp.configuration.storage.s3.buckets.uploads<br>myApp.configuraton.storage.s3.buckets.images</em></pre><p>This would work but if you ever dare to change the structure of your configuration file you will have to change this call in a lot of places. The other option is turn your configuration into an ADT and call:</p><pre><em>config.getBucketName(‘uploads’)<br>config.getBucketName(‘images’)</em></pre><p>Now you can just change the call in the ADT and the rest of the program will remain the same.</p><h4><strong>2.- We can solve problems in the right domain</strong>.</h4><p>By writing an ADT to handle read and write operations to a BST, we no longer have to worry about the details of inserting new nodes inside of a BST we just call the insert operation and its done. By writing an ADT to handle a collection of users we no longer have to worry about how they relate between them or with other collections, we just call the insert operation and it will do that for us.</p><h4><strong>3.- Our program becomes more obviously correct.</strong></h4><p>When we make the right abstractions and design our programs as ADTs it becomes a lot easier to spot bugs when doing a <a href="https://medium.com/@codingpains/the-most-powerful-debugging-tools-in-the-world-part-1-9e4e20a622dc">code reading</a> or step by step debugging, we just have to see if we are invoking the correct operation, if we are, then we go down one level and debug in a new layer of abstraction then and repeat the process. <em>This is why using ADTs concepts and guidelines when writing our code leads to cleaner and simpler code that is easier to read and maintain by you and other people.</em></p><p>My advice is: Think of your classes as ADTs, think of your modules as ADTs, think of everything you are coding as an ADT.</p><p>That is my quick explanation and reasoning around using ADTs as foundation for all your programs, to learn more about them I recommend you read:</p><ol><li><a href="http://dl.acm.org/citation.cfm?id=807045&amp;dl=ACM&amp;coll=DL&amp;CFID=693714066&amp;CFTOKEN=61042520">Programming With Abstract Data Types</a> — Barbara Liskov &amp; Stephen Zilles, 1974.</li><li><a href="http://www.cs.utexas.edu/users/wcook/papers/OOPvsADT/CookOOPvsADT90.pdf">Object Oriented Programming versus Abstract Data Types</a> — William R. Cook, 1990.</li><li><a href="https://www.safaribooksonline.com/library/view/code-complete-second/0735619670/">Code Complete: A Practical Handbook of Software Construction, Second Edition</a> — Steve McConnell, 2004 978–0–7356–1967–8. Chapter 6, pages 125 to 160. If nothing else, just read this one chapter and you will get the most important concepts of ADTs and their use.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35008d9402ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The most powerful debugging tools in the world- Part 3]]></title>
            <link>https://medium.com/@codingpains/the-most-powerful-debugging-tools-in-the-world-part-3-d596176ded82?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/d596176ded82</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Thu, 18 Jun 2015 23:18:30 GMT</pubDate>
            <atom:updated>2015-06-18T23:18:30.332Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xI2ABGyJ5_xhzGyc6pltOA.jpeg" /><figcaption>Illustration depicting François-Marie Arouet, better known as Voltaire</figcaption></figure><blockquote>No problem can withstand the assault of sustained thinking. - Voltaire</blockquote><p><a href="https://medium.com/@codingpains/the-most-powerful-debugging-tools-in-the-world-part-1-9e4e20a622dc">Click here to read Part 1 (Code Reading)</a></p><p><a href="https://medium.com/@codingpains/the-most-powerful-debugging-tools-in-the-world-part-2-967dc01e9960">Click here to read Part 2 (Printing)</a></p><h4>Thinking</h4><p>Every bug is a problem, and as our good friend Voltaire said hundreds of years ago, we can solve any problem with a good amount of thinking.</p><p>Thinking is required at every step of this debugging process, you must be thinking while doing your code readings, while taking notes, while placing your prints and reading their results. This must come naturally to you, you are a programmer, like me, and being thoughtful is (or should be) a core characteristic of us programmers.</p><p>Let´s stop being so philosophical about it and turn this into practical advice.</p><p>Assume your user or a the guy from QA tells about a bug in your program, they also tell you how to reproduce the bug and how critical it is. What do you do next? You put a break point at the beginning of the flow that is reported with a bug? No! I used to do that and it does not work so please don’t</p><p>Instead, ask yourself what could be causing it, imagine the input values and conditions needed for your code to fail like this, reproduce the error and see if it logs something, then think again. You will recognise what is happening very quickly, like if there is a value being changed or deleted before the code is trying to do something else with it or maybe the input of a function is invalid and you will also get your suspects.</p><p>You have an idea now about what is causing the error to show, what triggers it. What you will do next is a <a href="https://medium.com/@codingpains/the-most-powerful-debugging-tools-in-the-world-part-1-9e4e20a622dc"><strong>code reading</strong></a> with this in mind, take your notes and think again, this time you will most likely see the cause of the error, but if you do not, just keep thinking, reading code, taking notes, drawing the flow of the program until you can find it. It really should not take more than one or two passes of the code to figure it out</p><p>If the program is entirely yours, then you should know your code well enough to be able to find a bug just by thinking about the conditions that can make your code behave in the way the bug is making it behave, if is not yours then you have to read the complete code of the program (not the complete project or app of course just the function, process, module, library or whatever it is you are debugging.) to acquaint yourself to it and make drawings and notes of how it works. Then go back to thinking.</p><p>Now, lets quote someone else here because just thinking can make you feel like you are not really making progress, but that is a misconception and totally disagree with this quote in this scenario:</p><blockquote>If you spend too much time thinking about a thing, you’ll never get it done. — Bruce Lee</blockquote><p>This is wrong when talking about programming. If we were talking about our goals and desires in life we could use this quote as a positive idea, like just go for it and do it! But in this case, jumping into adding breakpoints and writing code before thinking about the issue will make you waste more time than you think and you will end up debugging the new bugs produced by the code used to fix the previous bug… ironically. <em>Pro Tip: Keep track of the amount of bugs you have per feature and the amount of bugs you produce when fixing other bugs. When that number starts to decrease it means you are getting better.</em></p><p>And remember de first quote in this series of articles because it is the ground in which all three of them are based.</p><blockquote>The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. — Brian W. Kernighan, in the paper <a href="http://www.mtholyoke.edu/~mcrowley/beginners.pdf">Unix for Beginners (1979) page 12.</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d596176ded82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The most powerful debugging tools in the world - Part 2]]></title>
            <link>https://medium.com/@codingpains/the-most-powerful-debugging-tools-in-the-world-part-2-967dc01e9960?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/967dc01e9960</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Tue, 02 Jun 2015 03:44:58 GMT</pubDate>
            <atom:updated>2015-06-19T15:36:31.595Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*_cEj75SBWH0QJd0ZjLeDKQ.jpeg" /><figcaption>Ken Thompson and Dennis Ritchie (standing) at Bell Labs, 1972</figcaption></figure><blockquote>I just print values. When I’m developing a program I do tremendous amount of printing. And by the time I take out, or comment out the prints it really is pretty solid. I rarely have to go back. — Ken Thompson in the book <a href="http://www.amazon.com/dp/1430219483/ref=cm_sw_r_tw_dp_2gsBvb1XWTAGM">Coders at Work by Peter Seibel</a></blockquote><p><a href="https://medium.com/@codingpains/the-most-powerful-debugging-tools-in-the-world-part-1-9e4e20a622dc">Click here to read Part 1 (Code Reading)</a></p><h4>Printing.</h4><p>You don’t really need a fancy debugger to inspect the values in your variables, you can just do a lot of prints with the values and labels at different points of your code and it will work just as good and faster than the step by step debugger for the most cases.</p><p>For me, the most common places to put a debugging print statement are:</p><ul><li><strong>Right after the setup of your program/function/method</strong>. Just inspect the values of your variables and invariants at the beginning where you consider all the initialisation is done.</li><li><strong>Before and after any value is modified</strong>. Any operation that will modify the value of a variable have to be preceded by a print of the value (how it was before) and followed by another print (how it is after), label each print properly so you know what it means.</li><li><strong>Loops.</strong> Before a loop starts and after it ends I print all variables related to the loop, the variables that control the loop and the variables or objects that are modified during the loop execution. If the problem is harder to find than that, do prints inside of the loop following the previous principle “before and after any value is modified”.</li><li><strong>At the end of the program</strong>. These are basically the returning values or the internal state that got modified, print them and see that everything works.</li></ul><p>Now that your program is full of prints, just feed it with a bunch of different input values for which you can predict the outputs: some values that will safely work, some values that will work in the boundaries and some values that will not work and you know how they should fail beforehand. You can write a script to do all this for you. If you can bombard your program with all kind of valid, invalid and crazy inputs, if it prints the expected values at the right times then you can say is solid and move on. But if something goes wrong then the prints will make it <strong><em>easier for you</em> </strong>and tell you where to look at because you <strong><em>divided your code in sections</em></strong><em> </em>(another take on divide and conquer) and the buggy code is easy to spot. Now you can use that debugging tool if you want.</p><p>This method is very <strong><em>useful to detect and isolate </em></strong><a href="http://en.wikipedia.org/wiki/Race_condition"><strong><em>race conditions</em></strong></a>, these can be very difficult to spot (I always struggle with them, a lot) and they are more prone to occur now that we are coding multithread and asynchronous programs. <strong><em>Using breakpoints to debug race conditions will almost always end up with us declaring our bug a “</em></strong><a href="http://en.wikipedia.org/wiki/Heisenbug"><strong><em>Heisenbug</em></strong></a><strong><em>”</em></strong> which is one that only happens when you are not inspecting, but then you add a debugger and it just won’t happen. If that happens to you, remove the debuggers and print values, you will find the race condition.</p><p>Even when this method is very powerful, <strong><em>there is a more efficient way to use it. That is by thinking</em></strong>. I will talk about that last concept in the next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=967dc01e9960" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The most powerful debugging tools in the world- Part 1]]></title>
            <link>https://medium.com/@codingpains/the-most-powerful-debugging-tools-in-the-world-part-1-9e4e20a622dc?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e4e20a622dc</guid>
            <category><![CDATA[methodology]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Thu, 28 May 2015 16:09:22 GMT</pubDate>
            <atom:updated>2015-06-02T03:58:09.072Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kZY7jC2g2QRH7aE4jx92BQ.png" /><figcaption>A fragment of <a href="https://github.com/azendal/neon">Neon’s</a> code, a DSL to write classes and modules in JavaScript.</figcaption></figure><blockquote>The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. — Brian W. Kernighan, in the paper <a href="http://www.mtholyoke.edu/~mcrowley/beginners.pdf">Unix for Beginners (1979) page 12.</a></blockquote><p>I can almost hear your thoughts right now, a little voice in your head screaming “<a href="http://getfirebug.com/">Firebug</a>!”, “<a href="http://lldb.llvm.org/">LLDB</a>!”, “<a href="http://www.gnu.org/software/gdb/">GDB</a>!” or “<a href="https://github.com/node-inspector/node-inspector">Node inspector</a>!”. If that´s you… well, guess again!</p><p>The best debugging tools are not just free to use but they are not programs in which you just step through code one line at a time while looking at the values of your variables and the stack, that is useful but too slow and when I used that debugging technique I found that it made me lazy and unproductive.</p><p>What I´m talking about in this series of articles are extremely simple and natural <strong>tools </strong><em>(eyes, paper, brain)</em><strong> </strong>that will be used in effective techniques <em>(code reading, printing values and thinking)</em><strong>.</strong> The title of this post is definitely misleading because I will not talk about eyes, notebooks and brains (as in tools), instead I will focus my efforts on the techniques mentioned above by writing one article for each one of them.</p><p>Before starting with the first point in the list, I must make something clear: You don´t need to wait for a bug to reveal itself before you can start tracking and killing them. Yes! debugging starts whenever you decide to do some…</p><h4>Code Reading</h4><blockquote>I think an hour of code reading is worth two weeks of QA. It’s just a really effective way of removing errors. -Douglas Crockford in the book <a href="http://www.amazon.com/dp/1430219483">Coders at Work by Peter Seibel</a>.</blockquote><p>Code reading is proposed by Crockford as a weekly team activity in which one of the members of the team will read out loud the code of a program he or she wrote while its displayed on a big screen or projection for everyone else to see. Yes, it sounds super lame and dull but trust me is nothing like that. I came by that quote while reading the book myself and it was just so compelling and mind-blowing that I had to highlight it, write it down in my journal along with a reflection on it an try it for my self. To be honest, after a few months reading code I don’t think Crockford is exaggerating.</p><p>This practice accomplishes 4 big things:</p><ol><li>Potencial errors and stupidities are called out by the other programmers and many times by your self.</li><li>Better solutions are proposed.</li><li>Junior programmers learn a lot from the experienced programmers.</li><li>Experienced programmers learn from their fellow experienced programmers. Big boys learn too.</li></ol><p>But is not necessary that you do code readings with other people in weekly meetings or code reviews, you can and should read your own code regularly (and other people´s code, GitHub could be your new public library), read some code you wrote last week, last month or at any other point in the past. You will be amazed with the amount of problems you will find, among them you will notice:</p><ol><li><strong>Bugs: </strong>Just by going through your code you will start catching bugs that have not even been found by QA or a user, things like a global variable that should be local, or the variable that is not in the right scope, the wrong assumption of an invariant that might not always be present, the asynchronous call that’s been working fine because the computer where it is running is slow (most of them usually translate in concurrency, damn concurrency!), etc. In other words code that is functional but fragile and hanging from a very thin thread.</li><li><strong>Poorly named variables and methods:</strong> You will see them, notice them and suddenly they become incredibly annoying, like white noise in your head and needles in your eyes every time you come by them in the code. You will know they are there when you read your code and can’t get a good idea of what that variable represents (what the hell is clrfsk, and what did I mean by stck_pdp?) or what the function is doing.</li><li><strong>Clever routines or functions:</strong> If you are reading the weirdest loop you’ve ever written in your life and even when you wrote it you just don’t get what in earth that thing is doing… then it is time to take note of it and write a simple and clear one. Cleverness is the worst enemy of any programmer, stay away from it and listen to Brian W. Kernighan and P. J. Plauger: “<em>If you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” as seen </em><a href="http://www.amazon.com/gp/product/0070342075"><em>The Elements of Programming Style</em></a></li><li><strong>New approaches:</strong> you will start thinking of better ways to solve the problem you solved in the past, some of them will be cleaner, simpler and more reliable, you will notice if you’ve learned since you wrote that last code and how much.</li></ol><p>There are basically two ways to read code, one is from top to bottom, the other one is from bottom to top. You can read code as you want, there is no right or wrong way to do it. Ken Thompson says he likes reading code from bottom to top, but I don’t feel comfortable doing it that way, I rather reading from top to bottom following a diagram, this way I can take notes on the abstraction of the program and see if the problems are solved in the correct domain, then I go to the next layer that should represent a new problem by itself with a new slang and all, and repeat this process until I’m done.</p><p>Code reading is, in my opinion, the most important practice or habit for debugging and learning.</p><h4>The Notebook</h4><p>No! Not the movie!</p><p>When you read code you must take notes or you will not get much out of it. Write a lot about everything you see:</p><ul><li><strong>Write your thoughts on your approach</strong>. Was it good or bad and how bad? Can you make it better? Can you make it simpler? Did you find a bottleneck that will start impacting performance in the future? Will it scale? Is it reliable enough? What happens if suddenly some dependencies of this routine or process suffer a horrible death?</li><li><strong>Did you find a potential bug? </strong>Write where you found the bug and how? How it can be triggered and when you expect it to happen? What are the consequences of it? Why did you miss it when you first wrote the code or why you wrote it at all (take a guess)? Then explain how would you solve it and how would you prevent bugs like that in the future (Remember that Crockford wrote JSLint to prevent his own bugs). <em>Pro tip: A metric, If the amount of bugs you repeat (as in type of bugs) decreases and is less and less every time, it means you are getting better, keep going. If not then change your method or be more disciplined following the current method.</em></li><li><strong>Draw diagrams of how your program works</strong>. You may have diagrams already in your notes from when you first designed the program, however I like drawing them again following the code just to see if I end up with the same diagram, this exercise can tell you a lot about the abstractions you used and the clarity of your code as well as how much you deviate from your original designs. <em>Pro tip: A metric, If you deviate less every time from your designs means that the abstraction is good, design is good and your skill is improving.</em></li><li><strong>Write about code style</strong>. Every ugly line of code must be documented in your notebook, tell yourself that you wrote an ugly line of code and why. Is it because the whitespace and indentation is bad? Is it because you don’t understand what that line does? Is it too clever? Bad naming? <em>Pro tip: A metric, If you are writing less and less ugly lines of code every time, then you are getting better.</em></li></ul><p>The more you write down, the more you learn. My preferred place to do these writings is my journal, I add a date to it and then index the entry at the beginning, this allows me to find the notes easily and revisit them whenever I need them. I also put small notes in the side every time I go and read the entries.</p><h4>Conclusion</h4><p>Code reading is probably the most important habit in your development as a professional, it will help you debug your programs even if the bugs have not been found by users or testers but without discipline is not as useful as it could be. Do it often and with discipline, write down all you find and be hard on yourself, make your results available for you to revisit whenever you need them and measure your own growth.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e4e20a622dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Applying the Scientific Method to Programming.]]></title>
            <link>https://medium.com/@codingpains/applying-the-scientific-method-to-programming-272605e35d20?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/272605e35d20</guid>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Thu, 21 May 2015 05:19:48 GMT</pubDate>
            <atom:updated>2015-05-28T06:17:17.355Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Teaching to unsuspecting youngsters the effective use of formal methods is one of the joys of life because it is so extremely rewarding. -Edsger Dijkstra (<a href="https://www.cs.utexas.edu/~EWD/ewd10xx/EWD1036.PDF">EWD 1036 page 29</a>)</blockquote><p>Every programmer has to follow a problem solving process, this is the only way to prevent getting lost in the way and to consistently get better at your job, it creates a solid path that you can revisit several times and find flaws or get new and better ideas on how to solve things.</p><p>I’ve been following an adaptation of the Scientific Method because its just too powerful, it would be ridiculous not to use it. The scientific method has taken us to space and just about every single scientific discovery ever has been made using it, also it is older than science itself, it all started with Aristotle.</p><p>So how do we apply it? Well first let’s get acquainted with it… shall we?</p><ol><li><strong>Question:</strong> The scientific method always includes a question, this is your starting point, you have a question and you want to discover the answer.<br>- <em>Can sound be transported by a beam of light?</em></li><li><strong>Hypothesis: </strong>After the question was asked, you come up with an idea of the answer.<br>- <em>If I point a laser beam to a mirror that is in front of a sound system that is playing a song, then it will produce vibrations in the reflection of the beam that could be interpreted as sound by a photocell and a noise cleaner.</em></li><li><strong>Independent Variables:</strong> They are the variables that I can change, optimally should be restricted to one.<br><em>- Increase the volume to get more vibrations.</em></li><li><strong>Dependent Variable:</strong> this is the result of an experiment, usually the interpretation of a set of data.<br><em>- Intelligible sound extracted from the light beam, yes or no.</em></li><li><strong>Controlled Variables:</strong> They stay the same through the project, maybe we should call them constants.<br><em>- Mirror size will be M.<br>- Light beam intensity will be L.<br>- Distance between mirror, laser and photocell is the same, D.</em></li><li><strong>Control group: </strong>Subjects that remain untouched.<br>- <em>A light beam reflected from a mirror that has no sound system behind.</em></li><li><strong>Data: </strong>Experimentation throws results, notes and charts could be made from them.<br><em>- 1 dB: No vibration perceived.<br>- 10 dB: Slight vibration perceived, no sound can be extracted from it.<br>- 20–40 dB: Intense vibration, sound can be extracted from it.<br>- +50 dB: Too much, no way to clean up the noise to get clear sound.</em></li><li><strong>Conclusions:</strong> After analysing the data from the experiment you make your conclusions. Was your hypothesis correct or incorrect? Under what scenarios it works, under which ones it doesn’t, what are the upper and lower boundaries, etc.<br>- <em>Given a range of 20dB to 40dB there is some intelligible sound that can be recovered from a beam of light.</em></li><li><strong>Publish results: </strong>Yup, write a paper and share your journals.</li></ol><p>So that’s the scientific method, now how do we apply it in programming?</p><p>Say that we have a very complex program to write, this program solves a big problem that is composed by many smaller problems (This is almost always the case). We then create an abstract blackbox, which usually is a drawing with circles connected by lines and some labels here and there, assuming that each circle has parts we don’t know yet but we think that each solves a smaller problem, then we continue to break every circle into smaller problems until we can solve just one tiny problem at a time.</p><p>Now we have to apply the method to the problem (Yes to each one of them):</p><ol><li>The <strong>problem</strong> turns into the <strong>question</strong>. We have something we want to program but it has a problem that prevents us from doing it.<br><em>- My program must produce C from A and B but the performance is way to low and it consumes all the time available, How can I reduce the run time enough for it to run?</em></li><li>Do <strong>research</strong> on your problem, chances are people already solved it or there are libraries that can help you. Take note of all your findings and your thoughts on them, will they work? why or why not?</li><li>Propose the <strong>hypothesis</strong> on how to solve it.<br><em>- “If I manage to get this data in this X state then that will happen and the program will work”.</em></li><li>We define our <strong>constraints</strong> which are the <strong>controlled variables</strong>, in simpler words the constraints are the requirements of the thing we want to program.<br><em>- The program should get A and B<br>- The program should return C<br>- The program should work in N seconds.<br>- The program should be polite and say hi to everyone.</em></li><li>The different <strong>approaches</strong> we propose become the<strong> independent variable</strong>, using a different algorithm could be considered an independent variable. Which one will solve the problem in the best way possible?<br><em>- Transform data A and B into a structure of shape C by using X algorithm.<br>- Transform data A and B into a structure of shape C by using Y library.</em></li><li><strong>Data</strong>: Prototype all solutions that theoretically work, test them with many different inputs and do a benchmark on them.<br><em>- Did it work?<br>- How did it do in the tests?</em></li><li><strong>Conclusions</strong>: Pick the best, or whatever you want to use that makes you feel confortable.</li><li>Repeat the same<strong> for every problem in your black box</strong>.</li><li><strong>Publish Results</strong>: Write your <strong>technical spec for the big problem</strong>, this spec will contain the solution to every smaller problem in the form of algorithms, it will all be backed up by research and a path that will allow you to support your solution in case of debates about how efficient or good it is, if someone proves you wrong you can always go back, change your hypothesis and add the constraint that made it fail.</li></ol><p>Want an example? Check <a href="https://github.com/gusortiz/keep-local-copy-of-tweets-updated-specification">this one</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=272605e35d20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ideas on code simplicity.]]></title>
            <link>https://medium.com/@codingpains/ideas-on-code-simplicity-86a4ca1ad69c?source=rss-2b6e9eee4890------2</link>
            <guid isPermaLink="false">https://medium.com/p/86a4ca1ad69c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[simplicity]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[CodingPains]]></dc:creator>
            <pubDate>Thu, 09 Apr 2015 15:53:23 GMT</pubDate>
            <atom:updated>2015-05-28T05:51:13.131Z</atom:updated>
            <content:encoded><![CDATA[<p>Back in 2012 our project manager at Freshout gave us a few chapters from different books to read. After the fact we had a series of conversations where we shared what we understood from some chapters and what was meaningful to us.</p><p>These are the notes that I took back then, they made impact back then and now that saw them again, they still are powerful.</p><blockquote>* We are designers/architects.<br>* Take time designing and writing simple code, this saves time and effort in the end.<br>* Our drive must be “TO HELP”. Writing software with the purpose of helping is taking a step forward in producing quality software.<br>* Define a simple purpose for your program.<br>* Thinking the design in the future (extrapolate to the future) keep our helpful programs helpful and maintainable.<br>* Programming is turning complex into simple.<br>* Understanding the problem is the difference between a good programmer and a bad programmer</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86a4ca1ad69c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>