<?xml version="1.0" encoding="utf-8" standalone="yes"?><?xml-stylesheet href="/rss.xsl" type="text/xsl"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" >
  <channel>
    <title>Software on Jose M.</title>
    <link>https://josem.co/categories/software/</link>
    <description>Recent articles on Jose M.</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Sun, 12 Apr 2026 21:00:50 +0200</lastBuildDate>
    
	<atom:link href="https://josem.co/categories/software/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>HUMANS.md</title><link>https://josem.co/humans.md/</link>
      <pubDate>Sun, 12 Apr 2026 21:00:50 +0200</pubDate>
      
      <guid>https://josem.co/humans.md/</guid><description type="html">&lt;p&gt;Things got a bit messy.&lt;/p&gt;
&lt;p&gt;They all demanded more, more and more: clients, your manager, deadlines coming up, even yourself, feeling you were falling behind, and now, thanks to AI, you can provide.&lt;/p&gt;
&lt;p&gt;Oh boy, big time!&lt;/p&gt;
&lt;p&gt;You don’t even execute the code anymore, reviewing PRs is almost a lost art, and you can’t remember the last time you typed some actual code in your editor.&lt;/p&gt;
&lt;p&gt;You have reached peak productivity in this new world. You’ve even started experimenting with work trees, so you can put agents to work on multiple features and bugs at the same time.&lt;/p&gt;
&lt;p&gt;But who has time to test things locally anymore? To understand the thousands of lines of code you’ve put in there in the last month alone? That’s when we need a new kind of file.&lt;/p&gt;
&lt;p&gt;An understandable and self-updated file that tells me how things are organized in the code, how to run things manually, and which kind of technical direction we’re following with each change. That’s when we need humans.md.&lt;/p&gt;
&lt;p&gt;This file is inspired by AGENTS.md or CLAUDE.md, which allows the LLMs to get the context of your project, but in a world where we don’t code anymore, perhaps we also need the opposite: a file to explain to us (humans) what’s going on at multiple levels. We could even instruct the coding agent to keep it updated while summarizing the important points.&lt;/p&gt;
&lt;p&gt;P.S. This is a kind of joke at the moment, but I don’t think it’s too far into the future that we’ll see this file in some repositories.&lt;/p&gt;
</description>
      <abstract>Things got a bit messy. They all demanded more, more and more: clients, your manager, deadlines coming up, even yourself, feeling you were falling behind, and now, thanks to AI, you can provide. Oh boy, big time!</abstract></item>
    
    <item>
      <title>If you don&#39;t write it, I don&#39;t read it</title><link>https://josem.co/if-you-dont-write-it-i-dont-read-it/</link>
      <pubDate>Tue, 07 Apr 2026 07:07:32 +0200</pubDate>
      
      <guid>https://josem.co/if-you-dont-write-it-i-dont-read-it/</guid><description type="html">&lt;p&gt;Writing might be repetitive, boring, and difficult. It takes effort, skill, and countless edits to make it right, to transform what you had in your mind into something people can understand without getting bored.&lt;/p&gt;
&lt;p&gt;Now with AI, it&amp;rsquo;s very tempting to use Claude, or ChatGPT, to write something, or just use a dictation app because who wants to write anymore, right? But if you think that what you want to communicate is not worth the effort of sitting down and articulating it as a human being in writing form, perhaps it was not so important after all.&lt;/p&gt;
&lt;p&gt;Writing is not only a dump of your thoughts, but it&amp;rsquo;s an exercise to organize your thinking, to articulate better what you had in your mind, to summarize some things, even to realize you were wrong sometimes.&lt;/p&gt;
&lt;p&gt;Why would you think that if you didn&amp;rsquo;t take the time to write it, people will take the time to read it? Whenever I read something online and see some signals of AI-generated copy (like the infamous —), I skip it.&lt;/p&gt;
&lt;p&gt;My rule is simple: if you don&amp;rsquo;t have time to write it, I don&amp;rsquo;t have time to read it.&lt;/p&gt;
</description>
      <abstract>Writing is sometimes repetitive, hard, and boring, but if you don&#39;t spend the time writing something, expect the same from your readers when they encounter your text.</abstract></item>
    
    <item>
      <title>Side Projects and AI</title><link>https://josem.co/side-projects-and-ai/</link>
      <pubDate>Mon, 01 Sep 2025 08:32:30 +0200</pubDate>
      
      <guid>https://josem.co/side-projects-and-ai/</guid><description type="html">&lt;p&gt;&lt;picture&gt;&lt;img src=&#34;https://josem.co//images/2025/desk@2x.jpg&#34; alt=&#34;Desk&#34; decoding=&#34;async&#34; fetchpriority=&#34;high&#34; loading=&#34;eager&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;&lt;em&gt;Photo by &lt;a href=&#34;https://unsplash.com/@remyloz&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Remy Loz&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

    
&lt;p&gt;Some years ago, building a side project meant finding time wherever you could. Late nights, weekends, or early mornings to squeeze in some work before your real job starts.&lt;/p&gt;
&lt;p&gt;Any SaaS or app you wanted to build used to take months of this busy schedule until you could launch it. As a result, balancing building a side project with a day job (plus family!) was a challenge that few people were willing to accept.&lt;/p&gt;
&lt;p&gt;Now, with tools like Claude Code, the paradigm has shifted. The cost of creating software is much cheaper. What used to take months now takes days. You can do most of your basic features with AI if you use a well-known framework with good standards. But what does this mean?&lt;/p&gt;
&lt;p&gt;First, there is a natural big shift in our job market. With less effort to build software, everybody else is experiencing the same benefit, so we&amp;rsquo;ll need to hire fewer engineers to do the same job we were doing before. I already know great people who are facing hard challenges entering the job market as junior engineers.&lt;/p&gt;
&lt;p&gt;If the barrier to launching a software product is lower, more will be in the market, making it harder to succeed. But at this point is where we, as software developers, are wrong; in fact it&amp;rsquo;s a great time to be an entrepreneur.&lt;/p&gt;
&lt;p&gt;As a software developer, &lt;strong&gt;coding was never the real barrier&lt;/strong&gt; to building a successful side business. Without AI, it might have taken longer, but we could still build what we wanted.&lt;/p&gt;
&lt;p&gt;The real challenge was—and still is—everything else required to get paying customers. We love staying in our IDEs, shipping yet-one-more-feature to our grand total of zero users. It&amp;rsquo;s comfortable. It&amp;rsquo;s safe. It&amp;rsquo;s familiar.&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s uncomfortable? Sales calls, cold emails, blog posts echoing in the void, facing rejection, or talking to potential customers (I know, scary!). These are the skills that turn code into revenue, and AI hasn&amp;rsquo;t fully automated them yet. So the challenges remain for everybody else, too.&lt;/p&gt;
&lt;p&gt;The only difference is that now we get a faster feedback loop about the skills we lack to build a business. The sooner we recognize what&amp;rsquo;s actually holding us back, the sooner we can develop the skills that matter.&lt;/p&gt;
&lt;p&gt;AI didn&amp;rsquo;t remove the obstacles—it just helped us find them faster.&lt;/p&gt;
</description>
      <abstract>Some years ago, building a side project meant finding time wherever you could. Late nights, weekends, or early mornings to squeeze some work in before your real job starts.</abstract></item>
    
    <item>
      <title>From Simple to Ornate and Back Again</title><link>https://josem.co/simple-to-ornate-and-back-again/</link>
      <pubDate>Wed, 07 Aug 2024 05:04:53 +0200</pubDate>
      
      <guid>https://josem.co/simple-to-ornate-and-back-again/</guid><description type="html">&lt;p&gt;Art history shows us that we tend to move between adding &amp;ldquo;unnecessary&amp;rdquo; elaborate decorations to clean styles and back again. It&amp;rsquo;s almost an endless cycle repeated over and over.&lt;/p&gt;
&lt;p&gt;This cycle happens in the different arts and other fields where design is involved, like software. Let&amp;rsquo;s trace it in architecture first.&lt;/p&gt;
&lt;p&gt;Here is the &lt;a href=&#34;https://www.wikiart.org/en/romanesque-architecture/abbey-church-of-st-james-lebeny-hungary-1208-0&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Abbey Church of St James&lt;/a&gt; in Hungary (1206), a clear example of the Romanesque style. By its side, &lt;a href=&#34;https://en.wikipedia.org/wiki/Notre-Dame_de_Paris&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Notre Dame&lt;/a&gt;, completed in 1345. Take a moment to appreciate all the decorations in the second picture not present in the first one.&lt;/p&gt;
&lt;p class=&#34;bigger-image&#34;&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/architecture1_double@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;a href=&#34;https://josem.co/images/2024/simple-ornate/architecture1_double@2x.png&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;
            &lt;img src=&#34;https://josem.co//images/2024/simple-ornate/architecture1_double@2x.png&#34; alt=&#34;Abbey Church of St James, in Hungary, and Notre Dame by its side&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;1000&#34; /&gt;
          &lt;/a&gt;
        &lt;/picture&gt;
      &lt;/p&gt;

    
&lt;p&gt;This tendency to add more details and decorations to an already functioning element of architecture went out of fashion (like it had done in previous periods). Here, you can compare Notre Dame with the &lt;a href=&#34;https://it.wikipedia.org/wiki/Duomo_di_Pienza&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Cathedral of Pienza&lt;/a&gt;, an example of Renaissance architecture.&lt;/p&gt;
&lt;p class=&#34;bigger-image&#34;&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/architecture2_double@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;a href=&#34;https://josem.co/images/2024/simple-ornate/architecture2_double@2x.png&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;
            &lt;img src=&#34;https://josem.co//images/2024/simple-ornate/architecture2_double@2x.png&#34; alt=&#34;Notre Dame, in Paris, and the Cathedral of Pienza by its side&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;1000&#34; /&gt;
          &lt;/a&gt;
        &lt;/picture&gt;
      &lt;/p&gt;

    
&lt;p&gt;So, 250 years to realize again that we don&amp;rsquo;t want to add so many grandiose elements and prefer simplicity?&lt;/p&gt;
&lt;p&gt;If we move to Baroque and Rococo, it&amp;rsquo;s like going in the opposite direction again, adding more and more decorations that weren&amp;rsquo;t essential to the buildings. Here&amp;rsquo;s the Cathedral of Pienza compared to the &lt;a href=&#34;https://en.wikipedia.org/wiki/Catherine_Palace&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Catherine Palace&lt;/a&gt; in Russia.&lt;/p&gt;
&lt;p class=&#34;bigger-image&#34;&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/architecture3_double@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;a href=&#34;https://josem.co/images/2024/simple-ornate/architecture3_double@2x.png&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;
            &lt;img src=&#34;https://josem.co//images/2024/simple-ornate/architecture3_double@2x.png&#34; alt=&#34;Cathedral of Pienza compared to Catherine Palace, in Tsarskoe Selo&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;1000&#34; /&gt;
          &lt;/a&gt;
        &lt;/picture&gt;
      &lt;/p&gt;

    
&lt;p&gt;But after a while, we got tired and returned to simple and clear lines.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/architecture4@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/2024/simple-ornate/architecture4@2x.png&#34; alt=&#34;Jefferson Memorial, 1943&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;&lt;em&gt;Thomas Jefferson Memorial in Washington, D.C&lt;/em&gt;&lt;/p&gt;

    
&lt;p&gt;The cycle between this highly detailed and elaborate style and returning to simple and clean elements is not perfect. Art is a complicated combination of influence, technique available at the time, and the historical context in which it&amp;rsquo;s developed. However, the pattern is there.&lt;/p&gt;
&lt;p class=&#34;bigger-image&#34;&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/cycleart_double@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;a href=&#34;https://josem.co/images/2024/simple-ornate/cycleart_double@2x.png&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;
            &lt;img src=&#34;https://josem.co//images/2024/simple-ornate/cycleart_double@2x.png&#34; alt=&#34;Cycle of art&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;1000&#34; /&gt;
          &lt;/a&gt;
        &lt;/picture&gt;
      &lt;/p&gt;

    
&lt;p&gt;The cycle is not only present in architecture. It can also be found in painting, photography, sculpting, literature, theatre, and even fashion. So it&amp;rsquo;s not surprising that we see it in software.&lt;/p&gt;
&lt;p&gt;This is one of the first text editors: vi. It was created in 1978, and it is as simple as it gets visually. Although you need to learn a shortcut or two to use it :)&lt;/p&gt;
&lt;p class=&#34;bigger-image&#34;&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/vi_double@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;a href=&#34;https://josem.co/images/2024/simple-ornate/vi_double@2x.png&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;
            &lt;img src=&#34;https://josem.co//images/2024/simple-ornate/vi_double@2x.png&#34; alt=&#34;Vi Editor&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;1000&#34; /&gt;
          &lt;/a&gt;
        &lt;/picture&gt;
      &lt;/p&gt;

    
&lt;p&gt;Here&amp;rsquo;s Microsoft Word, the king of text editors for a long time.&lt;/p&gt;
&lt;p class=&#34;bigger-image&#34;&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/word1995_double.webp&#34; type=&#34;image/webp&#34;&gt;&lt;a href=&#34;https://josem.co/images/2024/simple-ornate/word1995_double.jpg&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;
            &lt;img src=&#34;https://josem.co//images/2024/simple-ornate/word1995_double.jpg&#34; alt=&#34;Microsoft Word&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;1000&#34; /&gt;
          &lt;/a&gt;
        &lt;/picture&gt;
      &lt;/p&gt;

    
&lt;p&gt;You could say it&amp;rsquo;s just the technology that didn&amp;rsquo;t allow developers to create something more visually appealing in the early 80s, and that&amp;rsquo;s partially right. But now, technology lets you do much more, and people are returning to this minimalism. Here&amp;rsquo;s iA Writer, a text editor for Mac I use to write these articles, and loved by many people.&lt;/p&gt;
&lt;p class=&#34;bigger-image&#34;&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/iawriter_double@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;a href=&#34;https://josem.co/images/2024/simple-ornate/iawriter_double@2x.png&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;
            &lt;img src=&#34;https://josem.co//images/2024/simple-ornate/iawriter_double@2x.png&#34; alt=&#34;iA Writer&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;1000&#34; /&gt;
          &lt;/a&gt;
        &lt;/picture&gt;
      &lt;/p&gt;

    
&lt;p&gt;You can find a similar tendency in Operating Systems like Mac OS. Here&amp;rsquo;s Mac OS X 10.0 (released in 2001).&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/macosxcheetah@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/2024/simple-ornate/macosxcheetah@2x.jpg&#34; alt=&#34;Mac OS X Cheetah&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;&lt;em&gt;2001 (&lt;a href=&#34;https://blog.aventure-apple.com/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;source&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

    
&lt;p&gt;And we&amp;rsquo;re clearly back to clean interfaces in a recent version of Mac OS X 14.0, released 22 years later.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/2024/simple-ornate/mac14@2x.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/2024/simple-ornate/mac14@2x.png&#34; alt=&#34;Mac OS X Sonoma&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;&lt;em&gt;2023&lt;/em&gt;&lt;/p&gt;

    
&lt;hr&gt;
&lt;h2 id=&#34;will-we-go-back-to-rococo-software&#34;&gt;Will We Go Back to &amp;ldquo;Rococo&amp;rdquo; Software?&lt;/h2&gt;
&lt;p&gt;I know it seems impossible now, but we&amp;rsquo;ll certainly will.&lt;/p&gt;
&lt;p&gt;We naturally get tired of the same design styles over time, so we&amp;rsquo;ll get a new wave of overly designed software in the next few years. Given its reduced timeline compared to architecture or painting, software will take more time to see this cycle clearly, but it&amp;rsquo;ll be there.&lt;/p&gt;
&lt;p&gt;That said, if we see software design as an independent visual art, it&amp;rsquo;s also possible that this change happens much more quickly, and what takes 100 years in architectural styles to change could take ten years in software. Only time will tell.&lt;/p&gt;
&lt;p&gt;In the meantime, let&amp;rsquo;s enjoy this period of mostly simple software that focuses on doing one thing without distracting you.&lt;/p&gt;
</description>
      <abstract>Art history shows us that we tend to move between adding &#34;unnecessary&#34; elaborate decorations to clean styles and back again. It&#39;s almost an endless cycle repeated over and over. This cycle happens in the different arts and other fields where design is involved, like software. Let&#39;s trace it in architecture first.</abstract></item>
    
    <item>
      <title>The Beauty of Finished Software</title><link>https://josem.co/the-beauty-of-finished-software/</link>
      <pubDate>Tue, 31 Oct 2023 08:32:49 +0200</pubDate>
      
      <guid>https://josem.co/the-beauty-of-finished-software/</guid><description type="html">&lt;p&gt;Let me introduce you to &lt;a href=&#34;https://en.wikipedia.org/wiki/WordStar&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;WordStar 4.0&lt;/a&gt;, a popular word processor from the early 80s.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/wordstar.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/wordstar.jpg&#34; alt=&#34;Wordstar 4.0&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;&lt;em&gt;WordStar 4.0&lt;/em&gt;&lt;/p&gt;

    
&lt;p&gt;As old as it seems, George R.R. Martin used it to write &amp;ldquo;A Song of Ice and Fire&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Why would someone use such an old piece of software to write over 5,000 pages? I love how he puts it:&lt;/p&gt;

&lt;blockquote&gt;
It does everything I want a word processing program to do and it doesn&#39;t do anything else. I don&#39;t want any help. I hate some of these modern systems where you type up a lowercase letter and it becomes a capital. I don&#39;t want a capital, if I&#39;d wanted a capital, I would have typed the capital.&lt;cite&gt;&lt;a href=&#34;https://josem.co/#rf1&#34; class=&#34;reference&#34;&gt;George R.R. Martin&lt;/a&gt;&lt;/cite&gt;&lt;/blockquote&gt;

&lt;p&gt;This program embodies the concept of finished software — a software you can use forever with no unneeded changes.&lt;/p&gt;
&lt;p&gt;Finished software is software that&amp;rsquo;s not expected to change, and that&amp;rsquo;s a feature! You can rely on it to do some real work.&lt;/p&gt;
&lt;p&gt;Once you get used to the software, once the software works for you, you don&amp;rsquo;t need to learn anything new; the interface will exactly be the same, and all your files will stay relevant. No migrations, no new payments, no new changes.&lt;/p&gt;
&lt;p&gt;This kind of software can be created intentionally, with a compromise from the creators that they won&amp;rsquo;t bother you with things you don&amp;rsquo;t need, and only the absolutely necessary will change, like minor updates to make it compatible with new operating systems.&lt;/p&gt;
&lt;p&gt;Sometimes, finished software happens accidentally; maybe the company behind it has disappeared, or the product has been abandoned.&lt;/p&gt;
&lt;p&gt;There are also some great examples in the UNIX world of finished software: commands like &lt;code&gt;cd&lt;/code&gt;(to change the current directory) or &lt;code&gt;ls&lt;/code&gt;(to list what&amp;rsquo;s there) won&amp;rsquo;t ever change in a significant way. You can rely on them until the end of your career.&lt;/p&gt;
&lt;h2 id=&#34;the-seduction-of-constant-updates&#34;&gt;The seduction of constant updates&lt;/h2&gt;
&lt;p&gt;Our expectations for software are different from other products we use in our daily lives.&lt;/p&gt;
&lt;p&gt;When we buy a physical product, we accept that it won&amp;rsquo;t change in its lifetime. We&amp;rsquo;ll use it until it wears off, and we replace it. We can rely on that product not evolving; the gas pedal in my car will always be in the same place.&lt;/p&gt;
&lt;p&gt;However, when it comes to software, we usually have the ingrained expectations of perpetual updates. We believe that if software doesn&amp;rsquo;t evolve it&amp;rsquo;ll be boring, old and unusable. If we see an app with no updates in the last year, we think the creator might be dead.&lt;/p&gt;
&lt;p&gt;We also expect new versions of any software will be better than the previous ones. Once it&amp;rsquo;s released, most of our problems will be solved! What a deceiving lie.&lt;/p&gt;
&lt;p&gt;Sometimes, a software upgrade is a step backward: less usable, less stable, with new bugs. Even if it&amp;rsquo;s genuinely better, there&amp;rsquo;s the learning curve. You were efficient with the old version, but now your most used button is on the other side of the screen under a hidden menu.&lt;/p&gt;
&lt;h2 id=&#34;finished-software-is-a-good-reminder&#34;&gt;Finished software is a good reminder&lt;/h2&gt;
&lt;p&gt;In a world where constant change is the norm, finished software provides a breath of fresh air. It&amp;rsquo;s a reminder that reliability, consistency, and user satisfaction can coexist in the realm of software development.&lt;/p&gt;
&lt;p&gt;So the next time you find yourself yearning for the latest update, remember that sometimes, the best software is the one that doesn&amp;rsquo;t change at all.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;references&#34;&gt;References&lt;/h3&gt;
&lt;p&gt;&lt;span class=&#34;reference-note&#34; id=&#34;rf1&#34;&gt;[1] George R.R. Martin in Conan show (2014). &lt;a href=&#34;https://www.youtube.com/watch?v=X5REM-3nWHg&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;https://www.youtube.com/watch?v=X5REM-3nWHg&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>Good Code Is Invisible</title><link>https://josem.co/good-code-is-invisible/</link>
      <pubDate>Wed, 19 Feb 2020 14:08:51 +0100</pubDate>
      
      <guid>https://josem.co/good-code-is-invisible/</guid><description type="html">&lt;p&gt;We all try to create good and clean code, projects that are maintainable and easy to change and yet, we don&amp;rsquo;t appreciate when we have one.&lt;/p&gt;
&lt;p&gt;Do you remember the last time you easily change something in your code?&lt;/p&gt;
&lt;p&gt;Maybe it was a simple constant that was only in one place, or a new parameter in an API endpoint that was fast to test. You might remember but I bet you didn&amp;rsquo;t stop to appreciate how easy the change was, how productive it felt and how it could have been much worse in other scenarios, it just felt right. You didn&amp;rsquo;t think too much about it because good code is invisible.&lt;/p&gt;
&lt;p&gt;We don&amp;rsquo;t think too much about existing code until it gets in our way to accomplish what we want, in the same way we don&amp;rsquo;t appreciate our own good health until we get ill.&lt;/p&gt;
&lt;h2 id=&#34;products-perspective&#34;&gt;Product&amp;rsquo;s perspective&lt;/h2&gt;
&lt;p&gt;From the stakeholders of a product, good and maintainable code is expected, although rare to find.&lt;/p&gt;
&lt;p&gt;They treat code in the same way that I treat my car. When I get into my car and start the engine, I expect it to work well and get me safely to my destination. I&amp;rsquo;d not be very happy if I see a warning light complaining about something I didn&amp;rsquo;t know it existed and I&amp;rsquo;d be even more concerned if three of them are on in the same trip.&lt;/p&gt;
&lt;p&gt;When you work with product stakeholders, they don&amp;rsquo;t pay attention to the code. They don&amp;rsquo;t care about how many returns or lines you have in a single method or whether you use TDD or modify the code in production with an FTP client.&lt;/p&gt;
&lt;p&gt;They see the project as the final user is going to perceive it. They&amp;rsquo;re trying to get the project somewhere else and code can help or prevent that from happening. They care about results in the form of features, bugs or speed, things way more tangible that the code you see in the editor.&lt;/p&gt;
&lt;p&gt;The fact that your code is good and maintainable is a competitive advantage that only you and your colleagues truly appreciate and, although it affects all the stakeholders of the product in a big way, they&amp;rsquo;re just usually not aware of it.&lt;/p&gt;
&lt;p&gt;And with all of this, if it&amp;rsquo;s very likely that few people notice how easy is to work with that project, why should you care?&lt;/p&gt;
&lt;h2 id=&#34;this-is-your-life&#34;&gt;This is your life&lt;/h2&gt;
&lt;p&gt;First of all, because, as Dave Thomas and Andrew Hunt mention in &amp;ldquo;The Pragmatic Programmer&amp;rdquo;: &amp;ldquo;this is your life&amp;rdquo;. Do you want to have a fulfilling pride of your accomplishments every week? Do you want to look at that piece of code and easily see how you made it better? Or do you prefer to spend the rest of your days in that company or project barely surviving, sweeping dirty code under the carpet with the hope that it&amp;rsquo;ll get better magically someday because you&amp;rsquo;ll have time for the ultimate refactoring (or rewriting the whole thing)?&lt;/p&gt;
&lt;h2 id=&#34;common-goals&#34;&gt;Common goals&lt;/h2&gt;
&lt;p&gt;Outside your personal feelings and goals, you&amp;rsquo;re working in that project because, deep down, you care about something. It could be the mission of the company, your team, the users or even just the money you&amp;rsquo;re making there. In any case, the better the project is because you cared about your work, the more chances it&amp;rsquo;ll have to succeed. And even if it doesn&amp;rsquo;t, you won&amp;rsquo;t have any regrets that it was your fault.&lt;/p&gt;
&lt;h2 id=&#34;bad-code-is-like-a-disease&#34;&gt;Bad code is like a disease&lt;/h2&gt;
&lt;p&gt;Bad code can hurt and eventually kill companies. If your company can&amp;rsquo;t adapt fast enough in a new market others will pass by and win. If your users aren&amp;rsquo;t happy about the quality of something you&amp;rsquo;ve built and you don&amp;rsquo;t know where the issue is because the code is a mess, you might lose them. If they leave others might follow and soon, what you cared about when you started in that project, might be lost forever.&lt;/p&gt;
&lt;p&gt;Do what you can every day to stay healthy and treat your code in the same way, you won&amp;rsquo;t regret it.&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>Why I Keep a Personal Log of Bugs</title><link>https://josem.co/why-i-keep-a-personal-log-of-bugs/</link>
      <pubDate>Thu, 24 Oct 2019 15:08:51 +0100</pubDate>
      
      <guid>https://josem.co/why-i-keep-a-personal-log-of-bugs/</guid><description type="html">&lt;p&gt;&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/apple-black-and-white-black-and-white-169573.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/apple-black-and-white-black-and-white-169573.jpg&#34; alt=&#34;Notebook&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;Notebook&lt;/p&gt;

    

&lt;em&gt;Photo by &lt;a href=&#34;https://www.pexels.com/@negativespace&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Negative Space&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;br/&gt;
When creating software, you&#39;ll make mistakes. Sometimes they&#39;ll be huge, sometimes they&#39;ll be small but you can always learn from them if you spend some extra time documenting them.
&lt;p&gt;After working for more 10 years as a software engineer I&amp;rsquo;ve realized it doesn&amp;rsquo;t change. You might develop some techniques to prevent some from happening but others will show up, it never ends.&lt;/p&gt;
&lt;p&gt;In order to learn from those mistakes and try to avoid them in the future you can develop a bug log. We&amp;rsquo;ll see here what that is and how it works but I promise it helps.&lt;/p&gt;
&lt;p&gt;I recently introduced this idea at &lt;a href=&#34;https://buffer.com&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Buffer&lt;/a&gt; where I&amp;rsquo;ve been working for almost 5 years now and I thought it&amp;rsquo;d be cool to share it publicly here as well.&lt;/p&gt;
&lt;h2 id=&#34;the-endless-cycle-of-software-development&#34;&gt;The (endless) cycle of software development&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;1. Work on a new feature
2. Fix bug(s)
3. Go back to 1.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sometimes you might focus on only developing new features or only fixing bugs but those are the biggest chunks of your work if you&amp;rsquo;re building software.&lt;/p&gt;
&lt;p&gt;I think we focus a lot on the how to develop more effectively new features: using the latest framework, text editor or IDE, a new programming paradigm, etc. and when we build something new again, we try to apply the things we&amp;rsquo;ve learnt and improve.&lt;/p&gt;
&lt;p&gt;On the other hand, when we fix a bug, we tend to do it as quick as possible and then move on to something else, almost like it didn&amp;rsquo;t happen in the first place. Very few people spend any time trying to learn new debugging techniques instead of learning the latest framework that came out.&lt;/p&gt;
&lt;p&gt;If we spent more time reflecting on those errors, learning from them and understanding where they came from we could improve a lot.&lt;/p&gt;
&lt;h2 id=&#34;documenting-a-personal-mistake&#34;&gt;Documenting a personal mistake&lt;/h2&gt;
&lt;p&gt;I&amp;rsquo;ve started to document those bugs, only the ones where I was the only engineer who did it so I can totally understand the context and reflect on what I personally did.&lt;/p&gt;
&lt;p&gt;There are many different ways to do this, but I thought it&amp;rsquo;d be cool to have one place where I can gather all of them and search in the future for references and patterns. I don&amp;rsquo;t know if the term already exist but I called it the &amp;ldquo;bug log&amp;rdquo;. 🤷‍♂️ 😅&lt;/p&gt;
&lt;h2 id=&#34;whats-a-bug-log&#34;&gt;What&amp;rsquo;s a bug log?&lt;/h2&gt;
&lt;p&gt;A bug log is a collection of your past introduced bugs with different sections for each bug:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The context where the bug was introduced and what you were trying to achieve (fixing another bug, adding a new feature, etc).&lt;/li&gt;
&lt;li&gt;Why the bug happened. What was wrong in production that made you realize that there was a bug.&lt;/li&gt;
&lt;li&gt;How you fixed it.&lt;/li&gt;
&lt;li&gt;The lesson you learned afterwards. A summary of what you&amp;rsquo;ve learned in the process.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These sections are the ones that work for me, but feel free to adapt them to your needs if you want to start a bug log.&lt;/p&gt;
&lt;h2 id=&#34;an-example-of-an-entry-in-the-bug-log&#34;&gt;An example of an entry in the bug log&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-md&#34; data-lang=&#34;md&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Context
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;&lt;/span&gt;When working on this JIRA ticket &lt;span class=&#34;gs&#34;&gt;____&lt;/span&gt;, trying to track an action on the backend,
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;I merged the pull request and it failed in production in a certain environment.
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Link to ticket: ....
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Link to pull request: ....
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Why the bug happened
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;&lt;/span&gt;The environment variable was not set in one of the environments and that caused
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;an error in production.
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# How I fixed it.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;&lt;/span&gt;I created the new environment variable by doing X and Y.
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Lesson learned.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;&lt;/span&gt;When using an environment variable make sure it&amp;#39;s available in all the environments
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;before deploying.
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see it&amp;rsquo;s not anything formal and it&amp;rsquo;s just for you so feel free to use the format and tone that makes the most sense.&lt;/p&gt;
&lt;p&gt;The nice aspect about this is that if I see this becomes a pattern like if I introduced more than one bug of this type in the next year or so, I can work on a better solution. For example, a parser that compares the env. variables used in a new pull request with the ones that are in production.&lt;/p&gt;
&lt;h2 id=&#34;where-do-i-store-the-bug-log&#34;&gt;Where do I store the bug log?&lt;/h2&gt;
&lt;p&gt;I&amp;rsquo;ve become a big fan of &lt;a href=&#34;https://notion.so&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Notion&lt;/a&gt; and I&amp;rsquo;ve added it there so other team members can see it but it could be anywhere, any note-taking app or even a Github repo with some markdown files could work.&lt;/p&gt;
&lt;h2 id=&#34;what-to-do-with-the-lesson-learned-sections&#34;&gt;What to do with the &amp;ldquo;lesson learned&amp;rdquo; sections?&lt;/h2&gt;
&lt;p&gt;Something I&amp;rsquo;ve realized is that by summarizing in one sentence the bug I introduced and why I can easily reflect and learn the lesson. I&amp;rsquo;ve taken one extra step to not forget it for the future so I use &lt;a href=&#34;https://apps.ankiweb.net/&#34; target=&#34;_blank&#34;&gt;Anki&lt;/a&gt;, a solution for reviewing cards from time to time, helping you learn what&amp;rsquo;s in the card.&lt;/p&gt;
&lt;p&gt;I used it before for other purposes but I created a new collection for this. What I do is creating a card whose front is the situation I faced when I introduced the bug and the back is the lesson learned. For example, here it&amp;rsquo;d be:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Front
--------
What should I do when I use an environment variable in the code?

Back
--------
Check by doing X/Y if it&amp;#39;s set in the right environments.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here&amp;rsquo;s how it looks in Anki:&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/anki-bug-log.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/anki-bug-log.png&#34; alt=&#34;Anki Bug Log&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;Anki Bug Log&lt;/p&gt;

    
&lt;p&gt;This will reinforce my learning and it&amp;rsquo;s easier that I remember it in the future. It can also include some code samples so you associated the situation to new code that you&amp;rsquo;ll be modifying in the future.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m a big fan of &lt;a href=&#34;https://apps.ankiweb.net/&#34; target=&#34;_blank&#34;&gt;Anki&lt;/a&gt; and how it can help you improve as an engineer so I&amp;rsquo;ll write an article about it soon.&lt;/p&gt;
&lt;h1 id=&#34;repeating-past-mistakes&#34;&gt;Repeating past mistakes&lt;/h1&gt;
&lt;p&gt;The other thing I do is before filling a new entry, I can try to search in the log something similar. Sometimes that helps me understand if I tend to make the same kind of mistakes.&lt;/p&gt;
&lt;p&gt;I hope this was useful to you! Do you have any thoughts or feedback? Let me know &lt;a href=&#34;https://twitter.com/gilgado_&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;on Twitter&lt;/a&gt;! 😉&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>Introduction to Bitwise Operations</title><link>https://josem.co/introduction-to-bitwise-operations/</link>
      <pubDate>Wed, 09 Oct 2019 10:08:51 +0100</pubDate>
      
      <guid>https://josem.co/introduction-to-bitwise-operations/</guid><description type="html">&lt;p&gt;Bitwise operations are really useful and fast for storing and operate on certain values. They are way more used in systems where resources are more limited like video-games or embedded devices.&lt;/p&gt;
&lt;p&gt;In this first article about bitwise operations, we get a quick introduction to them with a drawing (new format!) and some written content but I plan on sharing more 🙂.&lt;/p&gt;
&lt;h2 id=&#34;what-are-bitwise-operations&#34;&gt;What are bitwise operations?&lt;/h2&gt;
&lt;p&gt;They&amp;rsquo;re operations that deal with bits directly. Bits are 1s and 0s and it&amp;rsquo;s how everything is stored internally in a computer so being able to operate with them directly is very efficient because the processor is able to do those operations natively. &lt;a href=&#34;https://en.wikipedia.org/wiki/Bitwise_operation&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Wikipedia says&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;hellip;typically, bitwise operations are substantially faster than division, several times faster than multiplication, and sometimes significantly faster than addition&amp;hellip;&lt;/p&gt;&lt;/blockquote&gt;
&lt;h2 id=&#34;the-three-basic-operators&#34;&gt;The three basic operators&lt;/h2&gt;
&lt;p&gt;There are more but let&amp;rsquo;s take a look today at the three most basic operators:&lt;/p&gt;
&lt;h3 id=&#34;not&#34;&gt;NOT&lt;/h3&gt;
&lt;p&gt;NOT is very simple, if there&amp;rsquo;s a 1 we get 0. If there&amp;rsquo;s a 0, we get 1.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s represented by &lt;code&gt;~&lt;/code&gt; in most programming languages so for example: &lt;code&gt;~0101011 = 1010100&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;and&#34;&gt;AND&lt;/h3&gt;
&lt;p&gt;AND is like the boolean equivalent you already use in if conditions but with one difference, this operates at the level of bits:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;or&#34;&gt;OR&lt;/h3&gt;
&lt;p&gt;The same goes for the OR operation, represented with the | symbol in many programming languages.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;how-they-operate-with-more-than-1-bit&#34;&gt;How they operate with more than 1 bit&lt;/h2&gt;
&lt;p&gt;The key here is to remember that when we have a bitwise operation with more than 1 bit, we do it bit by bit. For example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// Bitwise OR
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;111010&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mo&#34;&gt;001100&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;-------&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;111110&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or in an AND operation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// Bitwise AND
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;111010&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mo&#34;&gt;001100&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;-------&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mo&#34;&gt;001000&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;example-to-show-how-to-use-them&#34;&gt;Example to show how to use them:&lt;/h2&gt;
&lt;p&gt;&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/intro-bitwise.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/intro-bitwise.png&#34; alt=&#34;Intro to bitwise&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;Intro to bitwise&lt;/p&gt;

    

&lt;em&gt;&lt;a href=&#34;https://josem.co/images/intro-bitwise-full.png&#34;&gt;Full drawing here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;br&gt;
In a future article we&#39;ll see other operators because you can do some very efficient calculations with numbers but we need more than just these three. See you soon!</description>
      </item>
    
    <item>
      <title>Remove Empty Elements in an Array in PHP</title><link>https://josem.co/remove-empty-elements-in-an-array-in-php/</link>
      <pubDate>Tue, 01 Oct 2019 08:08:51 +0100</pubDate>
      
      <guid>https://josem.co/remove-empty-elements-in-an-array-in-php/</guid><description type="html">&lt;h1 id=&#34;problem-with-array_filter&#34;&gt;Problem with array_filter&lt;/h1&gt;
&lt;p&gt;This is a small trick to avoid issues when removing elements in PHP in an array.&lt;/p&gt;
&lt;p&gt;If you have an array where some elements might be empty, like null, the first idea that comes to mind is doing something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-php&#34; data-lang=&#34;php&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;?&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;php&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;$array&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;d&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;array_filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;empty&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Of, if we don&amp;rsquo;t provide a callback to array_filter, PHP will do the same for us:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-php&#34; data-lang=&#34;php&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;?&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;php&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;array_filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will give us a new array with all the empty elements removed. The problem though, is that the structure of the array in terms of indexes is not the expected one:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-php&#34; data-lang=&#34;php&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;?&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;php&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;$array&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;d&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;print_r&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;array_filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;));&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// Array
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// (
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;//     [0] =&amp;gt; a
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;//     [2] =&amp;gt; b
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;//     [3] =&amp;gt; c
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;//     [5] =&amp;gt; d
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// )
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So the indexes for the items that we skipped are gone. This could be ok but when we try to use that array in some situations like a query in the DB, we might find some issues.&lt;/p&gt;
&lt;p&gt;In MongoDB for example, if you&amp;rsquo;re trying to do a find with &lt;code&gt;$in&lt;/code&gt;, you&amp;rsquo;ll get an error if the array is missing some indexes.&lt;/p&gt;
&lt;h1 id=&#34;solution&#34;&gt;Solution&lt;/h1&gt;
&lt;p&gt;The easiest solution to this problem of skipped indexes is to use &lt;code&gt;array_values&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-php&#34; data-lang=&#34;php&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;?&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;php&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;$array&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;d&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;$result&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;array_values&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;array_filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;));&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;print_r&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$result&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// Array
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// (
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;//     [0] =&amp;gt; a
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;//     [1] =&amp;gt; b
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;//     [2] =&amp;gt; c
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;//     [3] =&amp;gt; d
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// )
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p class=&#34;link-code&#34;&gt;
 &lt;span class=&#34;link-code&#34;&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://repl.it/repls/SnowSurprisedHypercard&#34;&gt;(see it live)&lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;This will extract the values into a new, well indexed, array.&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>CS Basics: How to refactor a boolean expression</title><link>https://josem.co/cs-basics-how-to-refactor-a-boolean-expression/</link>
      <pubDate>Mon, 23 Sep 2019 08:08:51 +0100</pubDate>
      
      <guid>https://josem.co/cs-basics-how-to-refactor-a-boolean-expression/</guid><description type="html">&lt;p&gt;&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/auditorium-benches-chairs-207691.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/auditorium-benches-chairs-207691.jpg&#34; alt=&#34;Class&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;Class&lt;/p&gt;

    

&lt;em&gt;Photo by &lt;a href=&#34;https://www.pexels.com/@pixabay&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Pixabay&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Computer Science sounds so boring, so academic, that sometimes it&amp;rsquo;s hard to know if there&amp;rsquo;s even any useful knowledge for our jobs building actual software.&lt;/p&gt;
&lt;p&gt;Of course, I&amp;rsquo;m half joking. Computer Science is very important to understand what&amp;rsquo;s going on in a computer but I understand it doesn&amp;rsquo;t sound as attractive as learning a specific technology that&amp;rsquo;s in demand in the industry.&lt;/p&gt;
&lt;p&gt;With this series of posts, I&amp;rsquo;ll try to extract from those long boring books a few things we can start applying right away and I hope you&amp;rsquo;ll find useful.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ll always start with the immediate practical part and then I&amp;rsquo;ll explain a bit more about the underlying reasons and terminology.&lt;/p&gt;
&lt;!-- more --&gt;
&lt;p&gt;Let&amp;rsquo;s start today with some boolean expressions.&lt;/p&gt;
&lt;h1 id=&#34;why-is-it-useful-to-refactor-a-boolean-expression&#34;&gt;Why is it useful to refactor a boolean expression?&lt;/h1&gt;
&lt;p&gt;It has happened to me many times that, when refactoring a condition, I had to change it to create a method that makes sense in the class. Let&amp;rsquo;s show an simple example.&lt;/p&gt;
&lt;p&gt;Imagine we have the following class (in Javascript, but can be applied to almost any language):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kr&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;Person&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;constructor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;active&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;email&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;active&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;active&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;email&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;email&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;email&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!==&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;active&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;sendEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;false&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;// ... send email ...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;At some point we realize that it might be easier to have an internal method that can tell us if the user can receive emails. According to the code that&amp;rsquo;d mean that it&amp;rsquo;s an active user and has an email set.&lt;/p&gt;
&lt;p&gt;We could do this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;canReceiveEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// What do we return here? 🤔
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;sendEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;canReceiveEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;false&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;// ...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see the &lt;code&gt;sendEmail&lt;/code&gt; method is more readable now, &lt;strong&gt;but what should we put in the &lt;code&gt;canReceiveEmail()&lt;/code&gt; method&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ll let you think for a second&amp;hellip;🙂&lt;/p&gt;
&lt;p&gt;🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔&lt;/p&gt;
&lt;p&gt;🤔🤔🤔🤔🤔🤔🤔🤨🐶🤨🤔🤔🤔🤔🤔🤔🤔🤔&lt;/p&gt;
&lt;p&gt;🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Did you figure it out?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;What we need is the opposite value of the condition we had:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The negation of that expression would be:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I think intuitively we can understand that if what we were looking for is that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The user is not active &lt;em&gt;OR&lt;/em&gt; doesn&amp;rsquo;t have email;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The opposite would be that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The user is active &lt;em&gt;AND&lt;/em&gt; has email.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the final class would look like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kr&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;Person&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;constructor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;active&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;email&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;active&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;active&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;email&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;email&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;email&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!==&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;active&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;canReceiveEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;sendEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;canReceiveEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// Notice negation of the method with !
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;      &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;false&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;// ... send email ...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class=&#34;link-code&#34;&gt;
 &lt;span class=&#34;link-code&#34;&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://jsbin.com/lusafuv/edit?js,console&#34;&gt;(see in JSbin)&lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;We could also have created the negative version &lt;code&gt;cannotReceiveEmail()&lt;/code&gt; but I prefer to use &amp;ldquo;positive&amp;rdquo; method names since they tend to be more useful in other places of the code. Nevertheless, If we had done that the result would have been:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;cannotReceiveEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;());&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;sendEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;cannotReceiveEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;   &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;false&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;c1&#34;&gt;// ... send email ...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id=&#34;computer-science-behind-solution&#34;&gt;Computer Science behind solution&lt;/h1&gt;
&lt;p&gt;What you just saw wasn&amp;rsquo;t discovered recently, the mathematician who formulated this solution, Augustus De Morgan, died in 1871.&lt;/p&gt;
&lt;p&gt;This rule, along with another one we&amp;rsquo;ll see in a bit, are called &amp;ldquo;De Morgan&amp;rsquo;s Laws&amp;rdquo;. They&amp;rsquo;re part of a bigger field in Mathematics and studied in any computer science course, called Boolean Algebra.&lt;/p&gt;
&lt;p&gt;The other rule is as follows. If we have this expression:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kr&#34;&gt;const&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;willDieSoon&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isYoung&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;worksOut&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It&amp;rsquo;s equivalent to:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kr&#34;&gt;const&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;willDieSoon&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isYoung&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;worksOut&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you didn&amp;rsquo;t get this one, think about what would happen in all the potential conditions:&lt;/p&gt;
&lt;p&gt;Consider &lt;code&gt;isYoung&lt;/code&gt; is true/false and &lt;code&gt;worksOut&lt;/code&gt; is true/false. What would be the result of the expression? Wouldn&amp;rsquo;t that be the same that in the first case?&lt;/p&gt;
&lt;p&gt;To truly understand this, it&amp;rsquo;s often useful to create a small table of possibilities. The last column represents: &lt;code&gt;willDieSoon&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;code&gt;isYoung&lt;/code&gt;&lt;/th&gt;
          &lt;th style=&#34;text-align: left&#34;&gt;&lt;code&gt;worksOut&lt;/code&gt;&lt;/th&gt;
          &lt;th&gt;&lt;code&gt;isYoung OR worksOut&lt;/code&gt;&lt;/th&gt;
          &lt;th&gt;&lt;code&gt;!(isYoung OR worksOut)&lt;/code&gt;&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;false&lt;/td&gt;
          &lt;td style=&#34;text-align: left&#34;&gt;false&lt;/td&gt;
          &lt;td&gt;false&lt;/td&gt;
          &lt;td&gt;true&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;true&lt;/td&gt;
          &lt;td style=&#34;text-align: left&#34;&gt;false&lt;/td&gt;
          &lt;td&gt;true&lt;/td&gt;
          &lt;td&gt;false&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;false&lt;/td&gt;
          &lt;td style=&#34;text-align: left&#34;&gt;true&lt;/td&gt;
          &lt;td&gt;true&lt;/td&gt;
          &lt;td&gt;false&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;true&lt;/td&gt;
          &lt;td style=&#34;text-align: left&#34;&gt;true&lt;/td&gt;
          &lt;td&gt;true&lt;/td&gt;
          &lt;td&gt;false&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The same table can be applied to the first expression:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;code&gt;isYoung&lt;/code&gt;&lt;/th&gt;
          &lt;th style=&#34;text-align: left&#34;&gt;&lt;code&gt;worksOut&lt;/code&gt;&lt;/th&gt;
          &lt;th&gt;&lt;code&gt;!isYoung AND !worksOut&lt;/code&gt;&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;false&lt;/td&gt;
          &lt;td style=&#34;text-align: left&#34;&gt;false&lt;/td&gt;
          &lt;td&gt;true&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;true&lt;/td&gt;
          &lt;td style=&#34;text-align: left&#34;&gt;false&lt;/td&gt;
          &lt;td&gt;false&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;false&lt;/td&gt;
          &lt;td style=&#34;text-align: left&#34;&gt;true&lt;/td&gt;
          &lt;td&gt;false&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;true&lt;/td&gt;
          &lt;td style=&#34;text-align: left&#34;&gt;true&lt;/td&gt;
          &lt;td&gt;false&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;the-morgans-laws&#34;&gt;The Morgan&amp;rsquo;s Laws&lt;/h2&gt;
&lt;p&gt;So the two rules, written in a formal manner, would be:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;\( \neg (P\lor Q)\iff (\neg P)\land (\neg Q) \)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;\( \neg (P\land Q)\iff (\neg P)\lor (\neg Q) \)&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;\( \neg \)&lt;/code&gt; means negation. In Javascript and many other languages is !&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\( \land \)&lt;/code&gt; means AND. In Javascript: &amp;amp;&amp;amp;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\( \lor \)&lt;/code&gt; means OR. In Javascript: ||&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\( \iff \)&lt;/code&gt; means, without going too much into the details, that both expressions can be replaced with each other, that is, that both expressions are equivalent.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So in Javascript, we could say this is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;P&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;Q&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;P&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Q&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;P&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;Q&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;P&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Q&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;rsquo;ve used the second one to refactor our code.&lt;/p&gt;
&lt;p&gt;We started with the &lt;code&gt;!P || !Q&lt;/code&gt; and ended with &lt;code&gt;!(P &amp;amp;&amp;amp; Q)&lt;/code&gt;. Let&amp;rsquo;s review it now:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// we started with this condition to check before sending the email:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// Then, we moved the logic to canReceiveEmail()
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// And used the negation of that:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;canReceiveEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// Which is:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isActive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;this&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hasEmail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;());&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// So:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;P&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Q&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;P&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;other-boolean-algebra-laws&#34;&gt;Other Boolean Algebra Laws&lt;/h2&gt;
&lt;p&gt;If you didn&amp;rsquo;t know about this boolean algebra laws specifically, don&amp;rsquo;t worry! You&amp;rsquo;re probably applying others like:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;\( x \lor y = y \lor x \)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;\( x \land y = y \land x \)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Those mean that:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;weAreInChrome&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;weAreInFirefox&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;===&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;weAreInFirefox&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;weAreInChrome&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isRaining&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;isCloudy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;===&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;isCloudy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;isRaining&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So, intuitively perhaps, you know that the boolean conditions with two values can be switched in order and the result is the same (🤓🗯️ &lt;em&gt;that&amp;rsquo;s commutativity!&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;There are &lt;a href=&#34;https://en.wikipedia.org/wiki/Boolean_algebra#Laws&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;many others boolean laws&lt;/a&gt; that are useful so I might do a second part of boolean logic later in the series with the ones that are not so intuitive.&lt;/p&gt;
&lt;p&gt;Did you find this one useful? Let me know &lt;a href=&#34;https://twitter.com/gilgado_&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;on Twitter&lt;/a&gt; please! 👋 🙂&lt;/p&gt;
&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Boolean_algebra&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Boolean Algebra&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/De_Morgan%27s_laws&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;De Morgan&amp;rsquo;s laws&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
      </item>
    
    <item>
      <title>Better Console Debug in Javascript</title><link>https://josem.co/better-console-debug-in-javascript/</link>
      <pubDate>Sun, 15 Sep 2019 22:56:23 -0700</pubDate>
      
      <guid>https://josem.co/better-console-debug-in-javascript/</guid><description type="html">&lt;p&gt;When debugging an object in Javascript, you usually do something like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;log&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;myObject&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or even:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;debug&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;myObject&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If we create the object with:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;myObject&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nx&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;test&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nx&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1234&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And you do a console.debug from somewhere in the code, in the console you&amp;rsquo;ll see:&lt;/p&gt;

&lt;p style=&#34;text-align:center&#34;&gt;&lt;img alt=&#34;&#34; src=&#34;https://josem.co/images/better-console-debug-js.png&#34; class=&#34;alignnone&#34; width=&#34;720&#34; /&gt;&lt;/p&gt;

&lt;p&gt;So it might not be clear which object you&amp;rsquo;re dealing with. To solve this you can do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;debug&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;myObject&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The result is the name of the object and the full object printed:&lt;/p&gt;

&lt;p style=&#34;text-align:center&#34;&gt;&lt;img alt=&#34;&#34; src=&#34;https://josem.co/images/better-console-debug-js-2.png&#34; class=&#34;alignnone&#34; width=&#34;720&#34; /&gt;&lt;/p&gt;

&lt;p&gt;This comes from ES6, it&amp;rsquo;s usually called &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Property_definitions&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;shorthand property names&lt;/a&gt; and it works because the key and the object variable has the same name.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s the same thing that saying:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;debug&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;myObject&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;myObject&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But more convenient as you can see. 😉&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Useful Utilities in Unix for Developers</title><link>https://josem.co/useful-utilities-in-unix-for-developers/</link>
      <pubDate>Fri, 13 Jun 2014 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/useful-utilities-in-unix-for-developers/</guid><description type="html">&lt;p&gt;After some years working as a software developer in different companies I have used many programs and utilities in *nix environments that I&amp;rsquo;d like to share.&lt;/p&gt;
&lt;p&gt;This is not an exhaustive tutorial about how to get the most of them, many options will be just ignored and I will list only how I use them on a daily basis.&lt;/p&gt;
&lt;h2 id=&#34;text-processing&#34;&gt;Text processing&lt;/h2&gt;
&lt;p&gt;I use these utilities to get info from a log or to quickly change a config file on a server.&lt;/p&gt;
&lt;h3 id=&#34;tail&#34;&gt;tail&lt;/h3&gt;
&lt;p&gt;It prints the last part of a file, it accepts some parameters like -f which will print the last part of a file and waits to print what it&amp;rsquo;s appended to the file (useful to see live logs).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ tail -f logs/log.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or if you want just the last n lines you can do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ tail -n &lt;span class=&#34;m&#34;&gt;200&lt;/span&gt; logs/log.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further reading: &lt;a href=&#34;http://man7.org/linux/man-pages/man1/tail.1.html&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;grep&#34;&gt;grep&lt;/h3&gt;
&lt;p&gt;The grep command searches a file, the standard input or multiple files for a pattern and prints the lines that match that pattern. As a pattern you can use a string or a regular expression, here are some examples.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ grep error logs/log.txt &lt;span class=&#34;c1&#34;&gt;# searchs error in log&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The same result using the standard input with a pipe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ cat logs/log.txt &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep error &lt;span class=&#34;c1&#34;&gt;# searchs error in log&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want to search only for the whole word, not including parts of it in the results you can with -w:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ grep -w &lt;span class=&#34;s2&#34;&gt;&amp;#34;error&amp;#34;&lt;/span&gt; logs/log.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In order to find a text in a tree of files you can use -r:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ grep -r &lt;span class=&#34;s2&#34;&gt;&amp;#34;error&amp;#34;&lt;/span&gt; logs
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want to show the number of lines that match that pattern:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ grep -c &lt;span class=&#34;s2&#34;&gt;&amp;#34;error&amp;#34;&lt;/span&gt; logs/log.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further reading: &lt;a href=&#34;http://www.gnu.org/software/grep/manual/grep.html&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;diff&#34;&gt;diff&lt;/h3&gt;
&lt;p&gt;Compares two files, I tend to use it without options.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ diff file1.txt file2.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further reading: &lt;a href=&#34;http://unixhelp.ed.ac.uk/CGI/man-cgi?diff&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;vi&#34;&gt;vi&lt;/h3&gt;
&lt;p&gt;Well I could say many things about this editor. In my computer I use Vim on a daily basis but in many servers this is not installed by default where vi is so I use the later for small edits in config files.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ vi nginx.conf
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;network&#34;&gt;Network&lt;/h2&gt;
&lt;h3 id=&#34;curl&#34;&gt;curl&lt;/h3&gt;
&lt;p&gt;Allows you to transfer data with many protocols (HTTP, FTP&amp;hellip;etc). I tend to use it to download something from the Internet.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ curl http://example.com/file.zip
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can also use patterns like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ curl http://example.com/&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;2000-2014&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;/part&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;a,b,c&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;.zip
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further reading: &lt;a href=&#34;http://curl.haxx.se/docs/manpage.html&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;scp&#34;&gt;scp&lt;/h3&gt;
&lt;p&gt;It&amp;rsquo;s like the combination of SSH and cp (altough it actually stands for secure copy), basically you can copy files through the SSH protocol, a simple example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ scp user@1.1.1.1:/files/1.txt .
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It also works the other way around:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ scp 1.txt user@1.1.1.1:/files/
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further reading: &lt;a href=&#34;http://linux.die.net/man/1/scp&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;rsync&#34;&gt;rsync&lt;/h3&gt;
&lt;p&gt;Rsync it&amp;rsquo;s a very complete tool but I tend to use like a simple &amp;ldquo;Dropbox&amp;rdquo; for certain directories.&lt;/p&gt;
&lt;p&gt;Totally worth it to read the whole man page: &lt;a href=&#34;http://ss64.com/bash/rsync.html&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;http://ss64.com/bash/rsync.html&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;management&#34;&gt;Management&lt;/h2&gt;
&lt;h3 id=&#34;htop&#34;&gt;htop&lt;/h3&gt;
&lt;p&gt;An interactive process viewer, it&amp;rsquo;s like an improved top. You just need to execute htop and it will start. It isn&amp;rsquo;t installed by default in many distributions but it&amp;rsquo;s a common package. If you can&amp;rsquo;t install it you can use top, which is very similar.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/htop.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/htop.png&#34; alt=&#34;Screenshot of htop&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;720&#34;  /&gt;&lt;/picture&gt;Screenshot of htop&lt;/p&gt;

    
&lt;p&gt;Further reading: &lt;a href=&#34;http://linux.die.net/man/1/htop&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;iostat&#34;&gt;iostat&lt;/h3&gt;
&lt;p&gt;Useful to monitor devices. It comes in handy when you don&amp;rsquo;t know what&amp;rsquo;s happening with a certain disk.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/iostat.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/iostat.png&#34; alt=&#34;Screenshot of iostat on a Mac&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;288&#34;  /&gt;&lt;/picture&gt;Screenshot of iostat on a Mac&lt;/p&gt;

    
&lt;p&gt;Further reading: &lt;a href=&#34;http://linux.die.net/man/1/iostat&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;##Directories &amp;amp; Files&lt;/p&gt;
&lt;p&gt;A lot in Unix systems has to do with files in some OS like Plan9 you can even treat a network interface as a file. These utilities are very basic but I could not leave them out.&lt;/p&gt;
&lt;h3 id=&#34;mv--cd--cp--ls&#34;&gt;mv / cd / cp / ls&lt;/h3&gt;
&lt;p&gt;Very basic utilities to move files or directories, change current directory, copy files or directories and list the content of a certain directory respectively.&lt;/p&gt;
&lt;h3 id=&#34;pwd&#34;&gt;pwd&lt;/h3&gt;
&lt;p&gt;Response to the question: where am I?&lt;/p&gt;
&lt;h3 id=&#34;rm&#34;&gt;rm&lt;/h3&gt;
&lt;p&gt;Remove a file or tree of directories (with -r option).&lt;/p&gt;
&lt;h3 id=&#34;ln&#34;&gt;ln&lt;/h3&gt;
&lt;p&gt;Link between two files or directories.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ ln -f origin new_link
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further reading: &lt;a href=&#34;https://www.mkssoftware.com/docs/man1/ln.1.asp&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;find&#34;&gt;find&lt;/h3&gt;
&lt;p&gt;I use it to find a file by name on a server:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ find / -name foo
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further reading: &lt;a href=&#34;http://unixhelp.ed.ac.uk/CGI/man-cgi?find&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Manual Page&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;best-utility-man&#34;&gt;Best utility: man&lt;/h2&gt;
&lt;p&gt;I remember that in my first class of OSs the teacher taught us the man utility. With man you can find everything you need, &lt;a href=&#34;http://linux.die.net/man/1/man&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;here&lt;/a&gt; you can see how to use it.&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>&#34;Class Methods&#34; in Scala</title><link>https://josem.co/class-methods-in-scala/</link>
      <pubDate>Mon, 15 Jul 2013 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/class-methods-in-scala/</guid><description type="html">&lt;p&gt;In Scala you can&amp;rsquo;t declare class methods, all the methods defined in a class belong to the object.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;House&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;street&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;String&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;clean&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Cleaning!&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;h&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;new&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;House&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;5th&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;h&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;clean&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Cleaning&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If we want a class method so we can do something like House.cleanAll we have to declare a &lt;strong&gt;companion object&lt;/strong&gt;, which is basically an object with the same name of a previously defined Class:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;object&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;House&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;cleanAll&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Cleaning all!&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nc&#34;&gt;House&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cleanAll&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And now we have the methods of the objects defined in the class and the &amp;ldquo;class methods&amp;rdquo; defined in the companion object, kind of tricky but this is how it works in Scala.&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Switch in Scala (Pattern Matching)</title><link>https://josem.co/switch-in-scala-pattern-matching/</link>
      <pubDate>Wed, 10 Jul 2013 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/switch-in-scala-pattern-matching/</guid><description type="html">&lt;p&gt;Scala has a powerful pattern matching mechanism, that we can think of a kind of &amp;ldquo;switch&amp;rdquo; if we come from another programming language, but it&amp;rsquo;s much more powerful and I&amp;rsquo;d love to explore some of its options here. A simple switch in Scala would look like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;match&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;One&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Two&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;_&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Whatever&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this case we have cases with 1 and 2, and if something else is matched then we return &amp;ldquo;Whatever&amp;rdquo;. But this is really simple, let&amp;rsquo;s make it more complex matching with types too.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;match&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Integer!&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;String&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;String: &amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;_&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Whatever&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The above piece of code would look like this in Java:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;instanceOf&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Integer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Integer!&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;instanceOf&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;String&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;String: &amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Whatever&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now if &lt;b&gt;a&lt;/b&gt; is a string we return &amp;ldquo;String&amp;rdquo;, if it&amp;rsquo;s an integer we return &amp;ldquo;Integer!&amp;rdquo; and if it&amp;rsquo;s something else we return &amp;ldquo;Whatever&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;We can also match against case classes. Imagine we have a case class with an integer and a string called Element.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;kd&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;Element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;String&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In that case we can make a more complete match:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;Element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;85&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Fruit&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;match&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;_&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Fruit&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Fruit is coming&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;80&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;_&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;80 kg!&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;80&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Fruit&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;80 kg of Fruit&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;_&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Whatever&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Apart from all the options described here we can add a boolean before the &lt;i&gt;=&amp;gt;&lt;/i&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;Element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;85&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Fruit&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;match&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Fruit&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;50&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;More than 50kg of fruit&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Element&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;80&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;_&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;80 kg!&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;case&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;_&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Whatever&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The nice thing about pattern matching is that you can use exactly the same structures in closures or catch blocks.&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>SBT in Scala Compile when You Save a File</title><link>https://josem.co/sbt-in-scala-compile-when-you-save-a-file/</link>
      <pubDate>Mon, 08 Jul 2013 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/sbt-in-scala-compile-when-you-save-a-file/</guid><description type="html">&lt;p&gt;I&amp;rsquo;ve worked on some Scala projects recently using &lt;a href=&#34;http://www.scala-sbt.org/&#34;&gt;SBT (Scala Building Tool)&lt;/a&gt; and every time I had a change in a file I needed to go to SBT and type compile until I found a simple instruction to keep it compiling for me. Just execute SBT and run the following command:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;~ compile&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now every time you save a file it will be compiled automatically. In the &lt;a href=&#34;http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Triggered-Execution.html&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;official documentation&lt;/a&gt; you can see more details.&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>Set Content Type in RSpec</title><link>https://josem.co/set-content-type-in-rspec/</link>
      <pubDate>Tue, 11 Jun 2013 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/set-content-type-in-rspec/</guid><description type="html">&lt;p&gt;The last week I had a spec with a request where I needed to specify the content type and Google sensei didn&amp;rsquo;t help me.&lt;/p&gt;
&lt;p&gt;It took me an hour until I finally found it, so let me show here briefly how to do it just in case I have to find it again.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;it&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;sets the content type&amp;#39;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;post&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;http://example.com&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;kp&#34;&gt;nil&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;CONTENT_TYPE&amp;#39;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;application/json&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;expect&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;request&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;content_type&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eq&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;application/json&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The fact that the content type must be set with an underscore is counterintuitive since the &lt;a href=&#34;http://www.ietf.org/rfc/rfc2616.txt&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;RFC says otherwise&lt;/a&gt;.&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Bruno: Localizable.strings to strings.xml (iOS - Android)</title><link>https://josem.co/bruno-localizable.strings-to-strings.xml-ios-android/</link>
      <pubDate>Sun, 19 May 2013 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/bruno-localizable.strings-to-strings.xml-ios-android/</guid><description type="html">&lt;p&gt;I&amp;rsquo;ve created a small gem, Bruno, to convert a Localizable.strings (iOS) file to a strings XML file (Android) and vice-versa.&lt;/p&gt;
&lt;p&gt;To install it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ gem install bruno&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A Localizable.strings file in an iOS project looks like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;APP_NAME&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Test App&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;TITLE_ACTIVITY_MAIN&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Test&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;INFO_TITLE&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Information&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;INFO_SUBTITLE&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;More information&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And with a single command:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ bruno convert --in Localizable.strings --out strings.xml&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You will get this file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-xml&#34; data-lang=&#34;xml&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;cp&#34;&gt;&amp;lt;?xml version=&amp;#34;1.0&amp;#34; encoding=&amp;#34;UTF-8&amp;#34;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nt&#34;&gt;&amp;lt;resources&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nt&#34;&gt;&amp;lt;string&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;name=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;APP_NAME&amp;#34;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;&amp;gt;&lt;/span&gt;Test App&lt;span class=&#34;nt&#34;&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nt&#34;&gt;&amp;lt;string&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;name=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;TITLE_ACTIVITY_MAIN&amp;#34;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;&amp;gt;&lt;/span&gt;;Test&lt;span class=&#34;nt&#34;&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nt&#34;&gt;&amp;lt;string&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;name=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;INFO_TITLE&amp;#34;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;&amp;gt;&lt;/span&gt;;Information&lt;span class=&#34;nt&#34;&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nt&#34;&gt;&amp;lt;string&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;name=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;INFO_SUBTITLE&amp;#34;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;&amp;gt;&lt;/span&gt;;More information&lt;span class=&#34;nt&#34;&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nt&#34;&gt;&amp;lt;/resources&amp;gt;&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can use a strings XML file from Android to convert it to iOS too:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ bruno convert --in strings.xml --out Localizable.strings&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can find the Git repository here: &lt;a href=&#34;https://github.com/josem/bruno&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;https://github.com/josem/bruno&lt;/a&gt; with further instructions.&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Dynamic Conditions for Associations in Rails 3</title><link>https://josem.co/dynamic-conditions-for-associations-in-rails-3/</link>
      <pubDate>Wed, 06 Feb 2013 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/dynamic-conditions-for-associations-in-rails-3/</guid><description type="html">&lt;p&gt;If you are using dynamic conditions in Rails 3, like Time.now or 1.week.ago you should use a Proc for that condition.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s an example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;has_many&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;:rented_cars&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;...&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;         &lt;span class=&#34;ss&#34;&gt;:conditions&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;proc&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#39;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;#{&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;Date&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;today&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to_s&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;ss&#34;&gt;:db&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#39; &amp;lt;= end_rent_date&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This way, Date.today will be called every time you perform a query.&lt;/p&gt;
&lt;p&gt;If you would have done it like in the following example, there will be cases when the results you&amp;rsquo;ll get are not expected since the condition will have the day you started the Rails application and Date.today won&amp;rsquo;t be called again.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;has_many&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;:rented_cars&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;...&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;         &lt;span class=&#34;ss&#34;&gt;:conditions&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#39;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;#{&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;Date&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;today&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to_s&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;ss&#34;&gt;:db&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#39; &amp;lt;= end_rent_date&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;(&lt;a href=&#34;http://www.ruby-doc.org/core-1.9.3/Proc.html&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Link to Proc docs in Ruby&lt;/a&gt;).&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Rescue from MultiJson::DecodeError in Ruby on Rails</title><link>https://josem.co/rescue-from-multijsondecodeerror-in-ruby-on-rails/</link>
      <pubDate>Thu, 17 Jan 2013 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/rescue-from-multijsondecodeerror-in-ruby-on-rails/</guid><description type="html">&lt;p&gt;If you are developing an API with Rails you need to rescue from the errors produced by a bad formatted JSON. In order to do that I use a middleware file placed in app/middleware named ParamsParserRescue.rb.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;ParamsParserRescue&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;ActionDispatch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;ParamsParser&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;call&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;env&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;begin&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;super&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;env&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;rescue&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;MultiJson&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;DecodeError&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;400&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{},&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Bad Request&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;]]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And with this middleware file you need to tell Rails that should use it. In the configuration file &lt;strong&gt;application.rb&lt;/strong&gt; add:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;config&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;middleware&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;swap&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;ActionDispatch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;ParamsParser&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;ParamsParserRescue&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Basically, we are doing whatever the call method does in ActionDispatch::ParamsParser and if the MultiJson::DecodeError exception is raised then we return a 400 HTTP Code instead of crashing.&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Programming Challenges</title><link>https://josem.co/programming-challenges/</link>
      <pubDate>Tue, 08 Jan 2013 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/programming-challenges/</guid><description type="html">&lt;p&gt;I&amp;rsquo;d like to share some sites with programming challenges, also known as programming puzzles. I find them very useful to learn a new language, much more than reading a lot of books. Actually, I usually read one book for beginners of the language and after that I go to one of the following sites and start to code. My favourite is /r/dailyprogrammer.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://www.reddit.com/r/dailyprogrammer/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;/r/DailyProgrammer&lt;/a&gt;. Subreddit with three challenges every week or so (easy, intermediate and hard).&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://projecteuler.net/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Project Euler&lt;/a&gt;. Math problems, created to be solved with a program.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://codeforces.com/problemset&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Code Forces&lt;/a&gt;. More problems!&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://codegolf.stackexchange.com/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Code Golf&lt;/a&gt;. Part of the Stack Exchange platform. Very focus on the number of lines, but that makes it more fun.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://codingbat.com/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Coding Bat&lt;/a&gt;. Most of the problems here are easy, and some of them include the solutions.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.reddit.com/r/programmingchallenges&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;/r/ProgrammingChallenges&lt;/a&gt;. Another subreddit, less organized.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.billthelizard.com/2009/06/programming-and-logic-puzzles.html&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Extra: a post with more links to challenges&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>Creating a Great RESTful API</title><link>https://josem.co/creating-a-great-restful-api/</link>
      <pubDate>Wed, 26 Dec 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/creating-a-great-restful-api/</guid><description type="html">&lt;p&gt;REST is a style of software architecture, often used in web. The design of Rails, for instance, is based a lot on REST. The idea behind this architecture is to have very similar interfaces to access all the resources in your system.&lt;/p&gt;
&lt;p&gt;Recently I had to create 2 APIs in 3 months so I had to learn all I could in a very short time. I&amp;rsquo;d like to share some conclusions but giving the fact that to develop an API people usually say you need 10 years of experience take them with caution.&lt;/p&gt;
&lt;h2 id=&#34;use-versions&#34;&gt;Use versions&lt;/h2&gt;
&lt;p&gt;People will trust your API so if you change something in the architecture of your application the 3rd party clients shouldn&amp;rsquo;t be affected by that.&lt;/p&gt;
&lt;p&gt;The common approach here is to add a parameter to your URL, something like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;http://myapp.com/api/v1/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;http://myapp.com/api/1/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I personally prefer the first method since is more clear, Google uses that too.&lt;/p&gt;
&lt;h2 id=&#34;use-proper-http-methods&#34;&gt;Use proper HTTP methods&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;GET: To get a resource or resources of one type.&lt;/li&gt;
&lt;li&gt;POST: To create a new resource if you don&amp;rsquo;t know where it&amp;rsquo;s going to be.&lt;/li&gt;
&lt;li&gt;PUT: To update a resource&lt;/li&gt;
&lt;li&gt;DELETE: To remove a resource.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;consistent-structure-of-urls&#34;&gt;Consistent structure of URLs&lt;/h2&gt;
&lt;p&gt;If you don&amp;rsquo;t have a very simple system, probably you&amp;rsquo;ll end up with a lot of URLs so it&amp;rsquo;s important to respect a pattern, I used this one:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GET &lt;a href=&#34;http://example.com/api/cars&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;http://example.com/api/cars&lt;/a&gt;. To get a list of the resources of one type (cars, for example).&lt;/li&gt;
&lt;li&gt;GET &lt;a href=&#34;http://example.com/api/cars/1&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;http://example.com/api/cars/1&lt;/a&gt;. To get a resource with the id 2.&lt;/li&gt;
&lt;li&gt;POST &lt;a href=&#34;http://example.com/api/cars&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;http://example.com/api/cars&lt;/a&gt;. To create a new resource.&lt;/li&gt;
&lt;li&gt;PUT &lt;a href=&#34;http://example.com/api/cars/1&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;http://example.com/api/cars/1&lt;/a&gt;. To update the resource with id 1.&lt;/li&gt;
&lt;li&gt;DELETE &lt;a href=&#34;http://example.com/api/cars/1&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;http://example.com/api/cars/1&lt;/a&gt;. To remove the resource with id 1.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;security&#34;&gt;Security&lt;/h2&gt;
&lt;p&gt;I haven&amp;rsquo;t used the best avaliable method: OAuth. In my case with a token parameter and SSL was enough, but in your case it might not be.&lt;/p&gt;
&lt;h2 id=&#34;show-examples&#34;&gt;Show examples&lt;/h2&gt;
&lt;p&gt;There will be a lot of users with a lot of different systems so it would be great if you can provide copy&amp;amp;paste examples. Probably curl will be enough for everyone.&lt;/p&gt;
&lt;h2 id=&#34;follow-the-leaders&#34;&gt;Follow the leaders&lt;/h2&gt;
&lt;p&gt;Also known as Twitter, Google and Facebook engineers are probably smarter than you. To create my APIs I have &lt;del&gt;copied&lt;/del&gt; studied the following APIs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developers.google.com/&amp;#43;/api/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Google Plus API&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dev.twitter.com/docs/api&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;The Twitter REST API&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developers.facebook.com/docs/reference/rest/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Facebook REST API (deprecated but still good for this purpose)&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://parse.com/docs/rest&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Parse REST API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;some-references-i-used-to-learn&#34;&gt;Some References I used to learn&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://marakana.com/s/post/1221/designing_a_beautiful_rest_json_api_video&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Designing a beautiful REST JSON API&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://restful-api-design.readthedocs.org/en/latest/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Thoughts on RESTful API Design&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://blog.apigee.com/detail/slides_for_restful_api_design_second_edition_webinar/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;RESTful API Design: Second Edition&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;</description>
      </item>
    
    <item>
      <title>Subversion and Files With @</title><link>https://josem.co/subversion-and-files-with-@/</link>
      <pubDate>Fri, 07 Dec 2012 07:30:40 +0100</pubDate>
      
      <guid>https://josem.co/subversion-and-files-with-@/</guid><description type="html">&lt;p&gt;If you have worked with Subversion and iOS you are probably aware of this problem. Whenever you are going to do something with a file that has an at sign in its name you can&amp;rsquo;t. For instance imagine you&amp;rsquo;ve just added a file for retina and try to add it to the repository (XCode can do this too):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ svn add logo@2x.png&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The message from Subversion will be:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Skipped logo@2x.png&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s because Subversion uses the @ for other purposes.&lt;/p&gt;
&lt;p&gt;From &lt;a href=&#34;http://svnbook.red-bean.com/nightly/en/svn.advanced.pegrevs.html&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;the Subversion book&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;hellip;how does svn know whether news@11 is the name of a directory in my tree or just a syntax for “revision 11 of news”? Thankfully, while svn will always assume the latter, there is a trivial workaround&amp;hellip;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The workaround is as simple as adding an at sign to the end of the path:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ svn add logo@2x.png@&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</description>
      </item>
    
    <item>
      <title>Learning Vim - Introduction</title><link>https://josem.co/learning-vim-introduction/</link>
      <pubDate>Tue, 20 Nov 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/learning-vim-introduction/</guid><description type="html">&lt;p&gt;I&amp;rsquo;ve started the great journal of learning Vim. I&amp;rsquo;ve heard a lot of good things about this editor and I&amp;rsquo;d like to learn how to use it effectively and share here all the things I&amp;rsquo;ll learn and my thoughts about every step of the way.&lt;/p&gt;
&lt;p&gt;As a novice I&amp;rsquo;ll make a lot of mistakes but I&amp;rsquo;ll try to search all the commands and tips to make sure they will be accurate enough to be shared.&lt;/p&gt;
&lt;h2 id=&#34;learning-curve&#34;&gt;Learning Curve&lt;/h2&gt;
&lt;p&gt;It&amp;rsquo;s probable you&amp;rsquo;ve heard that Vim is hard, that, in order to generate a random string you just need to put a student in front of this editor and tell him to close it. Here you can see a slide with the learning curve of different editors:&lt;/p&gt;
&lt;p&gt;&lt;p&gt;&lt;picture&gt;&lt;source srcset=&#34;https://josem.co/images/editor-learning-curve.webp&#34; type=&#34;image/webp&#34;&gt;&lt;img src=&#34;https://josem.co//images/editor-learning-curve.png&#34; alt=&#34;Learning curves of different editors&#34; decoding=&#34;async&#34; class=&#34;lazyload&#34; data-sizes=&#34;auto&#34; loading=&#34;lazy&#34;
          width=&#34;600&#34;  /&gt;&lt;/picture&gt;&lt;/p&gt;

    

&lt;em&gt;Learning curves of different editors&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Yes, Vim is scary right? But the truth is you can use Vim almost as any other editor until you learn the most basic commands and concepts that will make a good vim user. If you&amp;rsquo;ve using Vim for 20 years and you see me using vim the first weeks doing things like grabbing the mouse or using the arrow keys you could be surprised but the truth is &lt;b&gt;you don&amp;rsquo;t need to use the most efficient way to do things all the time&lt;/b&gt;.&lt;/p&gt;
&lt;h2 id=&#34;resources&#34;&gt;Resources&lt;/h2&gt;
&lt;p&gt;One of the main reasons so many people use Vim is its great community, which means a lot of good resources to learn too. In my case I&amp;rsquo;ll be following the &lt;a href=&#34;http://derekwyatt.org/vim/tutorials/&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;great videos of Derek Wyatt&lt;/a&gt; and of course my dear friend Google.&lt;/p&gt;
&lt;p&gt;I am looking forward to sharing all the things I&amp;rsquo;ll learn, stay tuned!&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>Naming of Predicate Methods</title><link>https://josem.co/naming-of-predicate-methods/</link>
      <pubDate>Wed, 07 Nov 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/naming-of-predicate-methods/</guid><description type="html">&lt;p&gt;A predicate method is tipically one that should return a boolean value (true or false). These methods are useful in a lot of scenarios, like when you have an class with a boolean attribute.&lt;/p&gt;
&lt;p&gt;Naming these kind of methods depends on the language you are using, but here are my top priorities.&lt;/p&gt;
&lt;h3 id=&#34;question-mark&#34;&gt;Question mark&lt;/h3&gt;
&lt;p&gt;If you are using Ruby you can name it with a question mark at the end, which makes the code really readable. Something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;is_alive?&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;vi&#34;&gt;@alive&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&#34;question-style&#34;&gt;Question style&lt;/h3&gt;
&lt;p&gt;In some languages you can&amp;rsquo;t use a question mark in the name of a method, so I usually name it like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Boolean&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;isAlive&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&#34;simple-getter&#34;&gt;Simple Getter&lt;/h3&gt;
&lt;p&gt;The worst name here, in my opinion, is having a get, like any other getter. It&amp;rsquo;s much better to have something like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;zombie&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;isAlive?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Rather than:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;zombie&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;getAlive&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Naming is so debatable that it would be silly to think more about this problem. I think with experience you can see the pros and cons of every option, I could even change my mind in some months about this :)&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Too Short Routines?</title><link>https://josem.co/too-short-routines/</link>
      <pubDate>Wed, 03 Oct 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/too-short-routines/</guid><description type="html">&lt;p&gt;I think as developers we tend to create complexity if we don&amp;rsquo;t think carefully about every line of code we are typing. Systems tend to be complex and managing that complexity is one of the main task we have.&lt;/p&gt;
&lt;p&gt;Routines are great, they are one of the best ways to encapsulate algorithms and make your code more readable. Sometimes we think routines are too short, but actually the usually are too long. Reading &lt;a href=&#34;http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Clean Code&lt;/a&gt; I realized Uncle Bob creates very short routines and all of them have a meaningful name.&lt;/p&gt;
&lt;h2 id=&#34;correlation-between-length-of-a-routine-and-its-name&#34;&gt;Correlation between length of a routine and its name&lt;/h2&gt;
&lt;p&gt;Usually the longer a routine is the harder is to name it. When you do something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;length&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;++&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nf&#34;&gt;show&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It&amp;rsquo;s very easy to come up with a name like &lt;em&gt;showAllElements(array)&lt;/em&gt;. But if you are processing a lot of input parameters (like in a web service) and cleaning the input a good name will be harder to find.&lt;/p&gt;
&lt;p&gt;Apart from that with small routines you&amp;rsquo;ll find your bugs easier and the reuse of that little algorithm is more likable since it&amp;rsquo;s already encapsulated and ready to be used again.&lt;/p&gt;
&lt;p&gt;In the book &lt;a href=&#34;http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;Code Complete&lt;/a&gt; a lot of studies are shown without a clear conclusion but when the author is listing all the valid reasons to create a routine you get the idea that most small routines can achieve that. These are some of them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Reduce complexity&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make a section of code readable&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Improve portability&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Simplify complicated boolean tests&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;exceptions&#34;&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;Steve Mcconnell says in Code Complete that &lt;em&gt;to ensure all routines are small&lt;/em&gt; is not a valid reason to create a routine:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In fact, some jobs are performed better in a single large routine.&lt;/p&gt;&lt;/blockquote&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In my experience, most of the time you can improve the readability of your code by creating smaller routines. To finish let me show you the following piece of code used by Steve to illustrate how using short routines can improve readability:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;node&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NULL&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;then&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;while&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;node&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;na&#34;&gt;next&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NULL&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;node&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;node&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;na&#34;&gt;next&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;leafName&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;node&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;na&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;end&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;while&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;else&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;leafName&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;end&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;He points out that this code should be encapsulated in a routine like &lt;em&gt;GetLeafName(node)&lt;/em&gt;.&lt;/p&gt;
</description>
      </item>
    
    <item>
      <title>An Important Lesson from Objective-C</title><link>https://josem.co/an-important-lesson-from-objective-c/</link>
      <pubDate>Fri, 21 Sep 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/an-important-lesson-from-objective-c/</guid><description type="html">&lt;p&gt;I&amp;rsquo;ve started to develop applications for iOS about 3 months ago and there were a lot of things new for me in that environment (there are a lot yet) and Objective-C wasn&amp;rsquo;t an exception.&lt;/p&gt;
&lt;p&gt;The syntax of this programming language is scary the first time you see it but with time you get used to it and you can get a lot of good practices too.&lt;/p&gt;
&lt;p&gt;One of the most important things I&amp;rsquo;ve learnt is that the more self-explanatory a method is, the better. It doesn&amp;rsquo;t matter how long it is. Actually this is something you can apply to other languages. Let me show you a quick example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-objc&#34; data-lang=&#34;objc&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cleanAllInputValuesAfterValidation&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;values&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;){}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sortDirectoriesAlphabetically&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;directories&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;){}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In fact, in Objective-C you can pass parameters in the middle of the method&amp;rsquo;s name, which teaches you a couple of things about naming. You can see DHH&amp;rsquo;s thoughts (the creator of the framework Ruby on Rails) about this &lt;a href=&#34;http://37signals.com/svn/posts/3250-clarity-over-brevity-in-variable-and-method-names&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Subversion: Remove All the Deleted Files from a Repository</title><link>https://josem.co/subversion-remove-all-the-deleted-files-from-a-repository/</link>
      <pubDate>Tue, 04 Sep 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/subversion-remove-all-the-deleted-files-from-a-repository/</guid><description type="html">&lt;p&gt;In order to remove all the files from the repository after they have been deleted from disk you have a couple of options.&lt;/p&gt;
&lt;p&gt;Using Sed:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;svn st &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep &lt;span class=&#34;s1&#34;&gt;&amp;#39;^!&amp;#39;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; sed &lt;span class=&#34;s1&#34;&gt;&amp;#39;s/! *//&amp;#39;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; xargs -I% svn rm %&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or with AWK:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;svn st &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep &lt;span class=&#34;s1&#34;&gt;&amp;#39;^!&amp;#39;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;{print $2}&amp;#39;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; xargs -I% svn rm %&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you don&amp;rsquo;t trust these commands (you shouldn&amp;rsquo;t but nowadays we don&amp;rsquo;t have enough time right?) you can see the list of files that will be removed from the repository without the xargs part:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;svn st &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep &lt;span class=&#34;s1&#34;&gt;&amp;#39;^!&amp;#39;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; sed &lt;span class=&#34;s1&#34;&gt;&amp;#39;s/! *//&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;svn st &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep &lt;span class=&#34;s1&#34;&gt;&amp;#39;^!&amp;#39;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;{print $2}&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I think AWK is more elegant in this case since it seems more obvious to me to print the second column than removing the &amp;ldquo;!&amp;rdquo; part, but that&amp;rsquo;s just my opinion.&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Return at the Beginning of Functions</title><link>https://josem.co/return-at-the-beginning-of-functions/</link>
      <pubDate>Fri, 24 Aug 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/return-at-the-beginning-of-functions/</guid><description type="html">&lt;p&gt;I had a little doubt about when to do the return if you have a big if, something like the following function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;animateElements&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;o&#34;&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pool&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;allAnimationsCompleted&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;doAnimation1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;doAnimation2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;doOtherOperations&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In that case all the function is inside of an if, so the following implementation would do the same:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;animateElements&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;o&#34;&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pool&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;allAnimationsCompleted&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;doAnimation1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;doAnimation2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;doOtherOperations&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I was totally sure that this was better, because the function is cleaner but recently, after doing some memory management on my own and forgetting some releases I&amp;rsquo;m not that sure. Let me expose the pros and cons and and a more complex example:&lt;/p&gt;
&lt;h2 id=&#34;pros&#34;&gt;Pros&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Less indentation&lt;/li&gt;
&lt;li&gt;Cleaner code&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;cons&#34;&gt;Cons&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;You are breaking the normal flow of a function, which is returning something after doing all the operations, this is critically important if you have to release some resources and the function returns before the execution of those lines. This could happen in a slightly different case:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;createElements&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;elem1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;createElement&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;square&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;createSquare&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;square&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;elem1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;doSomething&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;removeElement&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;elem1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;In my opinion, it&amp;rsquo;s not as readable as the normal flow, with an if, even if this if is huge.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I&amp;rsquo;m not sure if in the first case is better to put that return, but after the leaks I had (I was working with Objective-C) if the function is more complex and the return is in the middle, in my opinion it&amp;rsquo;s better to have something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;createElements&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;elem1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;createElement&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;square&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;createSquare&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;square&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;elem1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;doSomething&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;removeElement&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;elem1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For the rest of cases, an early exit at the top if some precondition is not met seems good enough to me.&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Origin of HTML Radio Buttons</title><link>https://josem.co/origin-of-html-radio-buttons/</link>
      <pubDate>Tue, 03 Jul 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/origin-of-html-radio-buttons/</guid><description type="html">&lt;p&gt;The radio buttons in HTML come in handy when the user should select only one option in a form.&lt;/p&gt;
&lt;p&gt;The HTML looks like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;input&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;radio&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;mac&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;computer&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;mac&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;label&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;for&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;mac&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;Mac&lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;label&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;input&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;radio&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;computer&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;pc&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;pc&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;label&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;for&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;pc&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;PC&lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;label&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;input&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;radio&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;computer&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;hackintosh&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;hackintosh&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;label&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;for&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;hackintosh&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;Hackintosh&lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;label&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This element was called radio buttons because of the behaviour of the old car radios, where you could keep pushed only one button at the same time.&lt;/p&gt;

&lt;img src=&#34;https://josem.co//images/radio.jpg&#34; alt=&#34;&#34; title=&#34;Car Radio&#34; width=&#34;640&#34; height=&#34;480&#34; class=&#34;aligncenter size-full wp-image-190&#34; /&gt;</description>
      </item>
    
    <item>
      <title>IPad Acceleration with Javascript</title><link>https://josem.co/ipad-acceleration-with-javascript/</link>
      <pubDate>Sat, 09 Jun 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/ipad-acceleration-with-javascript/</guid><description type="html">&lt;p&gt;It&amp;rsquo;s well known that Apple supports HTML5 from the very beginning, that comes with a lot of advantages for Javascript developers. One of them is knowing the exact position of the iPad using a couple of events.&lt;/p&gt;
&lt;p&gt;First of all I have to say I&amp;rsquo;ve only tested this with an Ipad 2 with iOS 5, but it should work too with the new iPad (a.k.a. iPad 3).&lt;/p&gt;
&lt;p&gt;In order to know what&amp;rsquo;s the position of an iPad we can use the Device Motion Event, specified by the W3C &lt;a href=&#34;http://dev.w3.org/geo/api/spec-source-orientation.html#devicemotion&#34; rel=&#34;noopener nofollow&#34; target=&#34;_blank&#34; class=&#34;external&#34;&gt;here&lt;/a&gt;. For my purpose I only use 3 variables:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;window&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;addEventListener&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;devicemotion&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;e&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;e&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;accelerationIncludingGravity&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;e&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;accelerationIncludingGravity&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;z&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;e&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;accelerationIncludingGravity&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;z&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;},&lt;/span&gt; &lt;span class=&#34;kp&#34;&gt;false&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Once we have these variables it&amp;rsquo;s all about testing and playing with ranges of values. What I did was creating some messages after I detect a certain position, for instance, when the iPad is in landscape or portrait position using a function executed every 10ms.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;mainLoop&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;setInterval&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;moveMe()&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;moveMe&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// here you check what&amp;#39;s the value of a, y, and z
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;// and it&amp;#39;s checked every 10 ms
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I know, it would be great to have a little plugin to detect the different positions and trigger events accordingly, but I don&amp;rsquo;t own an iPad yet so I can only test with borrowed iPads :(&lt;/p&gt;</description>
      </item>
    
    <item>
      <title>Starting to Learn Python (for Programmers)</title><link>https://josem.co/starting-to-learn-python-for-programmers/</link>
      <pubDate>Tue, 22 May 2012 00:00:00 +0000</pubDate>
      
      <guid>https://josem.co/starting-to-learn-python-for-programmers/</guid><description type="html">&lt;p&gt;Some months ago I started to learn Python, I found a lot of resources and not all of them were really useful, they were either for non-programmers or too long for an introduction. After some research I came up with a list of resources.&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;&lt;a title=&#34;Google&#39;s Python Class&#34; href=&#34;http://code.google.com/edu/languages/google-python-class/set-up.html&#34; target=&#34;_blank&#34;&gt;Google&#39;s Python Class&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a title=&#34;Python Design Patterns&#34; href=&#34;http://code.google.com/intl/es-ES/edu/languages/index.html#_python_patterns&#34; target=&#34;_blank&#34;&gt;Python Design Patterns&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&#34;http://me.veekun.com/blog/2012/05/05/python-faq-webdev/&#34; target=&#34;_blank&#34;&gt;Python FAQ: Webdev&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;&lt;/div&gt;

&lt;p&gt;Apart from the links and all the hours reading and studying I find really important to create little projects that I can finish and publish.&lt;/p&gt;
&lt;p&gt;I think these projects have two advantages, on one side you can see that Python (or any language you are learning) can be actually used for something that you were trying to resolve. On the other, you are able to build it all by yourself (and that will encourage you to keep learning).&lt;/p&gt;</description>
      </item>
    
  </channel>
</rss>