<?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 Darlan Alves on Medium]]></title>
        <description><![CDATA[Stories by Darlan Alves on Medium]]></description>
        <link>https://medium.com/@angularjsdev?source=rss-87035592d19a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0GimSH8r7BQ1bZyrWighvg.jpeg</url>
            <title>Stories by Darlan Alves on Medium</title>
            <link>https://medium.com/@angularjsdev?source=rss-87035592d19a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 01:43:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@angularjsdev/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[Os 10 mandamentos da programação]]></title>
            <link>https://medium.com/@angularjsdev/os-10-mandamentos-da-programacao-3e795c536bee?source=rss-87035592d19a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e795c536bee</guid>
            <dc:creator><![CDATA[Darlan Alves]]></dc:creator>
            <pubDate>Mon, 08 Dec 2014 23:18:11 GMT</pubDate>
            <atom:updated>2015-12-19T14:31:51.897Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Se está difícil, está errado. Se o problema parece complicado demais pra resolver, ou você não sabe exatamente o que está fazendo ou você está fazendo alguma coisa da forma errada.</li><li>Não assuma. Descubra qual é o problema real e valide sua solução primeiro. Só então, faça um protótipo, comece a testar e medir os resultados. Com isso você gasta menos tempo e aprende mais no processo.</li><li>Não faça coisas mais de uma vez. Faça o possível pra manter seu código isolado, com poucas dependências e reusável. Mantenha também a coerência: não use mais de um padrão em um mesmo projeto.</li><li>Não reinvente a roda. No entanto, sempre que tiver um tempinho, desmonte a roda e veja como funciona. Talvez você ache um jeito de fazer uma roda melhor no processo!</li><li>Tente manter as coisas simples. Tudo deveria ser feito da forma mais simples possível, mas não mais simples que isso.</li><li>Sempre deixe o código que você mexeu mais limpo e organizado do que quando você o encontrou.</li><li><a href="http://www.software-quot.es/the-most-important-single-aspect-of-software-development">Saiba exatamente o que você vai fazer</a>. Não comece a escrever códigos como se fosse um maníaco pra depois corrigir as falhas. Comece com alguns rabiscos no papel de como as coisas vão funcionar. Isso vai ajudar muito na montagem de um modelo mental do seu problema. Só então escreva a solução!</li><li><a href="http://blog.codinghorror.com/coding-for-violent-psychopaths/">Sempre escreva seu código pensando que a pessoa que vai mantê-lo depois é um psicopata violento que sabe exatamente onde você mora.</a> Ou seja, pense na equipe também, não faça só o que você acha melhor.</li><li>Não comente seu código a menos que seja realmente necessário. Se o código não está claro, ou se você não tem certeza se outras pessoas vão entender o que ele faz, tente reescrever de uma forma mais limpa primeiro.</li><li><a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/">O melhor código do mundo é aquele que não existe</a>. Código-fonte é difícil de manter, e fica obsoleto muito mais cedo do que você imagina. Tente achar meios de tornar o código mais elegante, menos verboso, e com o tempo você vai escrever menos e seu código vai ser melhor.</li></ol><p>Essas são as 10 regras que eu tento seguir no dia a dia dessa profissão de malucos. E você? Tem suas regras também?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e795c536bee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ten Commandments of Programming]]></title>
            <link>https://medium.com/@angularjsdev/ten-commandments-of-programming-ea4b86fd54a7?source=rss-87035592d19a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea4b86fd54a7</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Darlan Alves]]></dc:creator>
            <pubDate>Mon, 08 Dec 2014 01:48:21 GMT</pubDate>
            <atom:updated>2020-07-30T15:31:53.075Z</atom:updated>
            <content:encoded><![CDATA[<h2>10 Commandments of Programming</h2><p>10 rules that will help you with being a good, professional and efficient developer.</p><ol><li><strong>If it’s hard, it’s wrong.</strong> <br>If a problem seems too hard to tackle, either you don’t know exactly what you are doing or you are doing it wrong.<br>Break down your problem into smaller pieces and try to decouple everything. Writing pseudocode, creating aPoC and talking about your solution to a colleague are great ways to check if you’re going in the right direction.</li><li><strong>Don’t reinvent the wheel.<br></strong>We love coding. Yes, we do. But writing our own solution to everything just because we want it to be exactly like “this” or “that” is a waste of time and money.<br>But you <strong>should reinvent things</strong> from time to time, just for fun. You will understand how things work to the tiniest detail. And you can only innovate or improve on things that you know very well.</li><li><strong>Never stop learning.<br></strong>Programming is hard. Thinking about all possible ways that something can go wrong is exhausting. Dealing with edge cases and crazy users is an insanity. But you will have to spend some time out of that madness to keep learning new things.<br>Try a new framework, write pet projects, fill your Github account will endless crap that no one will ever see. That’s gonna be great for your one day, when you face a problem and “Aha, hold on!”, you know how to fix it because you tried that before.</li><li><a href="http://www.software-quot.es/the-most-important-single-aspect-of-software-development"><strong>Always be clear about what you are doing</strong></a><strong>.</strong> <br>Don’t start coding until <a href="https://8thlight.com/blog/uncle-bob/2014/01/27/TheChickenOrTheRoad.html">you know exactly</a> what needs to be done. <br>There’s nothing worse than someone writing code at random and just hoping it will work at some point.<br>That only adds up to a pile of unmaintainable mess.</li><li><strong>Don’t repeat yourself</strong>. <br>Reuse everything you can and keep things coherent. But don’t go too crazy either.<br>The whole point here is… if you need to change something, you should have to change it only in one place. Otherwise, you will make mistakes.</li><li><strong>Write tests for everything.<br></strong>Not a single line of code should go to production without some form of testing. And don’t trust your coverage either!<br>Code Coverage is a lie you tell yourself. Is just code porn.<br>Make sure you write a test, then write a line of code to pass that test.<br>Only this way you will know for sure that every single thing in your system is tested.</li><li><strong>Don’t comment, unless you really, really need it. <br></strong>Unless something incredibly hard to understand is part of your job, no comments should be tolerated.<br>Long if condition? Write the condition to a local constant that explains what’s that.<br>Weird algorithm. Write a function name that explains what it does.<br>Comments rot, and very fast</li><li><a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/"><strong>The best code is no code at all</strong></a><strong>.</strong> Code is hard to maintain, so whenever possible, don’t write it. Think how you can make it both more elegant and less verbose, and over time, it will shrink and work better.</li><li><strong>Always leave the code you changed cleaner than you found it.</strong> (a.k.a <a href="http://programmer.97things.oreilly.com/wiki/index.php/The_Boy_Scout_Rule">Boys scout rule of programming</a>)</li><li><strong>Stick to the rules!<br></strong>Discipline will pay off in quality and clarity over time. Things should be black and white: if you establish a rule, follow it to the letter.<br>Why? Because you don’t have to think about it. Your precious brain juice is better spent on things that you DO have to think about.</li></ol><p>These are basically the rules I try to follow when coding.</p><p>—<br>Also recommended: Watch this series of Clean Code talks from Uncle Bob:</p><p><a href="https://www.youtube.com/watch?v=7EmboKQH8lM&amp;t=1s">https://www.youtube.com/watch?v=7EmboKQH8lM</a><br><a href="https://www.youtube.com/watch?v=2a_ytyt9sf8">https://www.youtube.com/watch?v=2a_ytyt9sf8</a><br><a href="https://www.youtube.com/watch?v=Qjywrq2gM8o&amp;t=2301s">https://www.youtube.com/watch?v=Qjywrq2gM8o</a><br><a href="https://www.youtube.com/watch?v=58jGpV2Cg50">https://www.youtube.com/watch?v=58jGpV2Cg50</a><br><a href="https://www.youtube.com/watch?v=sn0aFEMVTpA">https://www.youtube.com/watch?v=sn0aFEMVTpA</a></p><p>Update: I found <a href="http://www.makinggoodsoftware.com/2009/06/04/10-commandments-for-creating-good-code/">this article</a> with another list of good rules to follow. Check it out!</p><p>Update 2: a <a href="https://medium.freecodecamp.com/good-code-vs-bad-code-263f71e867c1#.ln2eeq5fh">great checklist for good code</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea4b86fd54a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Less AngularJS, more Javascript]]></title>
            <link>https://medium.com/@angularjsdev/less-angularjs-more-javascript-ab756cfb81?source=rss-87035592d19a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab756cfb81</guid>
            <dc:creator><![CDATA[Darlan Alves]]></dc:creator>
            <pubDate>Mon, 03 Nov 2014 07:50:42 GMT</pubDate>
            <atom:updated>2018-01-05T12:12:10.303Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been wondering in the last weeks about a different approach on how we write our AngularJS stuff.</p><p>TL;DR: you could use annotations to separate your code and the framework syntax as much as possible.</p><p><strong>Update:</strong> I’ve created <a href="https://github.com/darlanalves/angular-di-annotations">a lib/node module/gulp plugin that converts the comments</a> into AngularJS syntax ☺</p><p>— If you want to see it in action, check this project:<br><a href="https://github.com/darlanalves/angular-repository">https://github.com/darlanalves/angular-repository</a></p><p>In the AngularJS world we have a module system that holds <strong>services, controllers, filters, </strong>and<strong> directives</strong>. Services have a little variation of syntax, so we also have <strong>factories, values </strong>and <strong>providers</strong>. All this stuff is essential part of the framework’s inner working, and they all have a way to be declared imperatively. Most of them, however, are not really AngularJS “things” but general concepts that we know already from MVC. The code goes like this:</p><pre>var $module = angular.module(&#39;module.name&#39;, [&#39;dependency&#39;]);</pre><pre>$module.factory(&#39;ServiceOne&#39;, [&#39;OtherService&#39;, function(a) {}]);<br>$module.filter(&#39;filterName&#39;, function() {});</pre><p>AngularJS syntax is not a big deal here, but we have some things that need to be done properly to avoid problems when our code is shipped for production.</p><p>One of this things is the array syntax, as seen in the factory above. To make sure the first parameter passed in to the factory is the “<em>OtherService</em>”, we have to annotate it in a specific format, in this case using an array and naming the dependency as string. This is both boring and error prone, also breaking one of the fundamental laws of code: DRY (don’t repeat yourself)!</p><p>To circumvent that, we have the awesome <a href="http://npmjs.org/package/ng-annotate"><strong>ng-annotate</strong></a> project, which does it automagically. But that’s not enough, as we still have to write this imperative declarations everywhere and this code ties the entire project to AngularJS in some way.</p><h3>So what’s the idea?</h3><p>I’ve been a PHP programmer before working with AngularJS, and one of the nifty things I did back then was to declare some things with <em>docblocks</em>, like Doctrine entities, event listeners, documentation tags for <em>PHPDoc</em>, and so on.</p><p>I also worked with <strong>ExtJS</strong>, a great framework from Sencha that has a super-duper documentation tool called <a href="https://github.com/senchalabs/jsduck"><strong>jsDuck</strong></a><strong>. </strong>This tool generates documentation pages right from the source, reading the same docblocks. So, why don’t we use that for AngularJS too?</p><p>Instead of writing this AngularJS specific syntax, why don’t we <strong>declare it instead </strong>to later be parsed with a plugin in your build tool?</p><p>The point is: the code should not look like it is written for AngularJS specifically. Check the code below:</p><p><a href="http://pastebin.com/KhGQ3SBb">https://pastebin.com/KhGQ3SBb</a></p><pre>/**<br> * @module my.module<br> * @requires foo, bar.baz<br> */</pre><pre>/**<br> * @factory Users<br> */<br>function UsersFactory(DataLayer) {<br>  return {<br>    findOne: function (id) {<br>      return DataLayer.findOne(‘User’, id);<br>    }<br>  };<br>}</pre><pre>/**<br> * @filter toDecimal<br> */<br>function toDecimalFilter() {<br>  return function(data) {<br>    return parseInt(data, 10);<br>  }<br>}</pre><pre>/**<br> * @controller UserEditController<br> */<br>function UserEditController(UserService) {</pre><pre>}</pre><p>Since you no longer have anything that <em>imperatively</em> connects your code with AngularJS, the code becomes cleaner and framework-agnostic. That’s a huge deal in my opinion, since our code becomes nothing but a bunch of functions that create things, much like <em>factories</em>. You just need <a href="https://github.com/darlanalves/angular-di-annotations">a tool to convert the comments to code</a>, which is as simple as a <em>docblock</em> parser walking over files. That’s quite easy nowadays with Gulp or Grunt.</p><p>If you decide to switch to another framework, obviously directives would be not portable, but they are not meant for that, as they are AngularJS-specific. Other stuff, like services, models, filters or controllers, could all be reused. With a little effort, AngularJS core objects, such as the <strong>$injector</strong>, <strong>$http</strong> or <strong>$q,</strong> could also be replaced with other implementations. I wrote <a href="https://github.com/darlanalves/handbag">a simple injector</a> just for fun to see how it works. That could be done with the other core services as well. You could even go nuts and replace the <strong>$compile </strong>service with one that handles the DOM manipulation with a lib like React!</p><p><strong>But why annotations? </strong>Because the new AngularJS version (2.0) will be using them too, as you can see <a href="https://docs.google.com/document/d/1fTR4TcTGbmExa5w2SRNAkM1fsB9kYeOvfuiI99FgR24/edit#">in this design document</a> or test <a href="https://github.com/angular/di.js">with the new injector</a>.</p><p>To extend the same idea, other small decisions can be taken in a project to completely remove any reference to AngularJS from your code. Think about the utility methods that come with the angular and how you could turn them into a injectable object:</p><pre>/**<br> * <a href="http://twitter.com/factory">@factory</a> util<br> * This small object could be replaced with Lo-Dash or Underscore<br> */<br>function toolbeltFactory() {<br>    var Utils = {},<br>        methods = &#39;bind copy equals extend forEach &#39;+<br>        &#39;fromJson toJson lowercase uppercase isArray &#39; +<br>        &#39;isDate isDefined isElement isFunction isNumber &#39; +<br>        &#39;isObject isString isUndefined&#39;;</pre><pre>    methods.split(‘ ‘).forEach(function(method) {<br>        Utils[method] = angular[method];<br>    });</pre><pre>    return Utils;<br>}</pre><p>With this small factory, we can start injecting our tool belt as a dependency. This way you never call a method of “angular” anymore, and your project has little to no dependency at all on the framework.</p><blockquote>Design should be based on application architecture, not framework constraints ;)</blockquote><p>Like it? You should also check the <a href="https://medium.com/@angularjsdev/ten-commandments-of-programming-ea4b86fd54a7">ten commandments of programming</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab756cfb81" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>