<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gonzalo N. D&#39;Elia on Medium]]></title>
        <description><![CDATA[Stories by Gonzalo N. D&#39;Elia on Medium]]></description>
        <link>https://medium.com/@gonzalo.delia?source=rss-7d709c8090e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_XkbgWAmU9IQenzWKp_Gjg.jpeg</url>
            <title>Stories by Gonzalo N. D&amp;#39;Elia on Medium</title>
            <link>https://medium.com/@gonzalo.delia?source=rss-7d709c8090e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:46:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gonzalo.delia/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From AngularJs to ReactJs: A Brief Comparison]]></title>
            <link>https://medium.com/quadion-technologies/from-angularjs-to-reactjs-a-brief-comparison-f44b21b56157?source=rss-7d709c8090e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f44b21b56157</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Gonzalo N. D'Elia]]></dc:creator>
            <pubDate>Thu, 17 May 2018 18:17:46 GMT</pubDate>
            <atom:updated>2018-05-17T18:58:56.312Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jXoW4NUI-E5HmhvrPvpipw.jpeg" /></figure><h4>Going from AngularJs to ReactJs might be easier than you think.</h4><p><em>Note: The following post assumes at least a basic knowledge of AngularJs and ReactJs.</em></p><p>In Quadion we love to try new technologies. And in my particular case, after being an AngularJs developer for almost 5 years, trying ReactJs looked like an exciting experience. Although in 2017/2018 both frameworks are considered as the top frameworks for frontend (together with <a href="https://vuejs.org/">vue.js</a>), they are somewhat different. The former is a complete framework which lets you build entire pages with the structure they provide, while the latter is just a library that does one thing (building components, more on that later), but really well.</p><p>Even though AngularJs had its moment, the older versions (1.x) are slowly being left behind in terms of interest. And that’s understandable, because the Google team is putting their efforts in newer versions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*cLXm7WPxQbTpVjvLAg4lGw.png" /><figcaption>% of questions of AngularJs in Stack Overflow.</figcaption></figure><p><a href="https://angularjs.org/">AngularJs</a> has been proven to be a reliable framework to build powerful apps, offering lots of advanced features. However, Google is putting all of its effort into <a href="https://angular.io/">Angular </a>(don’t confuse it with AngularJs — Angular refers to version 2 and above) which might be difficult to migrate to (although <a href="https://angular.io/guide/upgrade">paths to do so</a> exist).</p><p>Even though I had enjoyed a lot working with such a great framework, I felt that the new member in the neighborhood had lots to offer, so we decided to give it a try.</p><p>ReactJs is the current emerging technology. But it is not just “a trend”: it has arrived to stay. Backed by Facebook, it has an amazing community, growing at high speed. We know the <a href="https://stackoverflow.blog/2018/01/11/brutal-lifecycle-javascript-frameworks/">lifecyle of javascript frameworks is brutal</a>, so it was natural to wonder ourselves: Does it worth to learn a new framework/library ? Should we wait until the community is more developed ? What will be the cost of shifting our minds from the “AngularJs paradigm” to the “ReactJs paradigm” ? Should we continue with the newest Angular versions, instead of trying ReactJs ?</p><p>Given the increasing tendency of ReactJs, these doubts were natural. And it turned out that our background in Angular helped us a lot to make the transition smoother. It was just a matter of adapting some key concepts, and we were ready to go! Understanding their similarities (and differences) helped us to start new projects in ReactJs.</p><p>This is a small comparison which I believe it might help AngularJs developers understand what’s behind ReactJs and its features.</p><h3>Directives and Components</h3><p>From the AngularJs side, although from version 1.5 components were available, if you needed powerful DOM manipulation directives were the answer. Moreover, directives allowed you to encapsulate reusable functionality that could be configured through an interface (attribute binding), though it was not perfect: it could be complicated to understand the differences between inherited scopes and isolated scopes.</p><p>On the other hand, ReactJs offers their own “components” which are something very similar: reusable pieces of html + js, that can be configured from the outside. Instead of scope, we just have the concept of “state”, which is internal to the component: a component might have a state, or not. And that’s it.</p><p>Let’s see an example of a directive</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fjsfiddle.net%2Fjowmwdhs%2F3%2F&amp;src=https%3A%2F%2Fjsfiddle.net%2Fjowmwdhs%2F3%2Fembedded%2F&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3970ae6ac2aaff35d6d9748ceeb5e294/href">https://medium.com/media/3970ae6ac2aaff35d6d9748ceeb5e294/href</a></iframe><p>Here we just use a directive, with an isolated scope, that renders the strings that gets through its “hello-text” interface.</p><p>On the other hand, ReactJs offers a different syntax, but that allows you to achieve a similar result.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fjsfiddle.net%2Fxajsfu92%2F2%2F&amp;src=https%3A%2F%2Fjsfiddle.net%2Fxajsfu92%2F2%2Fembedded%2F&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/bed2b70bebfde371d49b07bdeb848c80/href">https://medium.com/media/bed2b70bebfde371d49b07bdeb848c80/href</a></iframe><p>Besides the concept of state, ReactJs offer a special property called “props”, which is basically what we passed to the React Component. Pretty much like when we passed our “Hello world!” to our AngularJs’ directive! What is important about props is that they’re thought only to be read. Moreover, if the component (just like the example) does not require an internal “state” (more on that later) it can be written as a simple js function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/212c988bdfa1510dde51d077e379dffe/href">https://medium.com/media/212c988bdfa1510dde51d077e379dffe/href</a></iframe><p>This makes a cleaner and simpler code (note: component variables should always <a href="https://stackoverflow.com/questions/30373343/reactjs-component-names-must-begin-with-capital-letters">be upper case</a>). Of course, AngularJs offers more control over how we passed information to our widgets, offering one way binding, two way binding, and more.</p><p>ReactJs makes it simple by forcing you to use one way binding, including functions to handle value updates in the upper component container if needed.</p><p>In the end, both offer a nice way to write widgets, that means, pieces of reusable functionality that have their own state, and can update themselves given their internal state.</p><p>On a personal note, I believe that ReactJs simplicity is a core feature, since developers don’t have to worry on which type of scope should they use, nor which attribute binding should they consider.</p><h3>Scope and State</h3><p>The definition for scope, according to<a href="https://docs.angularjs.org/guide/scope"> AngularJs docs</a>, is</p><blockquote><a href="https://docs.angularjs.org/api/ng/type/$rootScope.Scope">Scope</a> is an object that refers to the application model. It is an execution context for <a href="https://docs.angularjs.org/guide/expression">expressions</a>. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch <a href="https://docs.angularjs.org/guide/expression">expressions</a> and propagate events.</blockquote><p>Scope is the glue between controllers and views in AngularJs. That way, it is the perfect place to handle state of our apps, where we load our initial data and where our model resides. Once scope changes, view is updated to reflect changes.</p><p>Regarding ReactJs, while there’s no such dictionary definition for what state is in their docs, we think of it as the javascript context in which our model lies for each component, and the place that, when updated, will trigger new renders. Does that sound you familiar ? Yes, that sounds like one of the AngularJs core concepts, databinding (although in AngularJs it is less clear how the DOM actually changes — it just looks like magic).</p><p>There are, though, differences in how changes are detected. AngularJs tries to be smart in detecting any change you do to scope (through the digest cycle). While this might be a powerful concept, it has some caveats and may be too complex for some cases. For instance, it forces the framework to offer wrappers for many common javascript functions (prefixed by $ — for instance $timeout to replace setTimeout) in order to prevent execution of code that cannot be detected by the digest cycle. You might be surprised of how many times this has confused developers.</p><p>ReactJs, on the other hand, makes this simpler and expects you to tell it what and when you update, through the setState method. Through its <a href="https://reactjs.org/docs/reconciliation.html">reconciliation</a> algorithm, it will detect, after batching many state changes, how much of your app has changed, and what needs to be rendered again.</p><h3>DOM manipulations</h3><p>AngularJs always discouraged the integration of jQuery to AngularJs projects; regardless of that, they offered a small subset of it, through their <a href="https://docs.angularjs.org/api/ng/function/angular.element">angular.element()</a> API. In a way, it was used to transform the dom such as we were used to do it with jQuery. There’s no such thing in ReactJs. If you want to do DOM transformations, you should use the javascript API, which, as of today, is more consistent across browsers than ever.</p><p>Despite that fact, ReactJs components encourage dom modifications through the usage of render function as pure components: Given your state, you just build the output you want. If state changes, ReactJs will call render() again, so you have just to worry about render the output you want given your state.</p><p>That means, we treat the render function as a pure function. It allows to use pure javascript and JSX (a syntax extension to js) to create the structure we want. The imperative declaration of changes is discouraged, and the render function encourage to work in a cleaner way. To me, it is a very powerful feature.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0984421a55a8ad1c6cc32a7706f73a1e/href">https://medium.com/media/0984421a55a8ad1c6cc32a7706f73a1e/href</a></iframe><p>AngularJs, however, uses directives in plain HTML to describe the view we want to render. To that, AngularJs offers built in directives that we can place in our html code, whether we do it in the template of a directive, or in a separated html, linked through templateUrl property.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f5321ed54019cfea784e73816a6aaed/href">https://medium.com/media/9f5321ed54019cfea784e73816a6aaed/href</a></iframe><p>As you can see, there are differences, between putting “some sort of html into js” (ReactJs approach, with JSX) and putting “some sort of js into html” (AngularJs approach). Proper debugging is one of the benefits of the first approach , it is easier to understand what is going to be rendered while debugging the render function; on the contrary, understanding the final output of the html compilation (how do I debug ng-repeat, without looking into AngularJs source code?) might be at least tricky, especially for new developers.</p><h3>Ecosystem</h3><p>AngularJs has a built-in suite of services that allows you to <a href="https://docs.angularjs.org/api/ng/service/$http">fetch data</a> from the server, to describe proper <a href="https://docs.angularjs.org/api/ngRoute/service/$route">routing</a>, inject your <a href="https://docs.angularjs.org/guide/di">dependencies</a>, and even write localized apps using <a href="https://docs.angularjs.org/guide/i18n">internationalization</a>, and much more, all backed by the same community that develops the framework. This also comes with a cost, since the script files might be too unnecessarily big for your application.</p><p>ReactJs, however, is a thin library that only comes with few functionalities, and most of the utilities are provided by 3rd parties, backed (in most cases) by open source communities; an example of this is <a href="https://reacttraining.com/react-router/">React Router</a>. Furthermore, ReactJs is under continuous improvement and development, adding lots of new features in every release, making it a not-so-stable library. All of this might be a problem or not, according to your needs.</p><h3>Summary</h3><p>All in all, both are a great option to built your apps. Given that AngularJs is being left behind, and that ReactJs is having its momentum, it is a wonderful opportunity to try a flexible library to build the component your app needs.</p><p><em>Would you like to know more? Do you need our help? </em><a href="https://www.quadiontech.com/#contact"><em>Contact Us!</em></a><em><br></em><a href="https://www.quadiontech.com/"><em>www.quadiontech.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f44b21b56157" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quadion-technologies/from-angularjs-to-reactjs-a-brief-comparison-f44b21b56157">From AngularJs to ReactJs: A Brief Comparison</a> was originally published in <a href="https://medium.com/quadion-technologies">Quadion Technologies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing code: Unifying your codebase conventions]]></title>
            <link>https://medium.com/quadion-technologies/writing-code-unifying-your-codebase-conventions-ca02ba794274?source=rss-7d709c8090e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca02ba794274</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding-conventions]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Gonzalo N. D'Elia]]></dc:creator>
            <pubDate>Wed, 21 Jun 2017 13:10:10 GMT</pubDate>
            <atom:updated>2017-06-21T13:10:10.917Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EV2Rfcb2QmBsN45DdQ0EZQ.jpeg" /></figure><h3>Writing Code: Unifying Your Codebase Conventions</h3><p>Writing software can be harsh many times. Whether working alone or in small teams, adopting good practices or standards at the time of writing code usually contributes to improving its <a href="https://en.wikipedia.org/wiki/Computer_programming#Readability_of_source_code">readability</a>. Defining a programming style unified across the team helps with reading a code written by someone else.</p><p>How many of us, developers, have came across with lines of source code that were unintelligible or difficult to understand? Unifying criteria in one agreed style allows, at first glance when dealing with a piece of code, having the same mindset and just focusing on what the program does (or wants to do) rather than how it is written.</p><p>Following a defined <a href="https://en.wikipedia.org/wiki/Coding_conventions">convention</a> contributes to the code’s quality, gives it coherence and improves the experience when working with it. Moreover, it contributes in the mid and long term to its <a href="https://en.wikipedia.org/wiki/Maintainability">maintainability</a>: Programmers spend too much time on reading and trying to understand code. Improving this process facilitates the adaptability, modifiability and extensibility of your code<a href="#b1ff">¹</a>. If not, new bugs may be introduced because programming over existing code becomes harder. But how do we make all developers follow the standard we define?</p><p>The first solution we can think of is manual review: A manual revision to assert that the conventions are being followed. But it’s undeniable that this is tedious and slow — it will just take too much time. For small teams and a relatively small codebase it might be a possibility. But how could we achieve this goal when multiple teams work together, or in a project with thousands of hundreds of lines of code? What if each team works on different modules?</p><h3>Coding Standards</h3><p>As we have already stated, we need to establish a convention for coding time. Some clear examples of things to consider:</p><ul><li>camelCase or PascalCase?</li><li><a href="https://softwareengineering.stackexchange.com/questions/57/tabs-versus-spaces-what-is-the-proper-indentation-character-for-everything-in-e">Tabs or spaces</a> for indentation?</li><li>Using simple quotes (‘) or double quotes (“) for strings?</li><li>Should curly braces be in the same line (K&amp;R style) or in a new line ?</li></ul><p>.. and many more conventions. Defining all of them not only implies following each language’s recommendations but also setting up an unified style at the team level (or even at product/project/organization level) about how to write code, and how to ensure compliance with those rules.</p><p>There are some tools that allow you to automate the review of the code you write and prevent some of the bad practices (and even encourage the good ones!). In this post, we will see some of those tools we use when working with C# or JS.</p><h3>Javascript</h3><p>In these days and age, Javascript is widely used, from simple web pages to the richer web apps that include lots of animations, ajax calls and process many data. Applications can have a large frontend codebase, and since it is a dynamically typed language, it might become difficult to manage.</p><p>Javascript can also be a tricky language to start with, since there are many “<a href="https://github.com/stevekwan/best-practices/blob/master/javascript/gotchas.md">gotchas</a>”, and unifying the criteria to write code will improve your devs experience and learning.</p><p>This is a list of some of the things we use/do:</p><h4>‘use strict;’</h4><p>If you ever have programmed in JS, surely you have heard that you must never:</p><ul><li>Create global variables</li><li>Use the evil eval() function</li><li>Use the delete operator within a variable (declared with var)</li></ul><p>.. as well as other deprecated features from EcmaScript 3 (which are still available due to retrocompatibility with EcmaScript 5).</p><p>All these features can be easily avoided: the ‘<a href="https://johnresig.com/blog/ecmascript-5-strict-mode-json-and-more/">use strict</a>’ directive allows you to execute your javascript in a “safe” context, in which these features are prohibited, throwing an error when loading the script. This makes detecting and correcting errors easier. Adding the directive at the beginning of each script executes it completely in strict mode, and it also can be made at the function level as well, just like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dce9e6dab2ead3e5ddf95f6c8ec111a0/href">https://medium.com/media/dce9e6dab2ead3e5ddf95f6c8ec111a0/href</a></iframe><p>Doing so for all scripts, helps us prevent some common pitfalls (which could happen for instance if the developer is new to the language).</p><p>Let’s see an example. If we try to load the following script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc1e7f510739cb0c58577ff8c4ba1e56/href">https://medium.com/media/fc1e7f510739cb0c58577ff8c4ba1e56/href</a></iframe><p>We will get the next error just as we load the script on the page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*SNX3AKIb_4SUvSLBDuY5BA.png" /></figure><p>If we wouldn’t use the ‘‘use strict’, the script would work normally, and we are allowed to use global variables (which you probably already know why should be avoided).</p><h4>JSCS</h4><p>We have talked about coding conventions. If there’s too many people (whether because there are many teams or the standard usage is along the whole company), making each developer follow the convention will be hard. This is when <a href="http://jscs.info/">JSCS </a>enters the scene.</p><p>This tool let us automatically review all our scripts, and verify if the code follows the conventions we have defined. To do so, we create a .jscsrc file with the rules to comply (check their rules in the <a href="http://jscs.info/rules">docs</a>!). With the tool, we can easily detect errors, fix them, and we are also “guided” to write a better code.</p><p>Remember:</p><blockquote>Standardized practices ➞ Cleaner code and increased readability ➞ Increased maintainability!</blockquote><h4>Adding the Task-runner</h4><p>But how do we integrate JSCS to our workflow ? There are many ways, and the one we have chosen is using <a href="https://gruntjs.com/">Grunt</a>.</p><p>Grunt is a task runner which allows us to configure different repetitive tasks and the order in which they are done, like a pipeline. As they state in their doc, in one word: Automation.</p><p>Using Grunt we can <a href="https://en.wikipedia.org/wiki/Lint_(software)">lint </a>our code as well as <a href="https://en.wikipedia.org/wiki/Minification_(programming)">minify</a> it, <a href="https://en.wikipedia.org/wiki/Obfuscation_(software)">obfuscate</a> it, and many more tasks.</p><p>Although we recommend you to check grunt’s official docs to learn how to register tasks, for JSCS all you have to do is install through <a href="https://www.npmjs.com/">NPM</a> the <a href="https://github.com/jscs-dev/grunt-jscs">grunt-jscs</a> package, create a .jscsrc file with the rules and include it in a task in a gruntfile.js</p><p>Our example of .jscsrc file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c71a0d7982ce3cc834a717c55256a81/href">https://medium.com/media/3c71a0d7982ce3cc834a717c55256a81/href</a></iframe><p>As you can see, it is just a JSON object, with the rules as properties. And if you are not sure which style to define, because you think it is hard or you can’t come to an agreement with your teammates, then you could use the <a href="http://jscs.info/overview#presets">presets</a> defined by other companies, such as Google or jQuery ;)</p><p>You can check the gruntfile.js example in the <a href="https://github.com/jscs-dev/grunt-jscs#usage-examples">official docs page</a></p><p>Last but not least, how do we run this tasks? Once registered in the grunt file (using <a href="https://gruntjs.com/api/grunt.task#creating-tasks">grunt.registerTask()</a>) the only thing we have to do is run the command from the npm (npm configuration is out of the scope of this post).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72eccbefdaa5dcda8cd10aeabc06a5c5/href">https://medium.com/media/72eccbefdaa5dcda8cd10aeabc06a5c5/href</a></iframe><p>There are other tasks runners such as <a href="http://gulpjs.com/">Gulp </a>or <a href="https://webpack.github.io/">Webpack</a>.</p><h4>JsHint</h4><p>So far, by placing ‘use strict’ at the beginning of each script plus the usage of JSCS, we can prevent some silly mistakes and enforce the unified style of the code. But what if a function declares variables that are never used? What if a variable is used without ever been assigned before? What if there are lines of code after a return statement (which will never get executed)?</p><p>The code that never fails is the one that never needs to be executed and, therefore, it is not even written<a href="#5009">²</a>. Following this line of thought, if we add unnecessary code, we are only adding noise, which increases the effort to read it. Is it work in progress? Is it a developer’s error, who forgot to define a variable? Is it a typo? Did the developer intend to create a closure and do it wrong?</p><p>All these kinds of problems and many others can be detected with <a href="http://jshint.com/">JsHint</a>, a tool that lets us check the quality of our js scripts.</p><p>Just like JSCS, JsHint is integrated into grunt, and all we need is to create a .jshintrc file, and configure it with the rules (which you can read from their <a href="http://jshint.com/docs/options/">docs</a>).</p><p>One example we used:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d8229f9ec5db08565ee09e94139c7a7/href">https://medium.com/media/2d8229f9ec5db08565ee09e94139c7a7/href</a></iframe><p>There are many other tools that have similar functionalities to JSCS and JsHint, like <a href="http://www.jslint.com/">JsLint</a>, <a href="http://eslint.org/">ESLint</a>, among others. You can try all of them and use the one that fits you best!</p><h3>C#</h3><p>In C# the story is a little bit different: From the beginning, many errors that might happen in javascript don’t occur in C#, due to the simple fact that it is a <a href="https://en.wikipedia.org/wiki/Type_system#Static_typing">statically typed language</a>.</p><p>Type safety prevents us from using variables which are not declared, or casting incorrectly types. Plus Visual Studio is a very smart IDE and will catch many pitfalls. But what about styling conventions? That is still a problem difficult to detect. What if there are arguments not declared? Pieces of code that never run? What if some pieces can be written in a most efficient way (like using <a href="https://msdn.microsoft.com/en-us/library/bb308959.aspx">linq</a>). What about doing proper handling exceptions ? To accomplish this, two of the tools we extensively use are <a href="https://msdn.microsoft.com/en-us/library/3z0aeatx.aspx">Code Analysis</a> and <a href="https://www.jetbrains.com/resharper/">Resharper</a>.</p><h4>Code Analysis</h4><p>Code Analysis (“CA”) is a static analysis tool that searches for some common patterns or <a href="https://en.wikipedia.org/wiki/Code_smell">code smells</a>. It is integrated with Visual Studio and can be easily added to the compilation process: You only need to configure a set of rules about if those patterns should emit a warning or an error at compile time. The list of rules can be found in <a href="https://msdn.microsoft.com/en-us/library/ee1hzekz.aspx#h2">docs page</a>.</p><p>As already mentioned, the configuration can be exported into a file, in this case a .ruleset. A ruleset is just an XML, in which each node is a pattern or rule, with an unique identifier, and a value indicating if an error or warning will be issued, or if it is going to be ignored. One example of ruleset we used (comments added):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc37ac7b82eaa8902cd7625799028389/href">https://medium.com/media/cc37ac7b82eaa8902cd7625799028389/href</a></iframe><p>In order to create it, you only need to click the option “Add new File” after right-clicking on the solution, and look for the “Code Analysis Rule Set”. Visual Studio editor let us set the action for each rule (Error, Warning, None).</p><p>After that, the only thing we need to do is to go to each project’s properties (the csproj file), right-click on them, and under “Code Analysis” tab search for the file we have created, under the “Code Analysis” section. Remember also to check the option “Enable Code Analysis on Build”.</p><p>And that’s it! Our VS will include these rules at compiling time.</p><p>One thing to notice, there are three modes to compile in Visual Studio. Debug and Debug — CA (for debugging) and Release (which will not emit metadata for debugging). Only the last two will run the Code analysis.</p><h4>Resharper</h4><p>In case your organization has a Resharper licence (and I definitely recommend it!), there is a “Code Editing” section in its option, used to set the styles we want to use. Resharper will use the configuration to autocomplete and format the code as we write. Just like CA, we can save our options so all developers can import them and be on the same page.</p><p>One thing to keep in mind is that both Resharper and CA overlap in some rules definition (like Naming Conventions), so you have to ensure that the configurations is on sync (or set them in only one of the two tools).</p><p>Some other nice features from Resharper are the tools they offer for Refactoring, Unit Testing, and suggestions to improve the code. It is highly recommended!</p><h3>Commit Policy and Continuous Integration</h3><p>Up to now, we have seen that most of the tools mentioned above allow developers to write code locally in their environment, and run the linters and CA after that. But this has a problem: It leaves most of the responsibility to the programmer. What if (whatever the reason) he ignores the process?</p><p>In case your project/organization has a <a href="https://blog.quadiontech.com/continuos-integration-320ecefaf8a3">Continuous Integration</a> area, you can run these tools (CA, linters) in the CI tool you used to generate new versions of the software, and throw errors in case any failure or inconsistency within the styles are found. This makes the build fail, and forces developers to fix the problem.</p><p>And going one step further, Visual Studio allows you to add <a href="https://www.visualstudio.com/en-us/docs/tfvc/add-check-policies">Check-In Policies</a>, so that devs must go through CA before committing their code. This is a way to prevent some mistakes from reaching the CI environment. Regarding the linters, we have seen how to run them through the NPM console, but there are some plug-ins that let the Visual Studio show the linter’s errors in the Error Tools (like <a href="http://vswebessentials.com/download">Web Essentials</a> and <a href="https://marketplace.visualstudio.com/items?itemName=LukePage.JSLintVS2012">JsLint Extension</a>) after compilation. One thing that is worth considering is that this will run the linters everytime you hit “Compile” in the IDE, even in the case you haven’t touched any javascript!. If your js codebase is large, it may add a couple of minutes to your compilation process, and you might prefer to run them manually only when it is really needed. It is up to what your team prefers.</p><h3>Summary</h3><p>To sum up, it is important that styling conventions have an unified criteria about how to write code. It will add coherence to your source code, improve your experience of reading the code, and improve the maintainability in the mid and long term. Readability is very important, and automating most tasks that improve it is something that is definitely worth the shot. It is easy to implement (as we have seen here), and there plenty of tools for your language of choice. Of course it is not a silver bullet: to continue improving your code’s quality you will also have to consider periodic reviews, refactorings when needed, and whatever you think it will improve your codebase. Maintaining your codebase quality is a long road to travel!</p><p><em>[1]</em><a href="#51c5"><em>^</em></a><em> </em><a href="http://scottdorman.github.io/2007/06/29/Why-Coding-Standards-Are-Important/"><em>http://scottdorman.github.io/2007/06/29/Why-Coding-Standards-Are-Important/</em></a></p><p><em>[2]</em><a href="#9655"><em>^</em></a><em>Keep in mind that sometimes less code does not mean more readable code. So you will need to find the balance that works for you and your team.</em></p><p><em>© Quadion 2017. All rights reserved.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qAvN0hRAPWRdNTsDqeBzog.png" /></figure><h4>Thanks for reading our post!</h4><p>Would you like more information? Do you need our help?</p><figure><a href="https://www.quadiontech.com/nearshoring"><img alt="" src="https://cdn-images-1.medium.com/max/297/1*FJfe4Ph2xplYxq4oDWIpSg.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qAvN0hRAPWRdNTsDqeBzog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*Wi2m6yKYxXmF4eevLufkZw.png" /></figure><p>New York, USA +1.212.202.0568<br>Buenos Aires, Argentina +54.11.5031.2930<br><a href="http://www.quadiontech.com/">www.quadiontech.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca02ba794274" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quadion-technologies/writing-code-unifying-your-codebase-conventions-ca02ba794274">Writing code: Unifying your codebase conventions</a> was originally published in <a href="https://medium.com/quadion-technologies">Quadion Technologies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>