<?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 Rafael Pinheiro on Medium]]></title>
        <description><![CDATA[Stories by Rafael Pinheiro on Medium]]></description>
        <link>https://medium.com/@rbpinheiro?source=rss-f6f051323d33------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Qvcovy_5369q1Fdn.jpg</url>
            <title>Stories by Rafael Pinheiro on Medium</title>
            <link>https://medium.com/@rbpinheiro?source=rss-f6f051323d33------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 12:17:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rbpinheiro/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[Review your code]]></title>
            <link>https://medium.com/@rbpinheiro/review-your-code-6e43da2f4aba?source=rss-f6f051323d33------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e43da2f4aba</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[good-practices]]></category>
            <dc:creator><![CDATA[Rafael Pinheiro]]></dc:creator>
            <pubDate>Fri, 08 Apr 2016 16:37:33 GMT</pubDate>
            <atom:updated>2016-04-08T16:37:33.455Z</atom:updated>
            <content:encoded><![CDATA[<p>As I finish writing this post, I will review it to check if I can structure it better or if I need to improve the way I am explaining my ideas, and of course for typos and mistakes. This should be the way you write code as well. You are not done when your code works, you are done when your code looks nice.</p><p>How many characters in length do you let your lines go? How well do you organise your code? Is your code open to future demands in features or will the team have to rewrite most of it from scratch? Take some pride on how your code looks.</p><p>Other people will see it and you might need to work on it again. When coming back to fix a bug you are not in the same mindset you were when first spending hours or days working on that feature. Review your code to leave it for the future you, so you can read it easily enough.</p><p>By spending some extra time reviewing what you did when your focus was to develop the logic of how things would work and taking care of bugs, you can focus on other important stuff. Did you miss a situation where a bug might show up later? Is your code good enough in case you need to extend it later?</p><p>I will try to bring it to a more practical scenario and review a real piece of code that I wrote. I like to keep my ajax calls to the server centralized, so in future when I need to change something on how the calls are made I have it all in one place, and not lost somewhere in the code.</p><p>There is a file called “api.js” in a project I am working on, if it grows too much I will split it into multiple files inside an “api” folder. But for now let’s just review it and check if we can make it better.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f696ce8c52b891964267096a9a5fcf2c/href">https://medium.com/media/f696ce8c52b891964267096a9a5fcf2c/href</a></iframe><p>You can see there that I keep the base url for the server on a string and some default options for when making a post call. I am <a href="https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Statements/export">exporting</a> some objects that handles the calls separated by domains and uses the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch">fetch API</a>. Also some <a href="https://jakearchibald.com/2014/es7-async-functions/">async magic</a> there and using the <a href="https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Operators/Spread_operator">spread operator</a> to create new objects extending existing ones.</p><p>Let’s take it one improvement at a time. First let’s move what belongs into a configuration file to it’s place. Luckily I already have a config file set up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81eb8603dcd5f48eb60448cad809aae5/href">https://medium.com/media/81eb8603dcd5f48eb60448cad809aae5/href</a></iframe><p>The API url is now being fetched from the configuration. But I am still calling fetch on a lot of places there, and when different api calls are necessary we will have even more fetch calls. That is not good, the same reasoning that makes me wanna keep all my ajax call on the same place makes me wanna avoid multiple calls to the same api (the fetch API in this case). If I ever need to update the way I am making this call I will have multiple ones, so let’s make it a single one and reuse that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0e944ead621ff65a8447ce1f72f63c2/href">https://medium.com/media/d0e944ead621ff65a8447ce1f72f63c2/href</a></iframe><p>I used <a href="http://www.sitepoint.com/currying-in-functional-javascript/">currying</a> and <a href="https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow functions</a> to create functions that handles get and post calls to the api. Now we need to write much less code when creating a new call, and if I ever need to change the calls to add a dynamic variable such as api version or keys to the calls I just need to do that in the new get and post functions instead of fixing lots of repeated code.</p><p>But we still have a lot of code there that we have to get past when reading the file later and that will require low to zero maintenance, so we can move that somewhere else and transform this file into route declarations for api. I will create an API handling class in my lib folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af6f7393b90af896099d669cf7587167/href">https://medium.com/media/af6f7393b90af896099d669cf7587167/href</a></iframe><p>Now we can even handle multiple APIs by providing a different base url.</p><p>This is how it looks like now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/351f97be3e5d24cb1fcb0e6906a1b48a/href">https://medium.com/media/351f97be3e5d24cb1fcb0e6906a1b48a/href</a></iframe><p>That is way more maintainable, when someone needs to add a new route it’s way easier than before. Anyone that looks at it knows how to do it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e43da2f4aba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Netflix to save the world]]></title>
            <link>https://medium.com/these-fucking-people/netflix-to-save-the-world-d1d7c3481d13?source=rss-f6f051323d33------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1d7c3481d13</guid>
            <category><![CDATA[disruptiveness]]></category>
            <category><![CDATA[information]]></category>
            <category><![CDATA[streaming]]></category>
            <dc:creator><![CDATA[Rafael Pinheiro]]></dc:creator>
            <pubDate>Thu, 03 Dec 2015 02:18:41 GMT</pubDate>
            <atom:updated>2015-12-03T02:18:41.582Z</atom:updated>
            <content:encoded><![CDATA[<p>Across history we can see pretty much the same thing happening over and over, a small group controls information and filters what most people should be able to access. Some even change information to produce their own truths. The information that arrives to you has, most likely, already been modified or filtered according to someone else´s point of view or interest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*uYnOnvHWShl1LFBg2oqbcA.jpeg" /><figcaption>Gutenberg Press</figcaption></figure><p>Around 1439 Gutenberg created a machine that would have a large impact on the world and on how information would be distributed. By making knowledge more accessible, Gutenberg´s new printing system created a revolution disrupting the structure of who hold the knowledge, and empowered the renaissance, the protestant reformation, the age of enlightenment and the scientific revolution.</p><p>In the 60s, the creation of networks of computers was again the beginning of a new disruptiveness, the internet makes information a lot easier to access and allows disruptive technologies and applications to grow faster. Every now and then something new comes up and causes chaos, Napster did it and was ultimately crushed, taxi apps did it for local taxi companies, Uber did it and caused mayhem on the streets when taxi drivers attacked the black cars.</p><p>If we analyze when things similar happened, we always see that by the end it is beneficial for the larger amount of the population and angers the small amount of people that are greatly benefited by how things work as they were before. We should embrace disruptiveness and force the wheels of power to spin on a different direction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*DgzQsGqEd6vZtTzduoXmCA.jpeg" /></figure><p>The uttermost media for misinformation and manipulation nowadays is television. The programming grid being created by the television companies gives them a huge amount of power to manipulate masses. The next big step we all should take is leave the conventional television industry and adopt content on demand, it´s better for you and it´s better for humanity. You should control what information you are going to consume and when you are going to do that, don’t delegate that to a generic commercial programming grid.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1d7c3481d13" width="1" height="1" alt=""><hr><p><a href="https://medium.com/these-fucking-people/netflix-to-save-the-world-d1d7c3481d13">Netflix to save the world</a> was originally published in <a href="https://medium.com/these-fucking-people">These fucking people</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing readable code]]></title>
            <link>https://medium.com/@rbpinheiro/writing-readable-code-3ef226dfa2?source=rss-f6f051323d33------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ef226dfa2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[good-practices]]></category>
            <dc:creator><![CDATA[Rafael Pinheiro]]></dc:creator>
            <pubDate>Tue, 17 Nov 2015 19:32:37 GMT</pubDate>
            <atom:updated>2015-11-23T13:08:03.790Z</atom:updated>
            <content:encoded><![CDATA[<p>When you are starting on something, be it coding or anything else, more experienced people will give you tips so you can avoid future problems, but many times we will ignore those tips because it doesn’t make sense. Till it does, and you regret not doing it right in the first place while you pull your hair off trying to fix things.</p><p>A few years ago I worked on a project that had a few dev teams working together, but each on a different part of the world. A developer from another team was leaving and my team was gonna become responsible for an old software that he was maintaining. Said software was written on a language that I was not used to work with and was using a framework that was long outdated. Fun, right?</p><p>I had to look around in the code for where I should work to fulfil my first task. When I found it, I stood there looking at it for a few minutes, probably, without blinking. If this piece of code were a painting, it would be the restored version of Ecce homo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*p1VPeGfOUNzU-P3_lGfztA.jpeg" /><figcaption>Ecce homo</figcaption></figure><p>The code, if my memory serves me well, was something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72acca595f2256bc48fb16aeae68b5ee/href">https://medium.com/media/72acca595f2256bc48fb16aeae68b5ee/href</a></iframe><p>I have no idea of what this code does, you have no idea of what this code does, and about a week after writing it, the developer who wrote it had no idea of what this code does. After a lot of swearing and debugging I was able to finally follow the code and modify what was needed, but if someone did good code in first place, I wouldn’t spend so much time on it.</p><p>If you think that writing code is hard, as soon as bug reports or change requests comes you will realise that reading it is much harder, and that you should have spent a few more minutes to do it properly.</p><p>Writing readable code will make you write less bugs and fix the existing ones way faster. Here are some tips on how to do it:</p><h4><strong>Meaningful names</strong></h4><p>As you can see from the code up there, the names of variable and methods should, at least, give a tip of what is contained inside of them or of what they do. Avoid variables like “tmp”, “str”, “val” and any that does not describe what is contained in them.</p><h4><strong>Don’t reuse variables</strong></h4><p>Everyone makes the mistake of reusing a variable so they will save memory by not creating a new one or just out of laziness. But that is confusing to whom reads your code, and if you do that inside for loops or some asynchronous code, the chance of you creating a bug are huge.</p><h4><strong>Declare variables at the top</strong></h4><p>When all your variables are declared at the top of the function, the developer who reads it will have a pretty good idea of what it does and how it does it. New variables in the middle of the code makes it confusing and more mysterious.</p><h4><strong>Initialise variables</strong></h4><p>There is no clearer variable declaration than one with a meaningful name and a default value, specially if your language does not declare the type of the variable explicitly.</p><p>Each language treats uninitialised variables differently, causing a different number of bugs on each. You can check the language you work with for potential bugs, or just write better code with initialised variables.</p><h4><strong>Small functions</strong></h4><p>Break your code into small functions that does one thing only. It is easier to understand a meaningful function name being called than having to read your whole code to understand it.</p><p>Simplicity is the key for understandable code.</p><h4><strong>Use return to avoid else</strong></h4><p>You will usually have situations where you should do something if your function argument fits a condition, and do something else if it doesn’t. Giving that your code is divided in small enough functions, you can just do something if that condition is met and return the value inside the if. If the condition is not met your code will continue to execute without the need for an else statement.</p><p>That will avoid deeper nesting.</p><p>Example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7eb58bb1b495b277d0bb20e4573ad3b0/href">https://medium.com/media/7eb58bb1b495b277d0bb20e4573ad3b0/href</a></iframe><h4><strong>Use proper indentation</strong></h4><p>Following the right indentation and the same pattern of indentation over the code will make you eyes scan the code way faster than if you have to check every line for what block of code it belongs.</p><h4><strong>Avoid globals</strong></h4><p>Modifying globals will cause side-effects that are not easy to identify, plus you never know the value of that global inside the scope you are currently in.</p><h4><strong>Pure functions</strong></h4><p>A function is pure if it does not produce any side-effects and does not depends on external conditions such as global variables. All the input should be given via the function’s arguments, and any number of times you give a pure function the same arguments, it will return the same output. That is possible only if you don’t depend on external conditions. This kind of function is predictable and won’t give you surprises, use them whenever possible.</p><h4><strong>Don’t use shorthands</strong></h4><p>The most common shorthand used is the if statement without brackets, because your code will fit in the next line. As soon as your code don&#39;t fit in a line, you might insert more lines of code that will seem to be inside the if block, but they aren’t. Even assuming you are testing your changes to the code, on some situations the undesired effect will not show on that specific test, or you will lose some time debugging your code only to feel stupid when you see that you missed some brackets.</p><p>This is bad:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/865eb2c4c81dabcdea6ea857ec5e2d37/href">https://medium.com/media/865eb2c4c81dabcdea6ea857ec5e2d37/href</a></iframe><h4><strong>Return the callback</strong></h4><p>If the language you are using supports first-class functions, meaning that you can send a function as an argument to another function and call it back with the results instead of returning it, always use a return statement to end the function execution there. You avoid that any undesired code gets executed after you finished what you were doing and the syntax highlight of your editor will make the return statement very visible, so you can identify a lot quicker the exit points of your function.</p><h4><strong>Avoid loops</strong></h4><p>If your language have minimal support for functional programming, at least supporting the map or foreach functions, prefer using that over for and while loops. If you are creating or modifying an array or object inside a loop, your data will be in different dirty states till it is finished. Plus you will need more auxiliary variables and more accessing of array via index.</p><h4><strong>Follow the project’s style</strong></h4><p>You can argue whether you should include the brackets on the same line or not, whether you should use camel-case or not, whether you use tabs or space for indentation, but you can’t use your own style over the current one for a project you are starting at. Mixed style’s will only lead to confusing code.</p><p>Any other tips you think that should have made this list? Don’t agree with any of them?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ef226dfa2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I am an atheist]]></title>
            <link>https://medium.com/these-fucking-people/why-i-am-an-atheist-89d91dde4dd0?source=rss-f6f051323d33------2</link>
            <guid isPermaLink="false">https://medium.com/p/89d91dde4dd0</guid>
            <category><![CDATA[religion]]></category>
            <category><![CDATA[atheism]]></category>
            <category><![CDATA[humanism]]></category>
            <dc:creator><![CDATA[Rafael Pinheiro]]></dc:creator>
            <pubDate>Sat, 14 Nov 2015 22:38:30 GMT</pubDate>
            <atom:updated>2015-11-14T22:43:10.780Z</atom:updated>
            <content:encoded><![CDATA[<p>No, I am not going into whether god exists or not. Maybe the title should have something to do with humanism instead of atheism, but I really wanna focus on how religion never made sense to me and pushed me away from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*jz9Jt1_mNoVn1RNhNm3GLQ.jpeg" /></figure><p>I know religion can be really important for some people, and that it helped many people in times of distress. But that is pretty much where the benefits ends and mayhem starts. Many might have a healthy relationship with religion and church, but that is not the reality of most.</p><p>From now on I will use the word church as a general idea of who dictates the rules for religions, I am not going to go into specific details of different religions. But I am going into their influence on history and everyday life.</p><p>The main social issues that causes, or caused along history, prejudice, deaths or that slowed down our evolution as human beings are racism, male chauvinism, homophobia, transphobia and poor educational systems. I am sure there are more that I am missing, but just think on how the church influenced on each of the items on that list.</p><p>The uttermost form of racism is slavery. Subjugating a whole race or nation was stated as a right on the bible long ago, glad that God decided to remove that part. But the remaining effect of prejudice from slavery times is still very present and is not disappearing any time soon. Using Louis C.K.`s words, it was not a clean shit that you don’t have to wipe.</p><p>Feminism is very strong nowadays, and thank God for that (see what I did there?), because women have been having their dreams, opinions and lives crushed and dictated by men and society for far too long. I am sure that a story about how women were created from men and to serve men does not help with that. A book that says that women should learn quietly with all submissiveness and that they should not teach or exercise authority over a man is surely not going to be on my shelve. Neither will I listen to someone that says that women should cover their whole bodies, head included, so they will not receive flattery or give men, other than her husband, sexual thoughts. As if what other people think or do is her sole responsibility.</p><p>If you live by rules that forbid you of laying with someone of the same sex, don’t do it. But do not enforce that on laws for everyone else that don’t really care for your proslavery, chauvinist and homophobic book. People lay with people of the same sex and that gives them happiness and joy, other people discriminate them and push them to the edge of society causing suffering and deaths. Who should I choose to support? Happiness and joy or suffering and death?</p><p>The earth is not the centre of the universe, the world is round(ish), there is something beyond the sky we see, we should open the human body to study it, that was all heresy and who had a different opinion should be punished. Till it is well proven and it helps people, then the church says “sorry” to all those thinkers and scientists. Humanity has a limit of how fast it is able to evolve it’s knowledge, and it doesn’t help to have the church slowing it down even more.</p><p>For a long time the church was one of the biggest voices on defining the laws of society, those times are known as the dark ages, and they are known like that for a good reason. We never had times where we evolved so slowly and caused so many deaths and violence for foolish reasons.</p><p>Later we have something called the enlightenment, and thoughts prevailed over god-given commands that we should follow sheeply without questions. We once again began to rise as better human beings and expand our knowledge on a much faster pace.</p><p>Once and again the news shows us attacks or wars that are driven by some religion. I believe that as long as we have strong religious leaderships we will have wars and prejudice. History shows us that and I am not foolish enough to doubt history.</p><p>If you usually go to the church or to any place of prayer, think of who are the sinners that you are most distant to and understand the least. Are they gay people, people from another religion, people that have no religion? Grab a chair and sit to talk and understand why they are the way they are, maybe they are not that different from you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89d91dde4dd0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/these-fucking-people/why-i-am-an-atheist-89d91dde4dd0">Why I am an atheist</a> was originally published in <a href="https://medium.com/these-fucking-people">These fucking people</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Would you tell me, please, which way I ought to go from here?]]></title>
            <link>https://medium.com/@rbpinheiro/would-you-tell-me-please-which-way-i-ought-to-go-from-here-2985ef3f503e?source=rss-f6f051323d33------2</link>
            <guid isPermaLink="false">https://medium.com/p/2985ef3f503e</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Rafael Pinheiro]]></dc:creator>
            <pubDate>Wed, 11 Nov 2015 15:09:46 GMT</pubDate>
            <atom:updated>2015-11-11T15:59:05.450Z</atom:updated>
            <content:encoded><![CDATA[<p>More than once someone asked me what they should be learning next. Which isn’t an odd question, specially, if you are a software developer or aspiring to be one. Software development is like a sandbox, and people from everywhere are creating new and exciting things faster than anyone can learn them. New frameworks, technologies and methodologies are invented, recycled and reapplied every day in a lot of different ways and for different purposes.</p><p>The last word from the previous paragraph is actually the keyword for answering this question that torments quite a few of my fellow developers. Unfortunately I don’t really have an answer for you, but I can help you find it.</p><p>And now for something completely different…</p><blockquote>“Would you tell me, please, which way I ought to go from here?”</blockquote><blockquote>“That depends a good deal on where you want to get to,” said the Cat.</blockquote><blockquote>“I don’t much care where–” said Alice.</blockquote><blockquote>“Then it doesn’t matter which way you go,” said the Cat.</blockquote><blockquote>“–so long as I get SOMEWHERE,” Alice added as an explanation.</blockquote><blockquote>“Oh, you’re sure to do that,” said the Cat, “if you only walk long enough.”</blockquote><p>What you just read is a piece of Alice in Wonderland, and if you ask me for directions of where you should be going next I am gonna tell you that it depends a great deal on where you want to get to. If you have not decided yet, it doesn’t matter, but don’t stop learning. Keep learning long enough and you will get somewhere.</p><p>By learning new things you will eventually find out where you want to go, that is when you are ready to find a real answer to that question. Once you know where you wanna get, you will be able to see a lot better what you need to learn and which road you should take.</p><p>If you are able to pin down what kind of company you want to work for, just go through their open positions and make a list of what they expect developers to know. If you want to dedicate your career as a researcher for an specific area, find out what languages and tools are being used on that specific field.</p><p>As a final tip, to really get to your objectives, learn and prove that you can work on what you want before you are given the chance. It surely is nice to show a nice diploma on a job interview and that might impress potential hirers, but if you have developed something on their area, even if it’s a small personal project, it might impress them even more and make of you a safer bet than that guy from the best university but that haven’t dedicated his time for what they are looking for.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2985ef3f503e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>