{"id":553,"date":"2016-08-03T13:30:35","date_gmt":"2016-08-03T13:30:35","guid":{"rendered":"https:\/\/www.audero.it\/blog\/?p=553"},"modified":"2016-08-10T22:46:40","modified_gmt":"2016-08-10T22:46:40","slug":"power-simplicity-code","status":"publish","type":"post","link":"https:\/\/www.audero.it\/blog\/2016\/08\/03\/power-simplicity-code\/","title":{"rendered":"The power of simplicity in code"},"content":{"rendered":"<p>A\u00a0few days ago I found an online test\u00a0featuring six exercises on JavaScript. For fun, wishing to challenge myself with something tricky, I decided to take it.\u00a0The test proved to be very simple, so it isn&#8217;t worth a discussion. It&#8217;s what happened next that inspired this article.<\/p>\n<p>I was talking with a workmate about the test and he decided to take it despite my warning about its simplicity. We compared the solutions we wrote for two of the six exercises and we found out that they were quite different: his solutions were terse\u00a0and clever, mine were long and\u00a0extremely simple in their approach to the problem. These differences have generated an interesting discussion that touched several topics: readability, complexity, performance, and maintainability.<\/p>\n<p>Starting from the analysis of the two exercises we compared and the solutions we wrote, in this article I&#8217;ll share my thoughts about the power of simplicity in code.<br \/>\n<!--more--><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"580\" data-permalink=\"https:\/\/www.audero.it\/blog\/2016\/08\/03\/power-simplicity-code\/code-readability\/\" data-orig-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-readability.jpg\" data-orig-size=\"1200,364\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"code readability\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-readability-1024x311.jpg\" src=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-readability.jpg\" alt=\"code readability\" width=\"1200\" height=\"364\" class=\"aligncenter size-full wp-image-580\" srcset=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-readability.jpg 1200w, https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-readability-300x91.jpg 300w, https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-readability-1024x311.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>But before starting the discussion, I want to describe the exercises and the solutions we came up with.<\/p>\n<h2>Exercise 1: the &#8220;fizz buzz&#8221;\u00a0test<\/h2>\n<p>The first exercise is well-known as\u00a0the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fizz_buzz\" target=\"_blank\">&#8220;fizz buzz&#8221; test<\/a>.\u00a0This test\u00a0is proposed\u00a0in many interviews, regardless of the programming language(s) relevant to the position, and it&#8217;s usually given\u00a0at an early stage of the interview process due to its simplicity. Nonetheless, many have found that <a href=\"https:\/\/blog.codinghorror.com\/why-cant-programmers-program\/\" target=\"_blank\">a large number of developers can&#8217;t solve the &#8220;fizz buzz&#8221; test<\/a>\u00a0or even write code at all in the attempt to solve it.<\/p>\n<p>The &#8220;fizz buzz&#8221; test is presented below:<\/p>\n<blockquote><p>Write a program that prints the numbers from 1 to 100. But for multiples of three print &#8220;fizz&#8221; instead of the number, and for the multiples of five print &#8220;buzz&#8221;. For numbers which are multiples of both three and five print &#8220;fizzbuzz&#8221;.<\/p><\/blockquote>\n<p>To keep the discussion focused, I will only report the core <code>fizzBuzz()<\/code> functions my workmate and I developed. Both of them accept a number as its only argument and return the result expected by the test.<\/p>\n<h3>My solution<\/h3>\n<p>The code I wrote for this exercise is reported below:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction fizzBuzz(n) {\r\n   var isDivisibleBy3 = n % 3 === 0;\r\n   var isDivisibleBy5 = n % 5 === 0;\r\n\r\n   if (!isDivisibleBy3 &amp;&amp; !isDivisibleBy5) {\r\n      return n;\r\n   }\r\n\r\n   var str = '';\r\n\r\n   if (isDivisibleBy3) {\r\n      str += 'fizz';\r\n   }\r\n\r\n   if (isDivisibleBy5) {\r\n      str += 'buzz';\r\n   }\r\n\r\n   return str;\r\n}\r\n<\/pre>\n<h3>Other solution<\/h3>\n<p>The other solution for the &#8220;fizz buzz&#8221; test is the following:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction fizzBuzz(n) {\r\n   return &#x5B;\r\n      !(n % 3) &amp;&amp; 'fizz',\r\n      !(n % 3) &amp;&amp; 'buzz'\r\n   ]\r\n   .filter(Boolean)\r\n   .join('') || n;\r\n}\r\n<\/pre>\n<h2>Exercise 2: string formatting<\/h2>\n<p>The second exercise was slightly more complex than the &#8220;fizz buzz&#8221; test but still simple in its nature. The text of the exercise is the following:<\/p>\n<blockquote><p>Create a <code>strFormat()<\/code> format function that accepts a variable number of arguments in input. The function behaves as follows:<\/p>\n<ul>\n<li>If the function is called without any argument, it returns the string &#8220;You didn&#8217;t give me any arguments.&#8221;<\/li>\n<li>If the function is called with a single argument, it returns the string &#8220;You gave me 1 argument and it is &#8220;_ARGUMENT_&#8221;.&#8221; where <code>_ARGUMENT_<\/code> is the value of the argument provided<\/li>\n<li>For all other cases the function returns the string &#8220;You gave me _ARGUMENTS-LENGTH_ arguments and they are &#8220;_ARGUMENT-1_&#8221;, &#8220;_ARGUMENT-2_&#8221; and &#8220;_ARGUMENT-N_&#8221;.&#8221; where <code>_ARGUMENTS-LENGTH_<\/code> is the number of arguments provided, and <code>_ARGUMENT-1_<\/code>, <code>_ARGUMENT-2_<\/code>, and <code>_ARGUMENT-N_<\/code> their relevant values.<\/li>\n<\/ul>\n<p>So, if the call to the function is<\/p>\n<p><code>strFormat(\"hello\", \"world\", \"fizz\", \"buzz\")<\/code><\/p>\n<p>the string returned is<\/p>\n<p>&#8220;You gave me 4 arguments and they are &#8220;hello&#8221;, &#8220;world&#8221;, &#8220;fizz&#8221; and &#8220;buzz&#8221;.&#8221;<\/p><\/blockquote>\n<h3>My solution<\/h3>\n<p>The code that\u00a0I wrote to solve this exercise is the following:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction strFormat(...args) {\r\n   if (args.length === 0) {\r\n      return &quot;You didn't give me any arguments.&quot;;\r\n   }\r\n\r\n   if (args.length === 1) {\r\n      return `You gave me 1 argument and it is &quot;${args&#x5B;0]}&quot;`;\r\n   }\r\n\r\n   var formattedArguments = args\r\n      .map(argument =&gt; `&quot;${argument}&quot;`)\r\n      .join(', ')\r\n      .replace(\/(.*), (.*)$\/, '$1 and $2');\r\n\r\n   return `You gave me ${args.length} arguments ` +\r\n          `and they are ${formattedArguments}.`;\r\n}\r\n<\/pre>\n<h3>Other solution<\/h3>\n<p>The solution developed by my workmate for this exercise is shown below:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction generateSentence(args) {\r\n   let n = args.length;\r\n   let sentences = &#x5B;\r\n      'You didn\\'t give me any arguments.',\r\n      'You gave me 1 argument and it is {lastArg}',\r\n      `You gave me ${n} arguments and they are {args} and {lastArg}`\r\n   ];\r\n   let sentence = n &gt; 1 ? sentences&#x5B;2] : sentences&#x5B;n];\r\n\r\n   return sentence;\r\n}\r\n\r\nfunction templateSentence(sentence, list) {\r\n   return sentence\r\n      .replace('{args}', list.slice(0, -1).join(', '))\r\n      .replace('{lastArg}', list.slice(-1));\r\n}\r\n\r\nfunction strFormat(...args) {\r\n   let list = args.map(arg =&gt; `&quot;${arg}&quot;`);\r\n\r\n   return templateSentence(generateSentence(list), list);\r\n}\r\n<\/pre>\n<h2>The power of simplicity in code<\/h2>\n<p>As mentioned in the introduction, the two exercises are simple and their solution doesn&#8217;t require more than a few lines of code. Nonetheless, the solutions presented in this post are really different in complexity and the approach used. I&#8217;ll start their comparison by discussing how readable the code of the two solutions is.<\/p>\n<h3>Code readability<\/h3>\n<p>My solution for the &#8220;fizz buzz&#8221; test is longer and more verbose than necessary but it gains in readability. I dare anyone having a basic knowledge of programming to not understand what the code does. But what I mean exactly with <em>readability<\/em>? Code readability doesn&#8217;t have a real definition, so every developer might explain it in a slightly different way. My definition of code readability is:<\/p>\n<blockquote><p>A code is <em>readable<\/em> if it can be understood by anyone with a basic knowledge of the programming language in use with a single read.<\/p><\/blockquote>\n<p>With <q>basic knowledge of the programming language in use<\/q> I mean that the person reading the code must understand essential statements like <code>if...else<\/code> and <code>for<\/code>. This means that if a person that doesn&#8217;t meet this condition is not able to understand the code under examination, the problem is not the code.<\/p>\n<p>In my definition I also mention <q>with a single read<\/q>. If a developer has to read a code multiple times to understand what it does, the code can be improved. The less experienced is the developer that is reading the code, the better. If a piece of code can be understood by anyone in the team, the code won&#8217;t turn into a magic box that nobody touches for the fear of breaking it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"581\" data-permalink=\"https:\/\/www.audero.it\/blog\/2016\/08\/03\/power-simplicity-code\/code-simplicity\/\" data-orig-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-simplicity.png\" data-orig-size=\"604,340\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"code simplicity\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-simplicity.png\" src=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-simplicity.png\" alt=\"code simplicity\" width=\"604\" height=\"340\" class=\"aligncenter size-full wp-image-581\" srcset=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-simplicity.png 604w, https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-simplicity-300x169.png 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/p>\n<p>Let&#8217;s now take a closer look at my solution for the first exercise to see how it relates with such definition.<\/p>\n<p>My <code>fizzBuzz()<\/code> function is made of basic language statements (<code>if<\/code> and <code>return<\/code>) and operations (<code>modulo<\/code> and <code>assignments<\/code>). In addition, the use of variable names (such as <code>isDivisibleBy3<\/code>) makes the code even easier to read.<\/p>\n<p>For example, the following <code>if<\/code> statement<\/p>\n<pre class=\"brush: jscript; highlight: [1]; title: ; notranslate\" title=\"\">\r\nif (isDivisibleBy3) {\r\n   str += 'fizz';\r\n}\r\n<\/pre>\n<p>is more readable than<\/p>\n<pre class=\"brush: jscript; highlight: [1]; title: ; notranslate\" title=\"\">\r\nif (n % 3 === 0) {\r\n   str += 'fizz';\r\n}\r\n<\/pre>\n<p>While for most developers this change won&#8217;t make any real difference, it can have a big impact on a junior developer.<\/p>\n<p>But how my function compares with the other one? The latter features the use of a couple of interesting techniques worth a mention.<\/p>\n<p>The first technique relies on how Boolean expressions are evaluated in JavaScript. When a Boolean expression is evaluated in JavaScript, the rightmost value processed is returned. So, in the expression <code>!(n % 3) && 'fizz'<\/code> if <code>n<\/code> is divisible by 3, the right operand (the <code>'fizz'<\/code> string) is evaluated and returned. This means that if <code>n<\/code> is divisible by 3, the result of the expression <code>!(n % 3) && 'fizz'<\/code> is <code>'fizz'<\/code>. If you&#8217;re new to JavaScript this result might come as a surprise because in most languages the result of a Boolean expression is always a Boolean.<\/p>\n<p>The second interesting technique employed is the use of the <code>Boolean<\/code> constructor with the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\/filter\" target=\"_blank\"><code>filter()<\/code> function<\/a>. Line 6 (<code>.filter(Boolean)<\/code>) shows that the <code>Boolean<\/code> constructor is passed as the first argument to <code>filter()<\/code>. This is a method to filter all the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Falsy\" target=\"_blank\"><em>falsy<\/em> values<\/a> from the array returned by the function.<\/p>\n<p>Both these techniques are nice and communicate something good about the author of the code. However, this cleverness comes with a price. The price is the nontrivial cognitive effort that a less experienced developer has to put in order to be able to understand the code. Even worse, the reader of the code might not be able to understand the code at all, turning the snippet into a magic box that he or she will avoid at all costs.<\/p>\n<p>Before moving to the next topic, I want to show you the shortest solution for the &#8220;fizz buzz&#8221; test:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction fizzBuzz(n) {\r\n   return (n % 3 ? '' : 'fizz') + (n % 5 ? '' : 'buzz') || n;\r\n}\r\n<\/pre>\n<p>As you can see, the above <code>fizzBuzz()<\/code> function is made of a single statement. While this is a short and simple solution to the problem, what do you think of its readability?<\/p>\n<p>With this question in mind, let&#8217;s discuss about code simplicity.<\/p>\n<h3>Code simplicity<\/h3>\n<p>I&#8217;ve been coding for a while now and an important lesson I&#8217;ve learned in my career is:<\/p>\n<blockquote><p>If there is a simpler solution to a problem, implement it.<\/p><\/blockquote>\n<p>This approach is not new and many others have come to this conclusion way before me. The above quote is nothing but a paraphrase of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/KISS_principle\" target=\"_blank\">KISS principle<\/a> with which you may be familiar with.<\/p>\n<p>Once completed a feature, many developers tend to refactor their code to improve it. However, many of them strive for the wrong goal. Instead of refactoring to improve code readability and to implement a simpler solution, many developers focus on shortening their code, often by employing clever techniques or relying on obscure language features. A good example of this habit can be spot by looking at the second solution for the &#8220;fizz buzz&#8221; test.<\/p>\n<p>When refactoring we should always strive for code simplicity. This involves reducing the cognitive effort required to understand a code. The solutions proposed to solve the second exercise offer a great starting point to analyze this aspect. This time, instead of focusing my attention on the specific lines of code written, I want to focus on the approach adopted.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"573\" data-permalink=\"https:\/\/www.audero.it\/blog\/2016\/08\/03\/power-simplicity-code\/php-street-fighter\/\" data-orig-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/php-street-fighter.jpg\" data-orig-size=\"720,511\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"PHP Street Fighter\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/php-street-fighter.jpg\" src=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/php-street-fighter.jpg\" alt=\"PHP Street Fighter\" width=\"720\" height=\"511\" class=\"aligncenter size-full wp-image-573\" srcset=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/php-street-fighter.jpg 720w, https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/php-street-fighter-300x213.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/p>\n<p>My solution consists of a single function, while the other is split in three. Generally speaking, I&#8217;m all for splitting a problem into multiple, smaller problems, solve them, and then combine the solutions to solve the original problem. However, experience has taught me that going too far with this approach can be harmful.<\/p>\n<p>Jumping from a function to another to grasp the aim of a code causes a lot of context switching in a developer&#8217;s brain. Too much context switching can lead to focus loss. It can also cause the loss of the original reason that firstly led to the code investigation. How many times have you started exploring a snippet of code to fix a bug and have found yourself few minutes later wondering what was your original goal? How many times have you felt that you&#8217;ve gone so many levels deep into the code that you lost track of what you were doing? I bet a lot. In these cases, it can be beneficial to combine two or more functions together to avoid too many jumps.<\/p>\n<p>In conclusion, if you reach a point where a problem has become fairly simple, don&#8217;t split it into subproblems. The context switching required by those reading the code might cause them a lot of frustration. Be sure you don&#8217;t violate the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Single_responsibility_principle\" target=\"_blank\">single responsibility principle<\/a> by combining unrelated functions, but avoid creating trivial functions.<\/p>\n<p>There is yet another benefit that code simplicity can bring to the table. Let&#8217;s examine it.<\/p>\n<h3>A note on performance<\/h3>\n<p>Readability is a crucial factor when writing code, but there is another important aspect developers should be concerned about: performance. Many think that a shorter, clever code always leads to better performance. In several cases this assumption is false, in others cases the improvement in performance is irrelevant (more on this in a moment), and only in few cases it really matters. As <a href=\"https:\/\/twitter.com\/getify\" target=\"_blank\">Kyle Simpson<\/a> has pointed out in several occasions, ECMAScript engines become better and better every month, and their ability to optimize code is constantly improving. So, there are cases where a developer can write terse and cryptic code that takes advantage of optimization techniques that lead to better performance compared to other solutions. But this gain will eventually vanish in a future release of the engines. Therefore, all that&#8217;s left is obscure code that nobody wants to read or change.<\/p>\n<p>As an example of a clever code that doesn&#8217;t lead to a faster execution, let&#8217;s take into account the solutions for the &#8220;fizz buzz&#8221; test. My solution is more verbose and adopts a simple approach, but it&#8217;s also incredibly faster than the other. The actual difference increases with the amount of times the performance test is run. The other solution is 4x to more than <strong>50x slower<\/strong> than mine. If you want to test the difference by yourself, <a href=\"https:\/\/jsbin.com\/jekahif\/edit?js,output\" target=\"_blank\">have a look at the JSBin I&#8217;ve set up<\/a>.<\/p>\n<p>Comparing the solutions for the second exercise provides similar conclusions. This time the difference in performance is smaller but still relevant. The clever solution is ~2x slower than the simple one. If you want to test the difference by yourself, <a href=\"https:\/\/jsbin.com\/casuyo\/edit?js,console\" target=\"_blank\">have a look at the JSBin I&#8217;ve set up for the second exercise<\/a>.<\/p>\n<h2>Conclusions<\/h2>\n<p>In this article I&#8217;ve proposed two JavaScript exercises and the relevant solutions I and a workmate of mine have developed to solve them. These solutions are very different in their approach to the problems and have different levels of complexity, readability, and performance.<\/p>\n<p>While comparing the solutions reported in this blog post, I highlighted some important lessons every developer should keep in mind. When developing and refactoring code we should always strive for code simplicity and readability, so that we reduce the cognitive effort required to understand our code. This attitude will allow anyone in our team to contribute to the code and it will avoid situations where a part of the software turns into a magic box that nobody is willing to change. A code that is simple and readable can be easily patched, extended, and changed.<\/p>\n<p>The approach I&#8217;m proposing for writing code doesn&#8217;t want to limit developers&#8217; expressiveness to a bunch of trivial features. My goal is to let developers focus more on code readability than the number of lines or the use of clever techniques. This is even more true if degradation in performance is the price to pay.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A\u00a0few days ago I found an online test\u00a0featuring six exercises on JavaScript. For fun, whishing to challenge myself with something tricky, I decided to take it.\u00a0The test proved to be very simple, so it isn&#8217;t worth a discussion. It&#8217;s what happened next that inspired this article.<\/p>\n<p>I was talking with a workmate about the test and he decided to take it despite my warning about its simplicity. We compared the solutions we wrote for two of the six exercises and we found out that they were quite different: his solutions were terse\u00a0and clever, mine were long and\u00a0extremely simple in their approach to the problem. These differences have generated an interesting discussion that touched several topics: readability, complexity, performance, and maintainability.<\/p>\n<p>Starting from the analysis of the two exercises we compared and the solutions we wrote, in this article I&#8217;ll share my thoughts about the power of simplicity in code.<\/p>\n","protected":false},"author":1,"featured_media":595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[63,64,23],"class_list":["post-553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-discussions-opinions","tag-code-readability","tag-code-simplicity","tag-performance"],"jetpack_featured_media_url":"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9Or4e-8V","jetpack-related-posts":[{"id":637,"url":"https:\/\/www.audero.it\/blog\/2016\/12\/16\/from-javascript-developer-to-javascript-engineer-re-implementing-ecmascript-2015s-string-prototype-repeat-method\/","url_meta":{"origin":553,"position":0},"title":"From JavaScript developer to JavaScript engineer: re-implementing ECMAScript 2015&#8217;s String.prototype.repeat() method","author":"Aurelio De Rosa","date":"December 16, 2016","format":false,"excerpt":"As developers, our work is to solve problems which often implies writing code. Some of the problems we face look really simple in nature, but their simplicity leads us to write sub-optimal solutions without even realizing it. JavaScript developers come from very different backgrounds, and assuming that everyone has the\u2026","rel":"","context":"In &quot;From JavaScript developer to JavaScript engineer&quot;","block_context":{"text":"From JavaScript developer to JavaScript engineer","link":"https:\/\/www.audero.it\/blog\/category\/javascript\/from-javascript-developer-to-javascript-engineer\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/12\/time-complexity-comparison.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/12\/time-complexity-comparison.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/12\/time-complexity-comparison.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":672,"url":"https:\/\/www.audero.it\/blog\/2017\/01\/18\/from-javascript-developer-to-javascript-engineer-find-all-celebrities-in-a-set-of-people\/","url_meta":{"origin":553,"position":1},"title":"From JavaScript developer to JavaScript engineer: find all celebrities in a set of people","author":"Aurelio De Rosa","date":"January 18, 2017","format":false,"excerpt":"In the first article of my series From JavaScript developer to JavaScript engineer titled From JavaScript developer to JavaScript engineer: Re-implementing ECMAScript 2015's String.prototype.repeat() method I've discussed how computer science concepts can help in writing better and more elegant software. Specifically, I've demonstrated how to use appropriate algorithms and data\u2026","rel":"","context":"In &quot;From JavaScript developer to JavaScript engineer&quot;","block_context":{"text":"From JavaScript developer to JavaScript engineer","link":"https:\/\/www.audero.it\/blog\/category\/javascript\/from-javascript-developer-to-javascript-engineer\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/12\/oscars-2014-selfie.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/12\/oscars-2014-selfie.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/12\/oscars-2014-selfie.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":832,"url":"https:\/\/www.audero.it\/blog\/2018\/07\/20\/5-javascript-interview-questions-a-mid-level-developer-should-be-able-to-answer\/","url_meta":{"origin":553,"position":2},"title":"5 JavaScript interview questions a mid-level developer should be able to answer","author":"Aurelio De Rosa","date":"July 20, 2018","format":false,"excerpt":"According to the results of the 2018's StackOverflow survey, JavaScript is the most popular technology. The amount of job offers for JavaScript developers is constantly increasing and with more companies adopting JavaScript as their main language, it's easy to find good ones. But before you are hired by a company,\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/www.audero.it\/blog\/category\/javascript\/"},"img":{"alt_text":"job interview panel","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/06\/job-interview-panel.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/06\/job-interview-panel.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/06\/job-interview-panel.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/06\/job-interview-panel.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/06\/job-interview-panel.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":14,"url":"https:\/\/www.audero.it\/blog\/2013\/05\/09\/how-to-change-the-default-view-in-zend-framework-1\/","url_meta":{"origin":553,"position":3},"title":"How to Change the Default View in Zend Framework 1","author":"Aurelio De Rosa","date":"May 9, 2013","format":false,"excerpt":"In this article I'll give you a little tip about a situation which often arises during the development of a website or a web application based on the Zend Framework 1. I'll explain how you can change the default view of a given action.","rel":"","context":"In &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/www.audero.it\/blog\/category\/php\/"},"img":{"alt_text":"Zend Framework banner","src":"https:\/\/i0.wp.com\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/05\/zend-framework-banner.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":524,"url":"https:\/\/www.audero.it\/blog\/2018\/05\/16\/event-delegation-in-javascript\/","url_meta":{"origin":553,"position":4},"title":"Event delegation in JavaScript","author":"Aurelio De Rosa","date":"May 16, 2018","format":false,"excerpt":"One of the most common tasks a web developer deals with is to add event listeners to the elements of a page. Event listeners are employed to perform one or more actions when a given event occurs on one or more elements. For example, by using an event listener we\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/www.audero.it\/blog\/category\/javascript\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/event-delegation.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/event-delegation.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/event-delegation.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/event-delegation.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5,"url":"https:\/\/www.audero.it\/blog\/2013\/05\/13\/learning-curve-what-it-is-and-how-it-applies-to-information-technology\/","url_meta":{"origin":553,"position":5},"title":"Learning Curve: What it is and How it Applies to Information Technology","author":"Aurelio De Rosa","date":"May 13, 2013","format":false,"excerpt":"The terms \"learning curve\" and \"steep learning curve\" are often talked and written in Computer Science. At the time I could not understand deeply those terms, every time I found them I felt like I was missing something that all programmers except me already knew. After, I realised that there\u2026","rel":"","context":"In &quot;Discussions &amp; Opinions&quot;","block_context":{"text":"Discussions &amp; Opinions","link":"https:\/\/www.audero.it\/blog\/category\/discussions-opinions\/"},"img":{"alt_text":"Tic Tac Toe learning curve","src":"https:\/\/i0.wp.com\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/05\/tic-tac-toe-learning-curve.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/comments?post=553"}],"version-history":[{"count":25,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/553\/revisions"}],"predecessor-version":[{"id":597,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/553\/revisions\/597"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/media\/595"}],"wp:attachment":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/media?parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/categories?post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/tags?post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}