<?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 Sergeon on Medium]]></title>
        <description><![CDATA[Stories by Sergeon on Medium]]></description>
        <link>https://medium.com/@Sergeon?source=rss-2153eebae02b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PYH5Ktt9zRs_S2N_RAahXw.png</url>
            <title>Stories by Sergeon on Medium</title>
            <link>https://medium.com/@Sergeon?source=rss-2153eebae02b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 04:57:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Sergeon/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[Eight critical job interview questions to make as a candidate in the software development industry]]></title>
            <link>https://medium.com/@Sergeon/eight-critical-job-interview-questions-to-make-as-a-candidate-in-the-software-development-industry-4a94e00b068c?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a94e00b068c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[job-interview]]></category>
            <category><![CDATA[job-hunting]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Mon, 05 Oct 2020 11:09:42 GMT</pubDate>
            <atom:updated>2020-10-05T11:09:42.949Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v5JkpSyf6XevV-Xezi5Gbg.jpeg" /><figcaption>A colorful abstract tree</figcaption></figure><p>They say that, from an interviewer perspective, a candidate not making questions is a red flag. However, job interviews are energy draining and tense situations, and it’s only natural for your mind to go blank when it’s your turn to ask questions.</p><p>So here I am jotting down ten questions, so I don’t forget in my next interview! Most of them are specifically tailored for startups or product companies since most of them don’t make sense in consulting (there’s not much point in asking who your teammates will be or what is the branching policy if you can’t know in which project will you be working in three months).</p><p>In general, by asking questions about the company or the job, you have two objectives:</p><ul><li>Cause a good impression so you can get an offer.</li><li>Identify potential red flags, so you can turn down the offer if that’s an option.</li></ul><h4>1. The lifecycle of a new feature</h4><p>What are all the steps that happen between the moment that a new feature is ideated and when it’s shipped to production?</p><p>This question will reveal a lot from the company. You will learn about their engineering practices, how designers work along with developers, how front-end, back-end, QA, and ops developers interact, how they avoid shipping bugs to production, and a lot of other interesting stuff.</p><p>If you just ask them whether they use scrum or another agile framework, the most likely answer is something like:</p><blockquote>yes! We work in two-week sprints, and use Jira to handle our user stories!</blockquote><p>Which is as good as nothing. It is better to ask about the whole development process and avoid discussing what tool they use to handle their issues.</p><h4>1b. Version Control and Branching Policy</h4><p>This should be clear after the previous question. However, the whole lifecycle of a new feature is a complex thing, and they may have abstracted out this point to avoid a super long answer.</p><p>Don’t walk out of the interview without asking this. Don’t assume they use version control or a sane branching policy just because it’s standard in the industry. Some companies, even bigger ones, ditch version control or consider it a problem rather than a solution. I’ve been there, and it was not nice. Be careful with your assumptions: the fact that some engineering practices are standard or super evident to you doesn’t mean that anyone in the world thinks like you.</p><h4>2. Testing and QA</h4><p>Again, maybe the first question already shed light on this. However, if that’s not the case, be sure to bring this issue to the table.</p><p>From my point of view, to prevent bugs from showing up in production is a shared responsibility, and the team should avoid putting that burden on the shoulders of a single developer. Whether they have a nice suite of automated tests, a QA team, some process of manual review of the new features, you need to be absolutely sure that they have some <strong>process</strong> that:</p><ol><li>Ensures quality</li><li>Avoids flamewars</li><li>Is clear and standardized</li></ol><p>Of course, as developers, we should always perform due diligence in our code, so there aren’t bugs! But more eyes see more, and the lack of a proper process to ensure quality is something I consider a red flag. In particular, I don’t buy the idea that good engineering practices can replace a QA team.</p><h4>3. Team Members</h4><p>Always ask who your team members will be and the size of your team. Just from their names, you can learn a bit about the company diversity. You should be willing to work with them, so it would be weird not to ask about your future teammates.</p><h4>4. Documentation</h4><p>It is essential to know how a development team handles the documentation of their projects and processes. In a previous job I had, I remember when the CTO of the company was explaining to me the very first feature I was to implement. I asked them where all the information regarding that issue and other ongoing tasks were written down. I vividly remember how they pointed a finger to their head and said: “here.”</p><p>I wish I had asked about that <strong>before</strong> taking the job.</p><p>On the other hand, in another job I had in a consulting firm, I remember how one of the developers conducting the interview proudly showed me the onboarding documentation they had for new hires. It was clear and well structured. That’s the kind of thing I want to see when I arrive at a new company.</p><h4>5. Tech Stack</h4><p>Maybe you’re a front-end developer, and all you care about your new job is them not using that framework you totally hate. Or you’re that back-end zealot that doesn’t want to ever hear the word ‘JavaScript’ and consider writing CSS a self-degrading experience. But you definitely don’t want your interviewers to notice. So be nice and ask about the technologies the other teams are using.</p><h4>6. Funding</h4><p>This question will often be a bit useless because if the company is struggling financially, no one will tell you. However, sometimes you can learn valuable information by asking this and avoid jumping into a sinking boat.</p><p>A company with no cash flow and depends only on VC’s or the founder’s savings is a dangerous place to be. Maybe it’s not totally a red flag, but it is definitely something you should consider carefully.</p><h4>7. Gear</h4><p>About this, I am maybe a bit inflexible. For me, a company that doesn’t invest thoroughly in its employees’ equipment has many chances to become a failed business. Developers’ salaries are significant, and top-notch equipment is just cheap when comparing it to the cost of the wages. Trying to cut costs on the programmers’ laptops and monitors, or the software they use, is nearly the same as burning money.</p><p>On top of that, if things go wrong and the company starts to lose money, you can just sell the gear for a reasonable fraction of their price. But if you want to get rid of some employees, that will cost you money. It is just better to have seven employees with top equipment rather than eight with shitty laptops. It is cheaper, also.</p><p>I wouldn’t trust an entrepreneur that pretends he is saving money by buying cheap equipment.</p><h4>8. Business model</h4><p>Sometimes the business model of a company and its pricing is super clear and transparent, but that’s not generally the case.</p><p>Asking about this will show your interviewers that you’re not only focused on code and technology, which will probably cause a better impression in general. Also, ambiguous or unclear answers to this are probably a red flag.</p><p>There are other topics you may want to bring on the table in an interview if they are really important to you, such as the vacation policy, the onboarding process, whether they organize workshops for the developers, or what training budget do they have. At the end of the day, the topics that interest you the most are the ones you want to ask about. For me, those eight topics are super important, and I want to have them clear after a job interview.</p><p>I hope you enjoyed this piece! I would be pleased if you clapped or comment!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a94e00b068c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some coding stuff I’m glad I know]]></title>
            <link>https://medium.com/@Sergeon/some-coding-stuff-im-glad-i-know-3457e28712c3?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3457e28712c3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Sat, 12 Sep 2020 10:19:31 GMT</pubDate>
            <atom:updated>2020-09-12T10:19:31.137Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes, I’m coding and I use something and I think: ‘oh, I should write about this’. But usually it is something of little importance so I end up forgetting about it.</p><p>So I decided to make a potpurri of those things, because I really would love if someone taught them to me when I was starting with programming.</p><h3>#1 Enclose console.log parameters in objects</h3><p>If you’re about to:</p><p>&gt; console.log(height, age);</p><p>Or the probably better:</p><p>&gt; console.log(‘height: ’, height,‘age: ’, age);</p><p>Do instead:</p><p>&gt; console.log({height, age});</p><p>So you see an object logged in the console, which in turn will display the variables name and value.</p><h3>#2 Use a clipboard manager</h3><p>A clipboard manager will store in memory all the things you copy to the clipboard, so you don’t need to cmd+c them again. I use <a href="https://github.com/Clipy/Clipy">clipy</a> for Mac OS. For windows there is <a href="https://clipclip.com/">clipclip</a> which I didn’t try but it seems is pretty similar. There’s <a href="https://hluk.github.io/CopyQ/">copyQ</a> that works for windows, linux and osx (yeah I pasted those three links in a row).</p><p>This is not exactly coding related, but believe me, it will make typing in your editor really more enjoyable.</p><h3>#3 Consider using a single tab in your editor</h3><p>In my case, I work with vscode, but other editors have the same feature. In the case of vscode, by turning the setting <strong>show tabs </strong>to false, you will have only one tab in your editor. Whenever you open a new file, the single tab stops displaying the previous one and shows the new one.</p><p>This may seem uncomfortable when someone present this to you for the first time, but I find this really better than having a lot of tabs. When you have a lot of tabs in your editor:</p><ul><li>You constantly feel the pressure to remove some tabs, because there’s always too many of them.</li><li>You struggle a lot to remember the position of the tabs already open, and, if you’re like me, you use to fail a lot trying to open an old tab.</li></ul><p>However, working with only one tab forces you to hit cmd+P (the file search widget) to display the files whenever you need to locate another tab you were working with. And that’s great because it presents information in a way that is more easier to consume:</p><ul><li>you get to see the full path of your previously opened files, without the tab size messing with it.</li><li>The last n files opened will display chronologically.</li><li>If you don’t find the tab there, you just search for it in the search widget, which already has the focus, and believe me that’s actually <strong>way faster </strong>than juggling over your 12 opened 1cm tabs.</li></ul><h3>#4 Get used to work with multiple selection</h3><p>In most modern editors you can work with multiple selection and cursors, meaning you can write, copy and paste over multiple lines or positions in the same line at the same time.</p><p>It is easier to see it than read it so I leave this video which explain how this works in vscode: <a href="https://www.youtube.com/watch?v=Zgf2vXl5Gkk">https://www.youtube.com/watch?v=Zgf2vXl5Gkk</a></p><h3>#5 Learning Resources</h3><p>There are two learning resources that really impressed me lately.</p><p>One is the <a href="https://scrimba.com/">Scrimba platform</a>. It basically consists in a video lesson plus an interactive coding editor. You can modify the code from the lessons in real time and it works like a breeze. I took one of the -I think- very first Scrimba lessons, about CSS grid layout, and it really impressed.</p><p>I believe this platform is not as known as <a href="http://frontendmasters.com/">frontendmasters</a>, <a href="https://www.pluralsight.com/">pluralsight</a>, <a href="https://www.coursera.org/">coursera</a> etc., while the contents are arguably that good. If you’re learning front-end development, you should definitely give it a try.</p><p>The other one is the youtube channel <a href="https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw">the coding train</a>. The person behind the coding train is <a href="https://shiffman.net/">Dan Shiffman</a>, who mainly posts live-coding videos about generative art, data visualization and simulations. Most of the content is focused on javaScript.</p><p>I am really impressed by Dan’s videos and I think they are a really good resource to start learning javaScript, and coding in general. He explains things clearly, the videos have a really good rhythm and he is actually kinda fun.</p><p>(Well, actually there’s a catch: Dan doesn’t use multiple selection and that makes me nervous when I see him pasting something into several lines 😂 ).</p><p>—</p><p>And that’s a wrap. I plan to make more articles like this in the future. I hope you liked it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3457e28712c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some Vue tips for beginners]]></title>
            <link>https://medium.com/@Sergeon/some-vue-tips-for-beginners-e4ef4a904032?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4ef4a904032</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Mon, 28 Oct 2019 09:47:25 GMT</pubDate>
            <atom:updated>2019-10-28T09:47:25.650Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been using Vue since 2017 non-stop. Vue is probably one of the frameworks out there with best documentation and more easy to use for beginners, but it still have some minor pain points that is good to be aware of:</p><h3>Read the docs</h3><p>Vue docs are sweet. Don’t be afraid, just go read them. Vue has one of the best documentation site ever, if you’re gonna work with Vue, pay a visit and read carefully.</p><h3>Understand reactivity</h3><p>Vue reactivity is so sweet and feels like magic if you come from a jQuery-like way of handling user interfaces, but it have some caveats.</p><p>In the docs there is <a href="https://vuejs.org/v2/guide/reactivity.html">this dedicated page about reactivity in-depth</a>, you should read ir carefully because, as a beginner, you will make a lot of errors related to how Vue track values down. There is <a href="https://vuejs.org/2016/02/06/common-gotchas/">this other page about common beginner gotchas</a> that is heavily related. Read them carefully. The main points are, succinctly, the following:</p><ul><li>You need to initialize component variables within data for them to be reactive.</li><li>If your data variable is an object, you need to initialize every child to track its changes.</li><li>Vue cannot track array modifications by index. use Vue.set or reassign to a new array.</li></ul><h3>Understand v-model</h3><p>The v-model directive allows to setup a ‘two way data binding` between a form-control and a component variable.</p><p>Only, it is not two way data binding, and it has nothing to do with form controls by themselves.</p><p>The v-model directive works with any component or html tag that takes a value prop and emits an input event. Native html form-controls like &lt;input&gt; or &lt;select&gt; happen to do this.</p><p>On the other hand, putting v-model in a component like v-model=&quot;name&quot; is like doing: &lt;input :value=&quot;name&quot; @input=&quot;name = $event.target.value&quot; /&gt; . It is not strict two-way data binding, but writing the variable as the component receives the @input event.</p><p><a href="https://alligator.io/author/joshua-bemenderfer">Joshua Bemenderfer</a> explains this very well <a href="https://alligator.io/vuejs/add-v-model-support/">in this article</a>. If your new to Vue, I strongly suggest you to create a custom component that supports v-model as an exercise, it will really pay off.</p><h3>Use computed properties!</h3><p>Vue has a featured called computed properties that allow you to define reactive properties of your components. <a href="https://vuejs.org/v2/guide/computed.html">The docs explain it better than I would</a>. The idea is to define a single property that reacts to any other value of your component. If for instance you should render a label when your component has a disabled prop, doesn’t have a user prop and its members value is empty, you could setup a single computed property for this:</p><p>computed: {</p><p>renderTheLabel() {return !!this.disabled &amp;&amp; ! this.user &amp;&amp; members.length === 0}</p><p>}</p><p>And then use it easily in your template:</p><p>&lt;label v-if=&quot;renderTheLabel&quot;&gt; . . . &lt;/label&gt;</p><p>Computed properties are cached, and Vue will only reevaluate them when one of this dependencies change.</p><p>Key points of computed properties:</p><ul><li>They are way more performant than methods , since they cache dependencies.</li><li>They make your template and syntax more clear.</li><li>They help you a lot to reveal intent. A method can do anything, but a computed property only return values based on component properties and data, so they make the code easier to read.</li></ul><p>— — —</p><p>And that’s a wrap! Of course, there are a ton of things you can do with Vue and some of them are complex -like using vuex-, but I think reactivity and v-model are the bigger paint points for people starting using Vue for scratch. Also, I see how a lot of people that post questions on SO or ask me about Vue usually overlook computed properties.</p><p>I hope this help you to some degrees if you’re learning to use Vue. If so, don’t forget to clap it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4ef4a904032" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy and nice git tricks]]></title>
            <link>https://medium.com/@Sergeon/easy-and-nice-git-tricks-f61bdfe119e8?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f61bdfe119e8</guid>
            <category><![CDATA[version-control-system]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[version-control]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Sun, 26 May 2019 12:50:48 GMT</pubDate>
            <atom:updated>2019-05-26T12:50:48.994Z</atom:updated>
            <content:encoded><![CDATA[<p>Here I post some of my favorite git commands and tricks that I use almost daily. I believe most of them are well known, but if you happen to not know to any of those, they are really cool.</p><h4>Create a new branch and checkout in one-liner</h4><p>git checkout -b my-new-branch-name</p><p>It is somehow strange that one have to use git checkout instead of git branch to do so. Instead to create a new branch with git branch and then checkout to it, use -b to create and checkout to a new branch on the fly.</p><h4>gitk</h4><p>There is this little program that ships with git called <strong>gitk</strong>. You just type gitk in your terminal when in a git project folder, and you will see a gruesome, sad, sober UI that depicts git branches that <strong>JUST WORKS</strong>. I like gitk a lot and I don’t think sourcetree, tortoise or any other GUI applications for git present branch histories in a better way.</p><h4>git log parameters</h4><p>hands down, git log is the second git command I use the most I think, only beat by git status. it presents the history of past commits in the current branch.</p><p>The git log command accept some parameters:</p><p>git log --oneline will format all the commits on just one line. This is really nice and usually you will prefer this than the longer format.</p><p>git log -n (n being a number) will display that exact number of commits. I do this a lot. I don’t know why. Maybe is not that useful after all, but I like to keep the number small since I usually only check the last two or three commits.</p><h4>git checkout .</h4><p>This will clean the current changes that are not added to the index with git add . Easy, fast and dangerous like an sql delete without a where .</p><h4>Cherry pick</h4><p>Cherry pick is one of the coolest weapons you have when you mess up things and start adding commits to the wrong branch. In a nutshell, cherry picks merge changes from a <strong>single commit </strong>to your branch, instead of from another branch with git merge. <a href="https://stackoverflow.com/a/9339460/4166367">This SO answer </a>is a great explanation about cherry pick.</p><p>The main point of git cherry-pick is that it applies the single changes from a commit to your current branch. So let’s say your working on branch implement-social-login . Then you checkout to fix-a11y-issues to check something. You add a commit correctly, and push. Then you forgot to checkout to the previous branch, and add another commit with social login code.</p><p>Now you can’t just checkout to the social login branch and git merge fix-a11y-issues , because you will get the commit you added about a11y that has nothing to do with your branch.</p><p>So you go to the a11y branch, and do git log -1 --oneline, then copy the commit hash, let’s say is “b504ca5”. Now you checkout to the social login branch and do:</p><p>git cherry-pick b504ca5</p><p>And boom: now your branch gets that commit, only that commit, with the same message and author. Copy/paste at is finest.</p><p>(Of course , you also need to reset the a11y branch to the proper commit to get rid of the extra one).</p><h4>git add -p</h4><p>As you may already now, git add --all add all the changes you’re already done to the index. My typical workflow is:</p><ol><li>Make changes</li><li>git add — all</li><li>git commit -m …</li></ol><p>This is the easiest way to commit new files. If you’re only modifying already existing files, git commit -am is even faster.</p><p>Now, fast is not always good. Using the -p parameter will ask you to add or ignore changed code <strong>chunk by chunk</strong>. This is super useful, and when you mess with a lot of files throwing a lot of logs and debuggers, you really want to use git add -p to be sure you’re not adding something wrong to your commit.</p><h4>Pro git book</h4><p>You now, there is this book about git that is <a href="https://git-scm.com/book/en/v2">completely published online</a> for free, authored by <a href="http://scottchacon.com/about.html">Scott Chacon</a> and <a href="https://ben.straub.cc/about">Ben Straub</a>, which is, in my opinion, far better than the official git documentation. When I need to refresh or learn some git concept, I always go there by default.</p><p>And that’s all. This is the damn first entry I write in 2019 so I really hope you people like it! If you learn something new, or already knew everything but still love the gitk gui, consider clapping!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f61bdfe119e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using javaScript in your git hooks]]></title>
            <link>https://medium.com/@Sergeon/using-javascript-in-your-git-hooks-f0ce09477334?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0ce09477334</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Mon, 07 May 2018 10:01:01 GMT</pubDate>
            <atom:updated>2018-05-07T10:01:01.473Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://git-scm.com/book/uz/v2/Customizing-Git-Git-Hooks">Git hooks really come in handy</a> to automatically perform a lot of repetitive tasks when working with git, and also can be used to ensure that some requirements are met before you can commit or push in a client repository, or before a remote repository can accept new commits. For instance, is really common to execute git hooks to check wether a test suite ran successfully, and with a certain coverage threshold.</p><p>Now, to do so, you just need to edit your hook scripts, which lie within the .git/hooks/ directory in any git repo. Such scripts are run before or after certain events, and git will use their output to make some changes (i.e., append a signature automatically to every commit message) or to prevent things for happening (for instance, prevent you to make a push if the linter output has errors or warnings).</p><p>By default, in any git repository, this folder is populated with a lot of sample hook scripts, that have names like pre-push.sample. If you inspect such sample files, you will see that they are just shell scripts that usually exit with 1 or 0 based on conditions. Sometimes, they print something to get the job done: for instance, in the prepare-commit-msg hook you need to print to stdout in order to indicate the desired commit message.</p><p>Exit with an 1 code will prevent the related action for happening: if you exit with 1 from the pre-commit hook, the commit will be rejected. On the other hand, 0 means that everything is ok. <a href="https://askubuntu.com/questions/892604/meaning-of-exit-0-exit-1-and-exit-2-in-a-bash-script">This is the standard in the shell scripts world</a>.</p><p>As you would see if you inspected the default hooks, they are all written in bash. And one of the best sources of documentation for git, <a href="https://git-scm.com/book/es/v2">the pro git book</a>, uses <a href="https://git-scm.com/book/uz/v2/Customizing-Git-An-Example-Git-Enforced-Policy">ruby as the scripting language for its examples</a>.</p><h3>Using javaScript</h3><p>Now, you can use any scripting language for your shell scripts or git hooks, would it be python, php, javaScript or any other, you just need to know some little things and adhere to certain criteria.</p><p>(<a href="http://2ality.com/2011/12/nodejs-shell-scripting.html">this article really will help you</a> a lot if you never used javaScript as a cli language).</p><p>In order to use javaScript code to be run in the shell, <a href="https://nodejs.org/en/">we will use node.js</a>. In any shell script, to tell your OS that the script is intended to be run by node, you just need to add this line to the first line of the script:</p><p>#!/usr/bin/env node</p><p>Now, if you put this in any file, toss some javaScript at it, and execute it, you should see the output in your terminal. For instance, let’s say we create this file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a684c0b24af05a7b578ec1e5e950666d/href">https://medium.com/media/a684c0b24af05a7b578ec1e5e950666d/href</a></iframe><p>Then we make it executable:</p><p>sudo chmod 774 ./test.js</p><p>Now, if we just run the file:</p><p>./test.js</p><p>We will see the ‘Hello World’ output in terminal.</p><p>Now notice how this is different from executing test.js with node. The command:</p><p>node ./test.js</p><p>would have the same output. However, by appending the <em>#!/usr/bin/env node </em>to the first line, we’re telling the OS that it should use node to execute the file by default: there is no need to invoke node explicitly. This is important in the git hook context because git hooks are just executed as a shell script: the OS will use node to do so <strong>only</strong> if we explicitly mark the file to be executed by node.</p><h3>Stdout and exit codes</h3><p>As we just see, <strong>console.log</strong> just writes to the <strong>standard output</strong>, so it works like print in a bash script. Should we need to output some specific message in a git hook, we just can use the old good console.log to get the job done.</p><p>Now, how to exit in a node script? Well, if you never done cli node.js before, you may think that return will do the trick. However, that won’t work. In order to send an exit code from a node shell script, <a href="https://nodejs.org/api/process.html">we must use the process module</a>. The process.exit() method will just work like a bash exit statement.</p><p>So, for our use case, we will just process.exit(1) whenever we want to abort some git event, or process.exit(0) when things are OK.</p><h3>Checking commit messages</h3><p>Let’s say we want to check if a commit message adheres to a certain structure. For instance, in my job, <a href="https://es.atlassian.com/software/jira">we use Jira</a> to manage our issues, and Jira issue tickets have an id like: PN-123, where PN are just the initials of the project name. So, when we create a branch or add a commit to a repository, they should reference a Jira issue: branches usually reference user stories or bugs, and commits usually reference tasks or subtasks.</p><p>So, we prepend the special <em>feature/</em> or <em>hotfix/</em> string and an user story ID in every branch we create, like:</p><p>feature/PN-301-allow-user-logout</p><p>And a plain ID in every commit:</p><p>PN-440-added-generic-error-notifications-styles</p><p>With most repository managers, like github, gitlab or bitbucket, is easy to enforce such policies just from the repository manager UI. So, for instance, we got our remote repositories to reject commits that don’t adhere to this naming policy.</p><p>Now, the problem is that this doesn’t prevent developers to mistakenly create wrong branch names or commit messages in their local repositories. And when they will push their work, it will be rejected, and they will be forced to rewrite history and do some git nasty tricks to fix those mistakes.</p><p>So, one good thing we could do in such a scenario is to setup a git hook to prevent bad commit messages to be committed directly in our local repository: now, whenever we make such a mistake, we can fix it at the right time.</p><p>When we want to check the commit message, the right hook is the commit-msg hook. We should add a <em>commit-msg</em> file to the hooks directory. In the hook, we will perform the following tasks:</p><ul><li>Check wether the branch name is correct. If not, we will print an useful error message end exit with 1.</li><li>Check wether the commit message is correct. If not, we will print an useful error message and exit with 1.</li><li>If everything is ok, we exit with 0.</li></ul><p>To check the branch name in every commit is a bit redundant, but as far as I know there is not a dedicated hook that runs when a new branch is created. Checking both the branch name and the commit message will ensure that the problem will be noticed whenever we try to add the first commit to a bad named branch, allowing us to rename the branch easily before any commit is added to it.</p><p>Now, in order to do so, we need two things in our script: the <strong>commit message</strong> and the <strong>branch name</strong>. The commit message will be provided to the hook as a parameter, while in order to get the branch name we will need to execute a git branch command inside our node.js script.</p><h3>Gathering parameters</h3><p>Parameters passed to a node shell script can be accessed from the special process.argv array. The process module is a special node object hat is accesible from every node file or module, just like the module object.</p><p>In every node script, the first two parameters will be the javaScript interpreter -node- and the script filename. So, parameters provided to our script will be found in process.argv[2] and more. There are dedicated node packages to handle with command line arguments, like <a href="https://github.com/substack/minimist">minimist</a>, but is not like we want to add a node_modules to our hooks folder. We are just grabbing one single argument, so just:</p><p>process.argv[2]</p><p>will do the trick.</p><p>Now, I said that the commit message will be passed as an argument.That’s, well, not exactly true, because if we log process.argv[2], we will see this:</p><p><em>.git/COMMIT_EDITMSG</em></p><p>Which is actually a filename, which in turn contains the commit message -this time is true-. So, in order to get the commit message, we need to read the file, like in the following snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72f29c7f02f60225cb9bcad531dc314d/href">https://medium.com/media/72f29c7f02f60225cb9bcad531dc314d/href</a></iframe><p>(notice how we are requiring the <em>fs</em> module. Native node modules like fs,path or util are always available in node shell scripts).</p><p>You may read before that you must <strong>never</strong> use synchronous api’s in node, like readFileSync(). Well, that’s true for code being ran in a web server, but in a shell script is absolutely safe to use synchronous api’s to grab things from the filesystem.</p><p>That snippet ahead just reads the filename at process.argv[2], that contains the commit message. Passing an encoding as the second parameter is mandatory to get a string instead of a buffer. The trim() call just prevents extra spaces or carriage returns characters to get into our commit message.</p><h3>Getting the current branch</h3><p>Sadly, the git branch is not passed to the hook as a parameter, so we will need to grab it from the OS. We can execute any command from a node script using the child_process module. child_process exports an object which provides two methods to handle with OS external processes: exec and spawn. Both are asynchronous, and spawn on top of that will return a stream, while exec will return a buffer or a string. When dealing with commands that output large amount of data spawn is the way to go, but to capture the output of a git branch call, exec will suffice, and it’s easier to use.</p><p>Just like in the official exec documentation, we will use the util module to promisify the exec call. A way to get the git branch output in a node script will be like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20e8d1dd759a5e41e99b3a992595c789/href">https://medium.com/media/20e8d1dd759a5e41e99b3a992595c789/href</a></iframe><p>The exec callback, apart from the error first parameter, has two parameters: stdout and stderr. The command output will, if all works as expected, be passed in the stdout parameter, which means that, when we promisify and await for the exec call, we need to check the stdout field.</p><p>The previous script will print a text like the following:</p><p><em>* feature/HP-100-new-feature</em></p><p><em>master</em></p><p><em>feature/HP-101-another-branch</em></p><p>Just a list of lines with the branch names, and the current branch marked with an asterisk. Now, to get the current branch, we need to select the one with an asterisks. Let’s say we captured the output in a branches variable, the next statement will return the currently selected branch:</p><p>const current = branches.split(&#39;\n&#39;).find(b =&gt; b.charAt(0) === &#39;*&#39;)</p><p>.trim().substring(2);</p><p>This just splits the lines into an array of lines, one per each branch, then finds the one that starts with the asterisk. The substring() call at the end just gets rid of the asterisk in the name, while the extra trim() prevents any undesired space or special char to slip into our current branch name variable.</p><h3>Enforcing the naming policy</h3><p>Now we know how to get the commit message and the branch name, so we just need to check if both of them comply with our naming policy. There are a lot of ways to do this: you can either start searching for specific substrings at the start of the messages, or use regular expression. For this particular case I prefer the latter. The following regular expressions will express the naming policies for the branch names and the commit messages:</p><p><em>const BRANCH_CONTRACT = /^(feature|hotfix)\/AP-[0–9]{1,6}-/;</em></p><p><em>const CODE_CONTRACT = /AP-[0–9]{1,6}-/;</em></p><p>In order to check if a string match a regex, we can just use the regex test() method:</p><p>BRANCH_CONTRACT.test(&#39;bad-branch-name&#39;); //false</p><p>CODE_CONTRACT.test(&#39;AP-501-added-favicon.ico&#39;); //true</p><h3>Creating the Hook</h3><p>We now know all we needed to create a node shell script as our commit-msg git hook. The following snippet is a valid git hook that will ensure that our commit messages and branch names follow our naming policy:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e798bb7178a5434c5b8da19d5e6a80a/href">https://medium.com/media/4e798bb7178a5434c5b8da19d5e6a80a/href</a></iframe><h3>Caveats</h3><p>If you use Source Tree -or, I guess, any git GUI, at least on MacOs, which is my current environment-, and add this hook to your project, you will see how Source Tree starts <strong>complaining about not finding node</strong>.</p><p>Following <a href="https://stackoverflow.com/questions/17538460/using-git-pre-commit-hooks-in-context-of-github-client/33588294#33588294">this SO thread</a>, there is a way to fix this, just by calling source tree from the command line (like <em>open /Applications/SourceTree.app/Contents/MacOS/SourceTree</em>). It’s pretty awkward, but it works.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0ce09477334" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Asynchronous Testing Gotchas]]></title>
            <link>https://medium.com/cloudboost/javascript-asynchronous-testing-gotchas-ac7e5c39257?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac7e5c39257</guid>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[asynchronous]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Tue, 02 Jan 2018 08:41:16 GMT</pubDate>
            <atom:updated>2018-08-30T13:15:05.985Z</atom:updated>
            <content:encoded><![CDATA[<p>Asynchronous coding is hard to get right, and when it comes to test asynchronous code, is pretty easy to mess things up if you’re not careful or don’t understand well the difference between synchronous and asynchronous code.</p><p>Either using mocha in the back-end with node.js or jasmine in the front-end with karma, if you never did asynchronous testing before you will get a lot of problems getting things right.</p><p>The main problem with asynchronous testing is that, when you don’t set up it correctly, <strong>specs just end before its assertions get run.</strong></p><p>This usually lead to <strong>false positives. </strong>It is really easy to get false positives when testing with mocha or jasmine, since they, by default, <strong>flag a test as passed when they find no expectation in it.</strong></p><p>In the other hand, this may -or not- lead to a <strong>false negative</strong> in another test, or to strange exceptions that <em>seems</em> to be senseless.</p><p>Not only is really easy to mess your specs up when dealing with async code; on top of that, you will get non-deterministic outputs: sometimes the suite pass, sometimes no. And when it fails, the failing test may not be the same between each run. Usually a test suite pass locally but fails in your CI server.</p><p>When you have such symptoms, you surely has a spec -or several- that is handling its asynchrony wrong.</p><h3>The problem</h3><p>The core of the issue is that the test suite is terminating specs before its asynchronous code runs.</p><p>Just like this node.js snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3660b1642075123796b411968882ac2d/href">https://medium.com/media/3660b1642075123796b411968882ac2d/href</a></iframe><p>will never log anything, code like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f25304481795cd88b989ea04bf1285e4/href">https://medium.com/media/f25304481795cd88b989ea04bf1285e4/href</a></iframe><p>won’t run the expect(true).to.be.false; line before the end of the test.</p><p>On top of that, in most javascript test suites, <strong>specs with no expectations within just pass.</strong> This snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a67c0fcb2b99b81ee6279f37ce6ad8d1/href">https://medium.com/media/a67c0fcb2b99b81ee6279f37ce6ad8d1/href</a></iframe><p>Will generate this output in mocha:</p><pre>the silliest test suite ever<br>    ✓ a spec with no expectation will always pass</pre><pre>1 passing (5ms)</pre><p>This default behavior maybe is not bad by itself: you can put code in a spec, and, if it doesn’t throw an Error, it somehow means that everything is ok, so the test passes.</p><p>However, this default behavior may lead to serious issues when you’re dealing with assertions inside asynchronous callbacks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f25304481795cd88b989ea04bf1285e4/href">https://medium.com/media/f25304481795cd88b989ea04bf1285e4/href</a></iframe><p>This test, which should apparently just fail, actually passes. This is the output:</p><pre>a false positive<br>    ✓ an expect inside asynchronous code will be ignored</pre><pre>1 passing (8ms)</pre><p>Since the expectation lays within a 1 mssetTimeout, it won’t run until the next tick: when the spec finishes, there is <em>still</em> no expectation code, so the test just passes, since that is the default for specs with no expectations within.</p><h3>the solution</h3><p>To deal with this problem is really easy: both in mocha and jasmine, you can just pass an extra parameter to the it spec -usually called done-.</p><p>This flags the spec as asynchronous, and the test engine will wait to that parameter -which is a function- to be called before flagging the test as passed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9af4a5a85fd609f4f6a1c25d3a915baf/href">https://medium.com/media/9af4a5a85fd609f4f6a1c25d3a915baf/href</a></iframe><p>This test fails as expected.</p><p>Also, in mocha you can also <strong>return a promise </strong>in your spec in order to get the test engine to wait until it resolves before finishing the spec:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f035077fd07ffb5731ed12082e2d7ad1/href">https://medium.com/media/f035077fd07ffb5731ed12082e2d7ad1/href</a></iframe><p>Mocha will make that test to fail, as expected.</p><h3>The gotchas</h3><p>So far, this story is not the most interesting: a bit of googling will tell you how to perform asynchronous testing in javascript: you just need to ensure your expectations get run before the spec end usually calling <strong>done</strong>. Easy peasy.</p><p>However, this is the tip of the iceberg. Such a silly issue, with such a straight, simple solution, can lead to severe problems in a test suite, because when you <strong>forgot to call this done parameter properly</strong>, the suite run becomes non-deterministic and <strong>really hellish to debug</strong>.</p><p>Let’s imagine we have a suite like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47bdf1c2a9388ea7599024b5e521e3f5/href">https://medium.com/media/47bdf1c2a9388ea7599024b5e521e3f5/href</a></iframe><p>Now, the first spec, get() is obviously wrong. However, the suite will give a result like this:</p><p>ACME.com<br> ✓ get()<br> ✓ getLolz() (104ms)<br> ✓ getFruit() (102ms)</p><p>3 passing (216ms)</p><p>When that’s wrong. If you’re lucky enough, and you’re dealing with a suite that waits for every callback in the stack to run, you will receive a warning of the first expectation failing when it fails(mocha current version would do that, i.e.). If you’re not, your tests will happily pass. If you’re running a jasmine suite inside karma, this may depend upon your karma configuration.</p><p>Well, let’s imagine those are the specs of your codebase. Everything seems to be working fine since all the tests pass. Now, we add a new function getPlayer() and we test it too:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79da731b257540abb44fab2e91171812/href">https://medium.com/media/79da731b257540abb44fab2e91171812/href</a></iframe><p>Now, depending on the testing library we are using and its version , we’ll get a weird error message of some type. For example is easy to get something like:</p><p>✓ get()<br> ✓ getLolz() (112ms)<br> ✓ getFruit() (102ms)<br>1) getPlayer()</p><p>And some error regarding ‘ACME’ not being equal to ‘a wrong value ’. Maybe you’ll get all the tests passing, with an uncaught exception warning regarding the first assertion.</p><p>Here, despite the error message of the exception, it would seem that the new test is broken. In our contrived example, is pretty easy to spot that it is not, but in real tests, this will not be so obvious. Specially, when testing booleans, we just get an <strong>expected true to be false </strong>message, with no proper context of the spec that is failing. We will lose a lot of time isolating getPlayer() only to see that it actually passes when run in isolation.</p><p>What is happening, is that the expectation of the first test -which lies within a callback- <strong>happens to run during the fourth test execution</strong>: making us believe the fourth test is broken.</p><p>Here, some strange things start to happen:</p><p>1- If we remove the fourth test, the suite pass.</p><p>2- If we remove the first, the suite pass.</p><p>3- If we add any spec between the first and the fourth, that takes more than 800 ms to run, that test will fail.</p><p>Also, with different timing values, removing tests between the broken test and the one that seems to fail can make the suite to pass.</p><p>As is easy to spot, in such scenario, <strong>just to start running tests in isolation to check which is broken is not the way to go</strong>. You will start getting a lot of inconsistent results. If you just comment specs out in order to make a build, it can happen that the suite breaks when run inside the CI server, since you’re depending upon asynchronous stuff that don’t take always the same time to finish.</p><p>(</p><p>just if you don’t know, testing libraries usually have easy ways to ignore tests, or run some tests in isolation:</p><ul><li>mocha and jest have it.only() and describe.only() to ensure that a spec or a describe block gets run in isolation.</li><li>Jasmine has fit() and fdescribe() (the ‘f’ is for ‘focus’ afaik).</li><li>Most libraries allow to xit() or xdescribe() to ignore a test or describe block. Also, mocha has the .skip() method to skip a block or test.</li></ul><p>)</p><p>In such a scenario, you must properly understand what is going on and fix the root of the problem. If the test suite fails sometimes, in such an unpredictable way, it will start to fail always when it gets bigger, and it’s a signal that something really wrong lays within your suite.</p><p>Commenting out specs that, for whatever reason, happen to fail in such scenarios is really bad: you’re probably wiping out a useful, working test, and you will face the same issue when you add more tests. On top of that, you maybe have a bug in your app that your broken, false positive test is hiding.</p><p>The obvious thing here is to go <strong>spec by spec </strong>and check if the async assertions are running properly: lack of the <strong>done </strong>callback (or a returned Promise in mocha) is a strong signal that something is broken.</p><h4>Bad Promises</h4><p>However, <strong>this is not the only possible problem</strong>. Working with promises, we may have broken tests due to <strong>mistakes when making promise chains</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1037dedaa6747313c5565989742cdd38/href">https://medium.com/media/1037dedaa6747313c5565989742cdd38/href</a></iframe><p>Here, we’re attaching a .then right after acme.getSomething(): doing so, we’re wrapping the expectation inside a <strong>plain callback </strong>-it just happen to be called inside a .then handler- and detaching it from the main promise chain. As a consequence of that, the <strong>done callback will run before the assertion</strong>, and the test will pass, even if it is broken (‘abracadabra’ is not the expected result there).</p><p><strong>So, just checking done parameter is passed to the spec and then called within the spec is not the only thing you need to check</strong>.</p><p>In order to fail properly, the spec should be written like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7bf1722fc5e15d0b8e7432b648b55d4/href">https://medium.com/media/c7bf1722fc5e15d0b8e7432b648b55d4/href</a></iframe><h4>Shared state</h4><p>They use to say <a href="http://toddkaufman.blogspot.com.es/2008/02/acid-principles-applied-to-testing.html">that tests should always be isolated</a>: this is a really good advice in general. On top of that, dealing with asynchronous testing, to properly <strong>isolate every test from each other is mandatory</strong>. If some of your tests depend upon some state set by a previous test, you can’t run tests in isolation. An when you can’t run a failing spec in isolation, you can’t tell if it fails by itself, by the previous test messing with the state, or by another one that is creating an asynchronous, delayed exception. Too many candidates: don’t ever share state between your specs, and you will never need to consider dependencies between tests when debugging a failing suite.</p><h4>So</h4><p>I really hope this story helps someone out there: when I first started doing js testing, I had almost no idea about the oddities of asynchronous api’s, callbacks, promises and all the stuff, and really had a bad time dealing with it. Asynchronous coding is hard, and asynchronous testing is harder, and having such problems when making javascript TDD is pretty common, so I really expect this can be useful to someone :-D!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac7e5c39257" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/javascript-asynchronous-testing-gotchas-ac7e5c39257">JavaScript Asynchronous Testing Gotchas</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git branches are just references to commits]]></title>
            <link>https://medium.com/@Sergeon/git-branches-are-just-references-to-commits-b66923026df9?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b66923026df9</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Sun, 10 Dec 2017 17:42:08 GMT</pubDate>
            <atom:updated>2017-12-10T17:42:08.717Z</atom:updated>
            <content:encoded><![CDATA[<p>Git branches are just pointers to commits. They are not actually ‘branches’ at all, since don’t contain nor group several commits: every branch just refers to a <strong>single commit</strong>. Since a Git repository is a ‘tree’ of nodes -the commits themselves- it sure has ‘branches’: but a ‘git branch’ has not a 1:1 correspondence to a ‘tree branch’ in that sense.</p><p>I actually needed a LOT OF TIME to realize this fact. I’ve met a lot of developers who also don’t know what git branches are exactly, so I hope this story will help someone out there.</p><p>One of the biggest problems when dealing with branches as a git newbye is that most articles about git and git branches usually give a deceitful graphical representation of them, <strong>pretending that branches are actually groups of commits </strong>instead of what they are: mere names for commits. Googling for images about ‘git branches’ gives a lot of images like those ones:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*dh2dKZh0CE3c-xDJ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*Ww1ygaG-Cw1FgkDF.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/0*ggOlZPq9HPDiEYmh.png" /></figure><p>The problem with such visualizations is that they seem to pretend that, at a git level, there are such things as ‘branches’ that somehow represent a group of commits. (of course, I’m not saying that the articles containing such representations are deceitful. They are fine if you know git well, but can be misleading if you don’t know exactly what branches are at low level).</p><p>However, at git level you’re dealing basically <em>only with commits</em>. Your project story is stored as several commits, which represent <em>versions</em>. Branches are just ways to name commits, so you can do:</p><pre>git checkout develop</pre><p>instead of:</p><pre>git checkout 2d3dabff7754f56862aa7e791b0a48e9725c8af4</pre><p>or:</p><pre>git merge develop master</pre><p>instead of:</p><pre>git merge 2d3dabff7754f56862aa7e791b0a48e9725c8af4 39ba55984ece3cf50d644c78cd47e28c6830552b</pre><p>Of course, <strong>at project level</strong>, when we create a new topic branch and start a new feature, we’re actually creating a group of commits that relate to that new feature. But that’s not <em>exactly</em> the way git branches work from git perspective: in git, a branch points only to a single commit.</p><h4>Ok, so what’s the deal?</h4><p>Not much, actually. However, I’ve seen several problems related to this lack of branches understanding, mainly those:</p><ul><li>Developers get afraid to delete branches.</li></ul><p>Once you’ve merged your ‘change-header-brand’ into master, it means that your master branch now points to a commit that contains -i.e., is descendant of- the last commit performing that feature. That commit -that version of your project, in which the new brand header is finished and ready for production- has now a reference other than the topic branch: so it can be deleted safely, without any risk of losing the work.</p><p>Developers who fail to realize this usually ends with a lot of local branches, which makes working with git really annoying.</p><ul><li>Lack of proper understanding of git merges</li></ul><p>To understand merges correctly can be taunting, and without the proper guidance is pretty easy to mess up things a lot when resolving conflicts in git: either you push conflicting files, or don’t add files to the merge commit that should be there, and you’re in the way to break a remote build.</p><p>If you don’t have a clear understanding of what commits and branches really are, chances that you will make such mistakes get bigger and bigger. To know what a git branch is and what is not is not the only thing you must to know in order to master git merges, but sure is one of them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b66923026df9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On pair programming]]></title>
            <link>https://medium.com/@Sergeon/on-pair-programming-dd827ce9637f?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd827ce9637f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[pair-programming]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Mon, 21 Nov 2016 15:06:01 GMT</pubDate>
            <atom:updated>2016-11-21T15:06:01.974Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first came to know about <a href="https://en.wikipedia.org/wiki/Extreme_programming">XP</a>, I really liked the idea of pair programming.</p><p>In software development and, well, in every aspect of life, I like the idea of do things slowly and carefully to get better results, avoid errors and prevent the need to re-do the same work several times. From this perspective, the idea of having two programmers to halve they actual coding time in order to produce better code seems great to me (while people who actually focus short-term productivity doesn’t really buy it).</p><p>Some years ago I had some pair programming with a coworker, but we coded little time together in the same machine and I didn’t form an opinion. Recently, I started to work at <a href="https://www.tea.ms/">teams</a> and spent a lot of time making pair programming with a coworker. <strong>Now, I really don’t feel comfortable with the idea of pair programming to work in a regular basis, while I strongly believe it has several advantages</strong>. Here are my thoughts.</p><h4>The bad parts</h4><ul><li>Programming != writing code</li></ul><p>Usually, when you’re programming you’re not writing code. I think that any developer spends more of the 90% of their working time reading code and documentation, or just planning and thinking about the code she is about to write. And two people can’t read easily in the same device. I found myself searching for docs in my mobile a lot while my mate was coding or reading in the monitor. That’s far from performant.</p><p>Also, when you’re just thinking on how to code somethings, if you have a person close to you, chances are that she will talk to you and break your focus. This may not happen, but surely will happen more that if you were alone. People tend to talk when they are close, even when there’s not a good reason to do it.</p><ul><li>Focus</li></ul><p>Even when you or your mate are actually coding, there are problems too. I really have a problem with the concentration, for instance. <strong>Humans cannot be focused constantly</strong>, some minor distractions are inevitable. When you’re coding, if you’re getting distracted, you just stop your work, with no other effect. But, when you’re doing pair programming, when you cease to focus, you’re not reviewing your mate code, and you’re forcing him to wait for you when you return from the clouds and need to read the code he wrote. Also, having to say “sorry, I was thinking about what would happen if <a href="http://theoatmeal.com/comics/dogs_as_men2">I had two middle-aged bearded men as pets</a>, can you explain me what was you doing?” is not the most polite interaction with a coworker.</p><p>On top of that, the fact that you have to maintain your focus while viewing how your mate is coding makes things worse. I was a professional online poker player for year’s, which is an activity that requires really heavy focus -since, playing online, you’re participating in several games at the same time-, and I had no problem making my A game for a period of, more or less, an hour. However, while performing tasks that are less intense -like viewing how my mate codes- I find more difficult to stay focused.</p><h4>The good parts</h4><p>While I think to just pair-programming 100% of the time is a bad idea, there are certain situations when it’s great, and good reasons to promote it:</p><ul><li>New kid on the block</li></ul><p>When you’re new in an organization, to be introduced into the codebase while pair-programming is really better than not. Period.</p><ul><li>Mentoring</li></ul><p>If you have a good senior developer in your team, the most profitable thing you can do with her time is <a href="https://medium.com/javascript-scene/the-essential-guide-to-building-balanced-development-teams-b051a62acc80#.q9n6smjiu">to mentor junior developers</a>. And mentoring usually involves pair programming.</p><ul><li>General knowledge</li></ul><p>A lot of important things that you may do while coding doesn’t show up in the code itself. The proper use or your IDE or editor, tricks involving multiple cursor or file searches, the proper use of debuggers or the chrome dev tools… those kind of things are <strong>really valuable </strong>and you can’t learn them just by peer reviewing code, you must see someone working with them.</p><ul><li>Avoid essential developers</li></ul><p>As a manager, you don’t want all your project to depend upon the availability of a single worker. Developers can leave your organization suddenly, get injured -we lost a devops for a month in our project due to a shoulder dislocation recently- and, well, they can eventually die. The best way to make the knowledge flow among your team and organization is to promote pair programming.</p><h4>So</h4><p>As a developer, I find pair programming to be uncomfortable when it last more than a small amount of time. Also, I think it is not efficient if the main goal is <strong>just to write quality code</strong>, and that <strong>peer review</strong> could achieve that goal better.</p><p>However, there are things in programming not <strong>directly </strong>related to produce quality code that does have a huge impact in the performance of a team or organization. As a team manager, <strong>I would enforce the developers on my team to have sessions of pair programming regularly, so no one is essential to the team and every developer in the team can learn from the others</strong>.</p><h4>Bonus: other stupid things I think about when my mate actually makes the hard work that pay my bills</h4><ul><li>How to make the perfect table tennis serve</li><li><a href="https://about.me/javascriptcheerleader">JS cheerleader</a>’s real identity</li><li>What is the strongest Saint Seiya character</li><li><a href="http://www.maxim.com/entertainment/man-100000-breasts-and-other-bets-gone-wild-2015-11">Boobs</a></li><li>Wether the <a href="https://getcomposer.org/">composer</a> logo is just nice or abominable</li><li><a href="http://www.simulation-argument.com/">If the universe is real or a computer simulation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd827ce9637f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[some thoughts on objects and function arity]]></title>
            <link>https://medium.com/@Sergeon/some-thoughts-on-objects-and-function-arity-6060ef00287e?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6060ef00287e</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Mon, 14 Nov 2016 15:01:02 GMT</pubDate>
            <atom:updated>2016-11-14T15:01:02.534Z</atom:updated>
            <content:encoded><![CDATA[<p>When you start learning programming and attend a course or read some tutorials, you may read that the goal of object oriented programming (<em>OOP</em> from now) is to simulate real world objects in the program classes.</p><p>Well, <a href="http://programmers.stackexchange.com/questions/137994/does-object-oriented-programming-really-model-the-real-world">it’s probably not the case</a>. <a href="https://www.johanbrook.com/writings/object-oriented-programming-and-modeling-the-real-world/">Not at all</a>. OOP is just about to write and read better, more robust and easier to maintain programs, and usually you don’t want your objects to be siblings of real world objects: you want them <a href="https://en.wikipedia.org/wiki/Single_responsibility_principle"><strong>just to be small</strong></a>.</p><p>When I read <a href="http://www.goodreads.com/book/show/3735293-clean-code">clean code</a> for the first time, years ago, there was this idea that strongly shook my mind: that <strong>one of the OOP main goals is to maintain a healthy balance between global variables and functions arity</strong>. Wether you consider <strong>javaScript</strong> to be an object oriented programming language or not, those kind of considerations are relevant too.</p><p>The <a href="https://en.wikipedia.org/wiki/Arity">arity</a> of a function is the number of parameters a function takes. Global variables are variables that are available to many modules of a program. Both concepts are in opposition: <strong>the less global variables you have, the most arity your functions have,</strong> since a function can only access a value if it is a parameter passed to itself or a variable that it have access to. (Actually, in a strict sense, ‘global variables’ are variables available to any module in your program; but variables available to many different modules can be considered global in a loose sense: that’s the way I’m referring to it in this article).</p><p>The most parameters a function has, the harder to use it is. If you have a function like getDouble(int), you perfectly know what it does just by reading its signature. But damn reduce( callback ), where that callback function has this signature:</p><pre>function( previousValue, currentValue, currentIndex, array); </pre><p>Is a mess. You usually need to read the docs to use a function that takes four parameters if you didn’t use it for some time.</p><p>Also, in most programming languages, methods with several parameters are difficult to refactor to default fallbacks. For example you have a:</p><pre>function createElement(name , type , color){</pre><pre>    if(color == null)<br>        color = &#39;white&#39;;<br>}</pre><p>That allows you to call it like:</p><pre>createElement(&#39;tree&#39; , &#39;node&#39;);<br>createElement(&#39;foo&#39; , &#39;node&#39;);<br>createElement(&#39;bar&#39; , &#39;root&#39;);</pre><p>Having the color to be white as default. Then you realize the color usually is not white and usually changes in every client call, but that the type is almost always a ‘node’. So you would want to change it to:</p><pre>function createElement(name , color , type){<br>    if(type == null)<br>        type = &#39;node&#39;;<br>}</pre><p>But you can’t because all the clients are currently calling it with the old signature. The bigger arity a function has, the bigger are the chances you will face this problem. Named parameters like in python would save us from that, but most PL’s doesn’t have that feature. The best way to achieve it is to pass hash tables or the like (PHP arrays or JS objects) as a single parameter instead of a large list of parameters that must respect a given order in every client call. For instance:</p><pre>function createElement(data){<br>    if(! data.color) data.color = &#39;white&#39;;<br>}</pre><p>Can be refactored to:</p><pre>function createElement(data){<br>    if(! data.color) data.color = &#39;white&#39;;<br>    if(! data.type) data.type = &#39;node&#39;;<br>}</pre><p>Without breaking current client calls.</p><p>This is not a reason to always pass a single data argument to functions. The signature:</p><pre>substring( start , end );</pre><p>Is really more readable than:</p><pre>substring(data);</pre><p>However,</p><pre>createUser(name, surname , sex, birthday, job, favoritePokemon );</pre><p>Can potentially lead to issues and just:</p><pre>createUser(userData);</pre><p>Can prevent them.</p><h4>Small objects</h4><p>A good small class or object has a limited amount of vars that are accessible to all its internal methods, so you don’t need to pass all the object properties from function to function as parameters. If you have a <em>View</em> object that needs a <em>selector</em>, a <em>data</em> and a <em>renderStrategy </em>vars, you have two options:</p><ol><li>Instantiate the object with that vars as properties, passed to constructor or factory function, so they are globally accessible for all the object methods.</li><li>Not to set them while creating or initiating the object, and get every method access them as parameters.</li></ol><p>For example we could code our view object as in the first option:</p><pre>var createView = function(selector , data , renderStrategy){</pre><pre>var module = {};</pre><pre>module.render = function(){<br>        /*some code that uses the outer function parameters*/<br>    };</pre><pre>module.getInitialState = function(){<br>        /*some code that uses the outer function parameters*/<br>    };</pre><pre>module.shouldUpdate = function(){<br>        /*some code that uses the outer function parameters*/<br>    };</pre><pre>    return module;</pre><pre>}</pre><pre>var view = createView(params);</pre><p>Or with the second style:</p><pre>var view = {<br>    render : function(selector, data, renderStrategy){<br>         ...<br>    },</pre><pre>    getInitialState :function(data){<br>         ...<br>    },</pre><pre>    shouldUpdate :function(selector , data){<br>         ...<br>    },<br>}</pre><p>Making <em>view</em> some sort of static object that doesn’t have state. However, parameters must be passed to its methods every time. If those methods relies on internal methods that also need access to that data, those methods would need that parameters too, so the arity of all the methods and the verbosity of the program will grow.</p><p>To depend a lot on state and global variables is a <a href="http://wiki.c2.com/?GlobalVariablesAreBad">certain way to disaster</a>. To increment the arity of your functions isn’t good too. However, to create <strong>small</strong> classes or objects allow you to depend upon global variables in a controlled and sensible way, avoiding the common pitfalls of global state driven programs, and also preventing its methods to have too much arity.</p><p>Function arity and object properties are good indicators of the size of your object: if the inner functions of your object or class gets a lot of parameters from other methods, it’s a sign that you should set those parameters as properties. If there are a lot of object properties that are not used in several methods, or that are only use among with other properties, is a sign that your object or class is too big and should split.</p><p><strong>Always maintain a vigilante attitude against functions with lots of parameters, and prevent them to proliferate on your code.</strong> Refactor those parameters to properties to be set up on creation, or use dictionaries as parameters instead of forcing clients to know the proper arguments order to use.</p><p>Oh, one last thing: <strong>if you didn’t read </strong><a href="http://www.goodreads.com/book/show/3735293-clean-code"><strong>clean code</strong></a><strong>, get your hands on it</strong>. This is surely the best recommendation you will read about programming this month if you didn’t know that book.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6060ef00287e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dealing with functional parameters in javascript]]></title>
            <link>https://medium.com/@Sergeon/dealing-with-functional-parameters-in-javascript-5bb53b036212?source=rss-2153eebae02b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bb53b036212</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sergeon]]></dc:creator>
            <pubDate>Mon, 07 Nov 2016 15:01:01 GMT</pubDate>
            <atom:updated>2016-11-07T15:01:01.666Z</atom:updated>
            <content:encoded><![CDATA[<p>In a lot of github sources or Stack Overflow Q&amp;A’s I see this pattern a lot, wherever there are callbacks or event handlers functional parameters:</p><pre>someHandlerFunction( function(res){</pre><pre>    doSomething(res);</pre><pre>});</pre><p>This is really unnecessary, that code should be write like this:</p><pre>someHandlerFunction(doSomething);</pre><p>It is basically the same, without the extra function wrapper (but also without filtering the arguments only to <em>res</em> -we’ll see this issue later-). <em>someHandlerFunction</em> is passing some response -<em>res</em>- to the function it takes as a parameter. <em>doSomething</em> is just a function: so you don’t need more. Any time in javascript a function requires another function as a parameter, that function <strong>does not have to be a new anonymous function</strong>. It can just be a function variable: <a href="http://ryanchristiani.com/functions-as-first-class-citizens-in-javascript/">functions are first-class citizens in javascript</a>. That is one of the best javascript parts, so you better abuse it.</p><p>Avoiding redundant function wrappers really pays off when a function takes two callbacks:</p><pre>someErrorSuccessTwoCallbackFn( function(err){<br>    notifyError(err);<br>}, function(res){<br>    console.log(res);<br>}); </pre><p>Please, just do:</p><pre>someErrorSuccessTwoCallbackFn(notifyError , console.log );</pre><p>Or when you’re using reduce or map:</p><pre>var current = &#39;there was a time&#39;;<br>var storyData = [&#39;when&#39; , &#39;pigs&#39; , &#39;flew.&#39;];</pre><pre>var story = storyData.reduce( function( text , word ){<br>  return text + &#39; &#39; + word;<br>} , current ) ;</pre><p>Better this way:</p><pre>var story = storyData.reduce( completeStory , current );</pre><pre>function completeStory(text , word ){<br>    return text + &#39; &#39; + word;<br>}</pre><p>Ok, this kind of pattern works properly most of the times, but it can lead to some pitfalls:</p><h4>Dealing with extra parameters</h4><p>Let’s say we have a function <em>processData</em> defined as follows:</p><pre>function processData(data , start , end){<br>    data = data.slice(start , end);<br>    //...then do something cool with data<br>}</pre><p>And we have a function that grabs data from some place, which is passing a status code as a second parameter, so:</p><pre>grabData( function(res, status){<br>    console.log(res);<br>    console.log(status);<br>});</pre><p>Will print an array with the data and, for instance, a ‘200’. Well, this is pretty bad because if we have our code like:</p><pre>grabData( function(res){<br>    processData(data);<br>});</pre><p>and we then refactor to:</p><pre>grabData(processData);</pre><p>We will have a different output, since the extra 200 from the <em>status </em>parameter is now being passed to <em>processData</em> as the <em>start </em>to slice the data array. This can be dramatically bad if grabData only sends this second parameter sometimes, depending on external side conditions, thus making this error difficult to reproduce in tests.</p><p>An easy way to circumvent this is just to create a wrapper function, but instead to pass it to grabData as anonymous, just declare it and pass it by name:</p><pre>grabData( dealWithData );</pre><pre>function dealWithData(data){<br>    processData(data);<br>}</pre><p>While this can seem dumb, I rather prefer to read code this way than have to cope with all the anonymous function wrappers inside function parameters. Also, is more DRY than creating several equal new wrapper functions if this operation is repeated in the code.</p><p>However, a better approach is to define a function once that can deal with this automatically every time a client needs to cut function arguments:</p><pre>grabData(unary(processData));</pre><pre>function unary(fn) {<br>    return function onlyOneArg(arg){<br>        return fn( arg );<br>    };<br>}</pre><p>Or even a function that just lets the client to choose the number of arguments in every call:</p><pre>grabData( setArity(processData , 1) );</pre><pre>function setArity( fn , arity ){<br>  return function withChosenArity(...args){<br>    return fn.apply(null , args.slice(0 , arity ) );<br>  }<br>}</pre><h4>Binding functions</h4><p>Another common pitfall when just passing functions as parameters, is that you’re passing <strong>just the function</strong>, not a function call from an object (a method call). This somehow decouples the function itself from the object it belongs, not allowing it to access to the object context, so internal uses of <em>this </em>keyword within the function body will fail or have unexpected weird behavior:</p><pre>var myAwesomeConsole = {<br>  uses : 0,<br>  log : function(msg){<br>    console.log( &quot; log number &quot; + this.uses);<br>    console.log(msg);<br>    this.uses++;<br>  }<br>}</pre><pre>var words = [&#39;hello&#39; , &#39;world&#39; , &#39;goodbye&#39;];</pre><pre>words.forEach(myAwesomeConsole.log);</pre><p>Will have this output:</p><blockquote>“ log number undefined”</blockquote><blockquote>“hello”</blockquote><blockquote>“ log number NaN”</blockquote><blockquote>“world”</blockquote><blockquote>“ log number NaN”</blockquote><blockquote>“goodbye”</blockquote><p>Because that <em>log </em>function is being called actually from the global object, instead from <em>myAwesomeConsole. </em>Should this global object -<em>window </em>in browser javascript- have a <em>uses</em> property, the side effects and behavior of calling <em>myAwesomeConsole.log </em>would<em> </em>be completely unpredictable.</p><p>A way to prevent this is to do:</p><pre>words.forEach(myAwesomeConsole.log.bind( myAwesomeConsole) );</pre><p>But that’s pretty verbose and we just don’t want to force clients to do that in every call, so we rather bind <em>myAwesomeConsole.log</em> to the <em>myAwesomeConsole </em>object this way once, right after defining the object:</p><pre>var myAwesomeConsole = {<br>  uses : 0,<br>  log : function(msg){<br>    console.log( &quot; log number &quot; + this.uses);<br>    console.log(msg);<br>    this.uses++;<br>  }<br>}</pre><pre>myAwesomeConsole.log = myAwesomeConsole.log.bind(myAwesomeConsole);</pre><pre>var words = [&#39;hello&#39; , &#39;world&#39; , &#39;goodbye&#39;];</pre><pre>words.forEach(myAwesomeConsole.log);</pre><p>In fact, the good ol’ <em>console.log</em> function of the <em>console </em>browser object had this very same problem, and it was fixed not so long ago from browser vendors just by binding the <em>console</em> methods to the <em>console</em> object itself this way.</p><h4>Finally</h4><p>Functions are just plain values in javascript, you can just pass them around like any other value type: <strong>just keep in mind you’re passing functions, not methods, </strong>so binding issues can arise.</p><p>Instead of creating anonymous function wrappers to pass to handlers, it’s better to just pass functions by name, in order to prevent boilerplate code ad unnecessary verbosity in your code. Whenever you’re dealing with event handlers, promises or node callback-style API’s, to get rid of all those redundant <em>function(){…}</em> wrappers will make your code more readable and performant.</p><p><a href="https://github.com/getify/Functional-Light-JS/blob/master/ch3.md">This chapter</a> from the <a href="https://github.com/getify">getify</a> book on functional programming is a great read to understand how to manage function parameters and how some helper functions can be used to manage functional parameters. The <em>unary </em>function from one of the previous code snippets was grab from there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bb53b036212" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>