<?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 Pedro Abinajm on Medium]]></title>
        <description><![CDATA[Stories by Pedro Abinajm on Medium]]></description>
        <link>https://medium.com/@pedroabinajm?source=rss-d586e2762f00------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-1W-wKYKKVbEEq0OWtZMIg.jpeg</url>
            <title>Stories by Pedro Abinajm on Medium</title>
            <link>https://medium.com/@pedroabinajm?source=rss-d586e2762f00------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:12:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pedroabinajm/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[What makes a good Software Engineer?]]></title>
            <link>https://medium.com/@pedroabinajm/what-makes-a-good-software-engineer-5bf2d7cd32fa?source=rss-d586e2762f00------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bf2d7cd32fa</guid>
            <category><![CDATA[imposter-syndrome]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[soft-skills]]></category>
            <dc:creator><![CDATA[Pedro Abinajm]]></dc:creator>
            <pubDate>Wed, 17 Jan 2024 13:12:48 GMT</pubDate>
            <atom:updated>2024-01-19T11:56:01.764Z</atom:updated>
            <content:encoded><![CDATA[<h4>My Nubank Journey: Main Challenge and Key Learning</h4><p>I’ve been part of a company experiencing rapid growth — more customers, more colleagues. When I joined, we had about 100 software engineers, and we were already patting ourselves on the back for that milestone. Little did we know, the team would skyrocket to over a thousand engineers.</p><p>At that point, the company had already earned quite a reputation for snagging the top-tier software engineers nationwide. Let’s make it clear — I’m not saying every fantastic software engineer in the country worked there, but it’s safe to say everyone working there was pretty damn good. That, at least, was my outsider perspective, and guess what? It turned out to be true when I stepped into the company.</p><h4>The toll I had to pay</h4><figure><img alt="Ugly duckling picture from a Disney movie. In this picture the duck is point to himself with a confusing face" src="https://cdn-images-1.medium.com/max/639/1*cMIkLsj3K0D1SHrpBOrdVw.jpeg" /><figcaption>Am I an imposter?</figcaption></figure><p>Joining the company, given my perspective back then, was a genuinely joyous moment in my career. And trust me, it was, but it had its toll. I never felt like I truly deserved it. I never saw myself as the <em>be-all and end-all</em> of a Software Engineer — the one we often envision as the best. You know, the kind with hacking skills, lightning-fast comprehension, <em>all the answers on the tip of their tongue</em>, a knack for architecture tradeoffs, <em>acing LeetCode challenges</em>, and possessing all the performance tricks to make their code the fastest on Earth. I knew I was none of that. I was aware of it, so that feeling crept in — I <strong><em>needed </em></strong>to prove that I was in the right place at that moment.</p><p>And let me tell you, this feeling of not quite fitting in with these super talented software engineers? It comes and goes, sure, but now it’s way more rare than when I first joined. It took me years and some therapy sessions, though.</p><h4>Unexpected Challenge: The Catalyst for Defining Software Excellence</h4><p>Let’s fast forward to the current year. There’s a working group dedicated to revamping our hiring process due to shifts in the company’s dynamics.</p><p>As usual we’ve got to make sure we cherry-pick the most adequate engineers to our positions. And guess who’s in that group? Yep, it’s me — the same person who didn’t think <em>I</em> was good enough just a few years back. Life has a way of throwing unexpected challenges our way, doesn’t it? Now, here I am, figuring out how to sort through and find the real gems among the candidates.</p><p>So, because of all this, I found myself pondering: <strong><em>what makes a good software engineer?</em></strong></p><h4>My Own Skills Assessment</h4><p>Well, let me kick off by listing what I believe has paved my way to success at the company:</p><ul><li>I do learn fast, maybe not as lightning-quick as some standout individuals, but hey, I get the job done.</li><li>I can sense when a solution is risky, even without having the full knowledge — experience, I guess.</li><li>I care about the future impacts of a solution — I wonder if such a change, perhaps making it look easier or faster, will have worse implications in the future.</li><li>I’m not just comfortable with doing; I want to make sure I understand what I’m doing.</li><li>I’m pretty good at spotting when something is crucial and can shift priorities and focus in an instant.</li><li>I thrive on diving into tough problems, figuring out solutions — that’s what fuels me.</li><li>Making a compelling argument for my solution is my strong suit, mainly because I have a rationale behind it.</li><li>Sharing knowledge is my passion, and I care about it. Passing on what I’ve learned since joining the company fuels my drive to help fellow software engineers who might be struggling just like I once did.</li><li>Visibility matters. I make it a point to ensure others know about the decisions I make.</li><li>Asking for help is my go-to. No point in struggling for too long, right? I ask for help as soon as I need it.</li><li>Being self-aware is my distinct edge. It helps me improve faster because I catch my mistakes early on.</li><li>People, I listen to them. I give care to 1:1 meetings — I work hard to understand their frustrations, often listening to the unspoken.</li></ul><p>Now, let’s delve into the aspects where I recognize my limitations:</p><ul><li>I’ve never been an outstanding student. Maintaining focus on one thing for an extended period has always been a challenge, making it tougher for me to delve deep into a specific subject.</li><li>Despite my quick learning, when it comes to some complex subjects, I require time to process and reason about it. I won’t immediately engage in reasoning. I need that time.</li><li>Trust is a key factor for me to express myself, especially with those I admire. I prefer to listen to these individuals without immediately questioning their perspective, even though they might be wrong at times.</li><li>Frustration tends to push me towards quick solutions, often leading to hasty decisions or behaviors.</li><li>I can get fixated on an idea, even when it’s not a good one. Recognizing its flaws usually requires me to see it for myself.</li></ul><h4>Journey to Proficiency: Embracing Imperfection</h4><p>In reflection, considering my journey and experiences, I find myself capable of distilling the essential skills that, in my view, define a proficient software engineer. They possess a unique blend of qualities:</p><ul><li><strong>Learn fast:</strong> Rapid adaptability to new concepts and technologies.</li><li><strong>Eager to self-improve:</strong> A constant drive to enhance their skills and knowledge.</li><li><strong>Experienced:</strong> A depth of understanding cultivated through hands-on experience.</li><li><strong>Understand what they are doing:</strong> Comprehensive understanding of the tasks at hand.</li><li><strong>Consider Future Impacts:</strong> They have a forward-looking mindset, assessing the potential long-term consequences of their decisions and questioning the ramifications of seemingly expedient changes.</li><li><strong>Reason about the specifications:</strong> The ability to think critically about project requirements.</li><li><strong>Self-aware:</strong> Insightful understanding of one’s strengths and weaknesses.</li><li><strong>Have a sense of priority:</strong> Skillful prioritization, focusing on what truly matters.</li><li><strong>Take initiative and responsibility: </strong>Proactively address challenges, taking timely actions to solve problems as they arise, often exceeding expected responsibilities.</li><li><strong>Can get deep about difficult stuff:</strong> A willingness and capability to delve into complex technical or business-related challenges.</li><li><strong>Open to change their positions:</strong> Adaptability and flexibility in changing circumstances.</li><li><strong>Can deal with frustrations:</strong> Resilience in navigating challenges that inevitably arise in a work environment.</li><li><strong>Express themselves:</strong> Effective communication of thoughts and ideas.</li><li><strong>Ask questions:</strong> A proactive approach to seeking clarification and understanding.</li><li><strong>Ask for help:</strong> Recognizing the value of collaboration and seeking assistance when needed.</li><li><strong>Care about people around them:</strong> A genuine concern for the well-being and success of colleagues.</li></ul><p>These skills collectively form the backbone of a successful software engineer, acknowledging the multifaceted nature of the role and the importance of both technical prowess and interpersonal acumen.</p><p>Undoubtedly, possessing all these skills is impossible! Yet, here’s the revelation: not having every single one doesn’t diminish your worth. The pursuit of perfection is a mirage. You can be exceptionally good without being flawless. In my journey, I grappled with this realization, and it’s okay if you are too. What I’ve come to understand is that acknowledging imperfections is the first step towards genuine growth. Embrace the fact that nobody is perfect, and that’s perfectly fine.</p><p>As we conclude this exploration of what makes a good software engineer, remember that the heart of the matter lies in acknowledging your strengths, even as you embrace your imperfections. The quest for excellence is a journey, not a destination. While the next post may delve into the intricacies of filtering these qualities in a hiring process, the key takeaway remains: you are valuable and capable, regardless of perfection. For now, let’s reflect on our individual growth, understanding that it’s the journey that shapes us. Keep the focus on what truly matters, and success will inevitably follow.</p><blockquote><strong>Disclaimer: </strong>The opinions expressed in this article are solely my own and do not represent the views of Nubank or my colleagues.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bf2d7cd32fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programmatic layout with Anko]]></title>
            <link>https://medium.com/@pedroabinajm/programmatic-layout-with-anko-4ca3a05dae91?source=rss-d586e2762f00------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ca3a05dae91</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[anko]]></category>
            <category><![CDATA[android-layout]]></category>
            <category><![CDATA[android-xml]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Pedro Abinajm]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 13:59:13 GMT</pubDate>
            <atom:updated>2018-11-28T18:39:36.477Z</atom:updated>
            <content:encoded><![CDATA[<h4>Anko vs XML for Android Layouts</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3Bmd6tqGBOjEdysl" /><figcaption>Much beautiful droid</figcaption></figure><blockquote><a href="https://github.com/Kotlin/anko">Anko</a> is a <a href="http://www.kotlinlang.org/">Kotlin</a> library which makes Android application development faster and easier. It makes your code clean and easy to read, and lets you forget about rough edges of the Android SDK for Java.</blockquote><p>If you try to apply Anko Layouts in an Android project where there are some developers working on you must be ready for a lot of discussions and expect a lot of resistance within the team. It won&#39;t be easy, but I believe its benefits are worth it.</p><p>I&#39;m going to light up some <strong>pros and cons about Anko Layouts</strong>, which I&#39;ve learned with these discussions I&#39;ve had. This way I can leave these lovely discussions public to everyone interested on. Please, feel free to add even more points on the comments section.</p><p>If you don&#39;t know Anko, I recommend these readings so you can fully enjoy this post:</p><ul><li><a href="https://github.com/Kotlin/anko">Anko Library</a></li><li><a href="https://antonioleiva.com/anko-layouts-android/">Most of the discussions I&#39;ve had was based on this guy</a></li><li><a href="https://pt.slideshare.net/mdevtalk/david-bilk-anko-modern-pstup-k-tvorb-layout">Some pretty awesome slides</a></li><li><a href="https://github.com/pedroque/AnkoLayoutsShowroom">Anko&#39;s showcase project</a></li></ul><h3><a href="https://www.w3.org/TR/REC-xml/">XML</a> programmers</h3><p>When I&#39;ve started with Android development, back in 2011, it was pretty common to listen from other frontend developers some jokes about us being XML programmers. <a href="https://blog.codinghorror.com/xml-the-angle-bracket-tax/">XML was never a fully accepted tool between developers</a> since it was replaced for JSON on API&#39;s responses.</p><p>Within XML problems are:</p><ul><li>Not type-safe</li><li>Not null-safe</li><li>Waste of computational resources for parsing it</li><li>Verbosity and complexity</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*KUUjvVHpG-EwMwNXdc0BPQ.gif" /><figcaption>Doing layouts with XML</figcaption></figure><p>But <strong><em>iOS community taught us to be grateful with XML</em></strong>. <a href="https://www.toptal.com/ios/ios-user-interfaces-storyboards-vs-nibs-vs-custom-code">There is a never ending debate amongst them</a> about what is the best way of doing layouts for iOS. That&#39;s because of Apple&#39;s problematic solutions <em>(hey storyboard, I&#39;m talking with you)</em> for it.</p><p>Along the time the one who started doing jokes about it was the Android community. Because we know they would love to have the option of doing their layouts with XML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*f2oWTLi3Tmb2ExsCTDaxOA.jpeg" /></figure><h3>And then Kotlin came</h3><p>Android community is absolutely in love with Kotlin, <a href="https://insights.stackoverflow.com/survey/2018/#most-loved-dreaded-and-wanted">it&#39;s the most loved developers&#39; language</a> just behind Rust. It helped us to avoid Java&#39;s verbosity and being much more productive on our jobs.</p><p><strong>With Kotlin came </strong><a href="https://proandroiddev.com/writing-dsls-in-kotlin-part-1-7f5d2193f277"><strong>DSLs</strong></a><strong>.</strong> It&#39;s an amazing tool for doing complicated things look much more understandable by having a closed scope about what they are supposed to handle. <em>Android community is now doing DSLs for everything you can imagine.</em></p><p>You know, when we have such awesome new technology we want to try it everywhere we can. Why not try to solve our little XML problems with a DSL? For our lucky, JetBrains have already done one, <a href="https://github.com/Kotlin/anko/wiki/Anko-Layouts">Anko Layouts</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Apm1WhxUjUr3R6MK9gfzoQ.gif" /></figure><h3>Anko Layouts, a DSL for doing Android layouts</h3><pre>verticalLayout { //Start a Layout<br>    linearLayout { //Inside one, you can start another one<br>        //Content of layout, like buttons and other things<br>        button(&quot;Some text&quot;)<br>    }<br>}</pre><p>It looks pretty amazing, doesn&#39;t it?</p><p>As it&#39;s Kotlin, every Kotlin benefit comes with it, like:</p><ul><li>IDE&#39;s autocompletion and refactor tools</li><li>type-safety</li><li>null-safety operators</li><li>extensions</li></ul><p>Because of Kotlin’s familiarity it’s much easier to understand what’s happening. It’s really easy to start with it.</p><blockquote><a href="https://antonioleiva.com/anko-layouts-android/"><strong>Using Kotlin code means you can do more complex things</strong>: for instance set a dimension that is the sum of two dimensions, simpler data binding, views are easier to reuse and compose…</a></blockquote><p>I&#39;ve just experienced a layout where we could reuse it fully by just changing its RecyclerView adapter.</p><pre>class SomeLayout constructor(<br><strong>    private val adapter: SomeAdapter</strong><br>) : AnkoComponent&lt;SomeActivity&gt; {</pre><pre>    override fun createView(ui: AnkoContext&lt;T&gt;) = with(ui) {<br>        ...</pre><pre>        recyclerView {<br>            layoutManager = LinearLayoutManager(ui.ctx)<br>            <strong>adapter = someAdapter</strong><br>        }          <br>    }<br>}</pre><p>With an <a href="https://en.wikipedia.org/wiki/Object-oriented_programming"><strong>OOP</strong></a><strong> language</strong> we can achieve amazing things, such as <a href="https://medium.com/@raonivaladares/swift-creating-themes-with-programmatically-ui-3eb6b2c01622"><strong>proper theming</strong></a>. I don’t know you, but I had the bad lucky of changing a theme of a whole app, not once, but twice in my life. It hurts.</p><p>It also comes with some bonuses:</p><ul><li><a href="https://android.jlelse.eu/400-faster-layouts-with-anko-da17f32c45dd"><strong>Performance gain</strong></a><strong>:</strong> Because it skips XML inflation step, our layouts load much faster. Imagine a scenario where we need <strong>dynamic layouts</strong> with a lot of inflations, doing it <strong>with Anko is even faster.</strong></li><li><strong>People have started to review layouts: </strong>it’s much easier to read a Kotlin file compared to a XML, because of a lot of noisy code XML brings with it, so it’s natural that people review it more once they understand it easier. <strong><em>Personal opinion alert:</em></strong><em> I say it by myself as well because I don’t care a shit about how an XML is written as it will be ugly anyway.</em></li><li><strong>Layout class:</strong> with it we can have every view responsibility there <strong><em>e.g.</em></strong> the <em>recycler view set up we usually do inside activity now we can do it on its layout class. </em>This is <strong>separation of concerns</strong>, keeping our <strong>activities dumber</strong>.</li></ul><p>A lot of benefits highlighted here show how Anko Layouts help us identifying reusable and bad code, compose views and applying themes. <strong>With all of these concepts applied</strong> soon we&#39;ll have a project where doing<strong> a layout is totally based on component composing </strong>giving a lot of productivity making us spend <strong>less time writing brackets</strong> and giving us <strong>more time drinking coffee</strong>.</p><h3>What about XML? Should we forget it?</h3><blockquote>Hey, that&#39;s so amazing. Let&#39;s do it!</blockquote><p>Not so fast. XML also has its benefits.</p><p>When XML was created it was made with some <a href="https://www.w3.org/TR/REC-xml/#sec-origin-goals">goals</a> in mind. We&#39;ll talk about some of them:</p><ol><li>The XML design should be prepared quickly.</li><li>XML documents shall be easy to create.</li><li>XML shall support a wide variety of applications.</li><li>XML documents should be human-legible and reasonably clear.</li></ol><p>In fact an XML file is really easy to create, all you need is a single file and it&#39;s done. Even though its verbosity is pretty boring for programmers, it helps to understand what&#39;s happening there with no magic under the hood. It was made so anyone could create and read XML files with no advanced programming skills.</p><p>But the greatest XML advantage is: <strong>Google officially supports it as the tool for layout creation in Android.</strong> We cannot know every reason behind this decision, but I guess much of it was based on that. Maybe Google thought that giving a tool that doesn&#39;t require too much programming knowledge would be a good thing for Android community so we could have some non-programmers working on it.</p><p>Because Google is moving towards XML since the beginning it brings a lot of advantages for this tool:</p><ul><li><strong>Layout preview tool:</strong> writing some layouts blindly, together with long gradle build times is crazy. I still remember the days that XML preview tool was not so good and it was a nightmare. Having it makes you learn fast new layouts and avoid you to wait a couple of minutes to see if what you&#39;ve done is working properly or not. Google also have made some tools to help you mock elements without having the risk to let them forgotten there. <strong>e.g.</strong> tools:text=&quot;Is this working?&quot; tag.</li><li><strong>Some features were made to work with it: </strong>attrs, styles, layout params and many others. It causes some boilerplate and new extensions to be able to work with it on Anko where you can do it with a single tag on XML.</li><li><strong>There are some properties that don&#39;t exist programmatically: </strong>such as android:padding</li><li><strong>Resources qualifiers: </strong>Even though I don&#39;t recommend multiple layout with different qualifiers, it&#39;s pretty easy to create a layout for different Android APIs, for example. You just need to put files with the same name in different folders and ta-da!</li><li><strong>Lint warnings: </strong>try to hardcode a text in a XML file and you&#39;ll get an warning telling you to extract it to a string resource.</li><li><a href="https://medium.com/@elye.project/a-must-know-secret-about-android-view-state-storing-mechanism-139d70487729"><strong>View state saving with IDs:</strong></a><strong> </strong>I&#39;ve learned that recently. If you don&#39;t put your view&#39;s an ID, Android won&#39;t save its states, besides we can do it easily with programmatic layout, it will require us to create one ids.xml file. Again, with XML files it&#39;s just a single tag.</li></ul><p>I&#39;m afraid there are even more stuff I don&#39;t know right now which works better for XML just because Google have made it to work this way. It causes some headache when you want to start doing your layouts programmatically because initial set up is much higher compared to any XML layout.</p><h3>Android community vs Anko Layouts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dhHFujxbnU46BkLxDPUfig.jpeg" /><figcaption>Anko? No! Gimme XML! <strong>ps:</strong> layoutParams and dp are extensions I’ve made</figcaption></figure><p><strong>Without Google support</strong> for programmatic layouts, <strong>Android community is not supporting it</strong> as well. It means that <strong>every new stuff </strong>out there <strong>you&#39;ll need to learn almost by yourself</strong> instead of following a good guide teaching you how to do it.</p><p>Last, but not least. XML is out there solving our problems for a long time, and it’s so far so good.</p><blockquote>Android community is just used with XML</blockquote><p><strong>We’ve learned to love this tool </strong>because it just solves anything we want without too much learning curve. <strong>We’re used with it</strong>, so moving to another technology would require us to basically learn everything from scratch.</p><h3>Should I write layouts with XML or Anko Layouts?</h3><p>Maybe the best solution would be Google enabling us to write our resource files with Kotlin and everything would be amazing. But until there our decision about it must be based on <strong>what problem are we trying to solve?</strong></p><p>On the recent projects I&#39;ve been working<strong> I&#39;ve chosen Anko Layouts</strong> because our company has grown enough and most of our design identity is defined, so we can move to create components based on it.</p><p>It&#39;s important to say that I&#39;m working in a team with more than 10 Android developers so <strong>we have enough people to spend more time creating these components</strong> and prepare our project for a future where a layout creation is just component composing.</p><p>But <a href="https://www.youtube.com/watch?v=EauykEv_2iA"><strong>every decision has a trade off</strong></a>. And it comes with a cost that most of developers don&#39;t know this new technology and it will require training, if company&#39;s employees change frequently it will no more be an advantage and start being a problem for every newcomer.</p><p>This decision has a risk where <strong>you&#39;ll have to learn a new technology from scratch</strong> <strong>and many companies don&#39;t want to take this risk.</strong></p><p>If XML is been working fine for you there’s nothing wrong on that, in fact, <strong>it’s a pretty solid decision to stick with XML right now</strong>. It won&#39;t bring you any problems, just because we&#39;re used with and know how to handle them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ca3a05dae91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Espresso, my test is flaky!]]></title>
            <link>https://medium.com/@pedroabinajm/espresso-my-test-is-flaky-28d20cf9b7b7?source=rss-d586e2762f00------2</link>
            <guid isPermaLink="false">https://medium.com/p/28d20cf9b7b7</guid>
            <category><![CDATA[espresso]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[test]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Pedro Abinajm]]></dc:creator>
            <pubDate>Fri, 24 Aug 2018 22:21:56 GMT</pubDate>
            <atom:updated>2018-08-25T16:58:08.077Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why is so difficult to have deterministic UI tests?</h4><p>When we work with interface tests, on our dream lands, we want to do the simplest thing ever, we just want to search for a component and assert if it’s like we expect it to be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uZwXS3WuCTy5736srEaA7w.jpeg" /></figure><p>If we want to check if a view with id such_a_nice_id is with a text Such a nice text on Espresso, we&#39;ll do like this:</p><p>onView(withId(R.id.such_a_nice_id)).check(matches(withText(&quot;Such a nice text&quot;)))</p><p>Wonderful, easy, simple.. Yeah, until we need to handle with asynchronism…</p><h4><strong>Asynchronism</strong></h4><p>It’s a headache in any UI testing framework. Most of them handle it with timers, most known for Thread.sleep(anyRandomNumber). That’s a nightmare solution as we can’t always be sure if that anyRandomNumber is enough or too much.</p><p>It brings together flaky tests, which we can’t have sure if they will be running safe forever. <a href="https://martinfowler.com/articles/nonDeterminism.html">It’s difficult to trust on flaky tests</a> and we should try to make them as much as reliable as possible.</p><h4>Stop, wait, now you are free to go</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbyGjXp4qzsTG19bKuOx3w.jpeg" /></figure><p>Espresso has a nice way to handle asynchronism, IdlingResource.</p><p>It works like a semaphore. You’ll tell when Espresso is free to run the assertions by making flags on the code, telling whether it’s idle or not.</p><p>Let’s imagine we have a AccountActivity, where the user it’s going to fill a form and click on a button to create its account. Of course, it will go through a network call to create this account and a DialogFragment was added to make sure user wait for it to finish. We need to tell Espresso to wait for it as well, otherwise we can’t be sure if the account was created properly. For our luck it’s possible with IdlingResource.</p><pre>class DialogFragmentIdlingResource(<br>    private val manager: FragmentManager,<br>    private val tag: String<br>) : IdlingResource {<br>    private var resourceCallback: IdlingResource.ResourceCallback? = null<br><br>    override fun getName() = &quot;dialog fragment idling resource&quot;</pre><pre>    override fun registerIdleTransitionCallback(<br>        callback: IdlingResource.ResourceCallback?<br>    ) {<br>        resourceCallback = callback<br>    }<br><br>    override fun isIdleNow(): Boolean {<br>        val idle = (manager.findFragmentByTag(tag) == null)<br>        if (idle) {<br>            resourceCallback?.onTransitionToIdle()<br>        }<br>        return idle<br>    }<br>}</pre><p>This&#39; an IdlingResource which waits for some DialogFragment to be gone. On our test, we just need to register it and, yeah, that dialog which would make our tests flaky, it’s not a problem anymore.</p><pre>@Before<br>fun setUp() {<br>    idlingResource = DialogFragmentIdlingResource(<br>        activityRule.<em>activity</em>.<em>supportFragmentManager</em>,<br>        LoadDialogFragment.<em>TAG<br>    </em>)<br>    IdlingRegistry.getInstance().register(idlingResource)<br>}</pre><pre>@Test<br>fun fillAllFieldsCreateAccount() {<br>    fillCreateAccountForm()<br>    onView(withId((R.id.btComplete))<strong><br>        </strong>.perform(click())<br><strong>    </strong>assertTrue(activityRule.<em>activity</em>.<em>isFinishing</em>)<br>}<br><br>@After<br>fun tearDown() {<br>    IdlingRegistry.getInstance().unregister(idlingResource)<br>}</pre><p>At first glance it’s amazing and wonderful. But I&#39;ll tell you something most of people don&#39;t tell you. <strong>It&#39;s not.</strong></p><p><em>As many IdlingResource you add, slower will be your tests</em>. That’s because when some IdlingResource tells Espresso that it’s not free to go it will wait 5 seconds until check again if it’s idle. So <strong>don’t use it as a silver bullet</strong> that you can spend it everywhere.</p><h4>It should wait, what’s happening?</h4><p>On the example above tests still were flaky and after going crazy, I’ve found out I had to do this change:</p><pre>override fun getName() = &quot;dialog fragment idling resource <strong>%d&quot;.format(hashCode())</strong></pre><p>This hashCode trick was required because if you don’t do it and run more than one test using the same IdlingResource, just the first test would work. That’s because Espresso does some stuff behind to reuse a IdlingResource with the same name (even if you unregister it), causing further tests to fail because IdlingResource already told them they were free to go based on our first test.</p><p>IdlingResource also requires knowledge about the code you’re going to test. If you don’t know the code and start writing tests, you may face a flaky test and you’ll be like <em>“Wtf, it was working, there’s nothing here to make it flaky”.</em></p><p>You’ll need to go though the code, hunting the responsible for this flakiness. I’ll tell you, it’s going to take a long time, and it will be very frustrating. <strong>Make sure to know very well the code you are going to test.</strong></p><p><strong>L</strong>ook for asynchronous makers, such as animations, network calls or threads and remove that code just to check if it’s the responsible for the flakiness. Remember that it might has more than one responsible.</p><h4>Animations</h4><p>Sometimes we need to wait some animation to finish to be able to make an assertion. I&#39;ll give you a very good tip, if you use ObjectAnimator you can disable them by adding it on your gradle:</p><pre>android {<br>...</pre><pre><strong>    testOptions {<br>        animationsDisabled = true<br>    }</strong></pre><pre>...<br>}</pre><p>If you use ViewPropertyAnimator it won&#39;t work and you&#39;ll need an IdlingResource to wait for the animation, avoid it if possible.</p><h4>Network Calls</h4><p>There isn’t any magic here. Every situation will need its solution.</p><p>If you do your network calls with Rx, than you can do this:</p><pre>class MyTestRunner : AndroidJUnitRunner() {<br>    override fun onStart() {<br><strong>        RxJavaPlugins.setInitComputationSchedulerHandler(<br>            Rx2Idler.create(&quot;RxJava 2.x Computation Scheduler&quot;)<br>        )<br>        RxJavaPlugins.setInitIoSchedulerHandler(<br>            Rx2Idler.create(&quot;RxJava 2.x IO Scheduler&quot;)<br>        )</strong><br>        super.onStart()<br>    }<br>}</pre><p>Now your Rx calls will notify Espresso when it’ll be idle.</p><p>If you use OkHttp , you can use <a href="https://github.com/square/okhttp/tree/master/mockwebserver">MockWebServer</a>. But it comes with a trade-off, you are not going to test API-Client integrations anymore. If you API changes the json, without the client knowledge, it will crash and your tests will not tell you. This decision depends on what you expect your tests to cover.</p><p>If you use Dagger2 you can <a href="https://android.jlelse.eu/testing-your-app-with-dagger-2-c91cdc0860fb">mock modules</a>. It’ll cover your code even less than MockWebServer, but this solution is, for sure, the easiest to have deterministic and fast tests.</p><p>Or you can have an IdlingResource just like DialogFragmentIdlingResource above and wait for some view indication to tell Espresso when it&#39;s finished. That&#39;s the slowest and hardest solution tho.</p><p>I can’t post here every solution for every problem, but I hope some of them helped you.</p><h4>Hunt for determinism, with care</h4><p>If a test fails once in a hundred, don&#39;t go crazy, take a look if it worths a fix, but if you can&#39;t fix it, I&#39;m going to share with you a small rule for this situation, <strong>always think your code is the responsible for a test failure. </strong>Make sure it&#39;s not, and if it isn&#39;t just run the test again.</p><p>Besides it will be hard, it will be high rewarding. There’s nothing more beautiful than a reliable test.</p><blockquote><strong>A test you can trust is a code you can trust.</strong></blockquote><p>If you trust your code, you can do every new amazing stuff developers are talking about, without fearing it breaking your code.</p><p>Write tests, make them reliable, trust your code and change it. Evolution is only possible with changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28d20cf9b7b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Homo Programmis]]></title>
            <link>https://medium.com/@pedroabinajm/homo-programmis-49caf786eb8c?source=rss-d586e2762f00------2</link>
            <guid isPermaLink="false">https://medium.com/p/49caf786eb8c</guid>
            <category><![CDATA[evolution]]></category>
            <category><![CDATA[empathy]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Pedro Abinajm]]></dc:creator>
            <pubDate>Mon, 20 Aug 2018 17:06:34 GMT</pubDate>
            <atom:updated>2018-08-30T14:38:28.355Z</atom:updated>
            <content:encoded><![CDATA[<h4>Do a better code review by having empathy</h4><p><a href="https://pt.wikipedia.org/wiki/Homo">There are at least 17 Homo species who ever inhabited Earth discovered until now.</a> We, as Homo sapiens, were able to evolve and dominate this planet, but why? What make us so different which turns us the only survivor among every Homo species?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*On4MaeEn1E6o_4CvthiBbg.jpeg" /></figure><p>We have a great collaboration ability. We’re masters on it. We can work together and have great capabilities of socialisation. <strong>Everyone is doing what’s better on, separating responsibilities for everyone’s benefit.</strong></p><p><em>It’s pretty easy to apply this concept on our workday,</em> as programmers, we do it in a daily basis. We work with designers, QAs, product managers, backend, frontend and mobile developers. Everyone knows how to do its job. Some products would be impossible to do with another people helping us on what we’re not capable of.</p><p>But we weren’t and still aren&#39;t the only who knows how to work as a group. Neanderthals used to work together in small groups, <a href="https://www.chimpworlds.com/chimpanzee-social-structure/">chimpanzees have a pretty organised society</a> and even ants are capable of working together as they were only one animal composed by thousands of them.</p><blockquote>So why? Why are we that amazing? Is it just because we’re more intelligent than any other animal who ever lived here?</blockquote><p>That’s impossible to measure but estimative shows that neanderthals used to have about the same brain size compared to us. And even so, what have made us develop this huge intelligence?</p><h4>Empathy to learn</h4><p>We cannot know too much about how our old cousins used to live. But we know somethings. We know that they used to live in smaller groups and even being of the same specie every group seemed to <a href="https://phys.org/news/2012-05-success-homo-sapiens-due-spatial.html">live far from each other</a>.</p><p><a href="https://www.lifezette.com/2017/10/is-empathy-a-biological-fact-of-human-nature/">Some specialists argue that we have one skill more developed on us than in any other animal</a>. And that’s <strong>empathy</strong>. <em>We have empathy enough to share knowledge to other human beings even if we don’t know them very well.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lc6eohzZZHKNZ5iL" /><figcaption>“A woman and a child sitting in chairs opposite to each other and playing” by <a href="https://unsplash.com/@freestockpro?utm_source=medium&amp;utm_medium=referral">Alexandr Podvalny</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><em>Have you felt anything about those persons in this picture above? If you have, congrats, only we, as animals, are capable of it just by looking at someone else&#39;s picture.</em></p><p>Besides many people think of programmers being introspective or people who aren’t capable of socialisation (and it may be true for a large amount of us) <strong>empathy and socialisation is in our DNA</strong>, that’s our nature. If so, we can build it.</p><p>Without empathy our sharing knowledge skill won’t reach its full potential. And even tools which purpose is to do it, like <strong>code reviews</strong>, will fail if we don’t practice how to be empathic with our team.</p><h4>Code Review</h4><p>When code review started to be a thing it was just to assure product quality by having another people looking at your code searching for errors. But sooner it was spread among developers another advantage was noticed. It was a great tool for <strong>sharing knowledge</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c5JdHTCCpa3hFtSn" /><figcaption>Photo by <a href="https://unsplash.com/@nesabymakers?utm_source=medium&amp;utm_medium=referral">NESA by Makers</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Raise team quality always has been a manager&#39;s concern. And one of the most difficult to succeed. As code review showed everyone its great capability for this purpose nowadays this&#39; the reason most of companies adopt this practice.</p><blockquote>We can’t share knowledge if we aren’t empathic</blockquote><p><strong>There’s a selfish reason to be selfless.</strong> And that’s if you’re able to listen other people you’re able to learn with them.</p><p>One of the main issues of code reviews is that it happens online, and is pretty noticeable that internet is a very toxic environment. It happens because face-to-face interactions are very important to create empathy as it’s much easier to notice people emotions.</p><p>But there still are examples of people being empathic there. That’s because some people are capable of sharing experiences to connect with each other, and it builds empathy. <strong>We can be empathic with words depending on what they’re saying to us.</strong></p><p>To develop this empathy we must always try to understand the reasons behind someone else&#39;s solution. Ask yourself <em>what&#39;s happening, why, try to be the person behind that code. Always </em><a href="https://en.wikipedia.org/wiki/Wikipedia:Assume_good_faith"><strong><em>assume good faith</em></strong></a><em>. </em>People are always trying to do their best, and if they aren&#39;t it has to be for a reason. Are they with personal problems?</p><p>Code review isn&#39;t exact, every person is different and we should do it with this in mind.</p><p>Another way to create empathy and trust is by praising efforts and good points. Don&#39;t be that kind of person who only shows yourself to criticise everyone else&#39;s code. In fact, <strong>always praise when possible and avoid criticisms if they aren&#39;t that important</strong> at the moment.</p><p>There are some empathy enablers/disablers studied in online communities, take a look at some of them:</p><p><a href="https://en.wikipedia.org/wiki/Empathy_in_online_communities#cite_note-Rice-6">Empathy enablers</a></p><ul><li><strong>Shared interests. </strong>Because empathy tends to be strongest among those that share common experiences, the presence of niche online communities can set the stage for higher levels of empathy among members.</li></ul><p><a href="https://en.wikipedia.org/wiki/Empathy_in_online_communities#cite_note-Rice-6">Empathy disablers</a></p><ul><li><a href="https://en.wikipedia.org/wiki/Cyberbullying"><strong>Cyberbullying</strong></a> is any bullying that takes place using electronic media. Studies have suggested that individuals who are bystanders, that is, witnessing someone bullying someone else, are less likely to intervene in online contexts.</li><li><strong>I</strong><a href="https://en.wikipedia.org/wiki/Internet_trolling"><strong>nternet trolling</strong></a> is “the practice of behaving in a deceptive, destructive, or disruptive manner in a social setting on the Internet with no apparent instrumental purpose.” Although empirical research on trolling is limited, studies have suggested that internet trolling may be a space occupied by already-sadistic individuals who can easily disrupt conversations and communities.</li><li><strong>Ambiguity.</strong> Because asynchronous, text-mediated online conversations lack the richness of interaction and cues that face-to-face interaction provides, online communication tends to be much more ambiguous. This ambiguity may decrease members’ abilities to find similarities in one another. In both online and offline interactions, increased perceived similarity is associated with increased empathy.</li></ul><h4>Change is the key for evolution</h4><p>Another key factor about Homo sapiens success I&#39;ve been hiding until now is <strong>we would never be able to succeed if we wouldn&#39;t be able to change</strong> and adapt to every situation.</p><p>We, humans, are what our environment is. We hold on ourselves, our family, our friends, our nation, our neighbourhood… That&#39;s a very important factor about <em>Homo sapiens</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B6bAPJEVVS7YuIzjrLN4Eg.jpeg" /></figure><blockquote><a href="https://historynewsnetwork.org/article/158425">As long as Homo erectus did not undergo further genetic alterations, its stone tools remained roughly the same — for close to 2 million years!</a></blockquote><p>We&#39;re capable of evolving without needing to go through a cocoon or change our DNA. That&#39;s because <strong>we change and adapt </strong>according to our environment.</p><h4>Don’t defend your code as it was your child</h4><p>When we advise a code change we are doing it for a reason. Try to understand this reason and be on the adviser&#39; skin. <strong>It’s everyone’s concern to keep the code healthy.</strong></p><p>Remember that <strong>it&#39;s not about</strong> <strong>you</strong> because <strong>your code isn&#39;t yours. </strong>You probably won&#39;t be the person who will be responsible for maintain this code in a couple of years. We need to see our code as it belongs to the team.</p><blockquote><strong>As long as you have learned something, that&#39;s all that matters.</strong></blockquote><h4>Further reading</h4><ul><li><a href="https://medium.freecodecamp.org/unlearning-toxic-behaviors-in-a-code-review-culture-b7c295452a3c">Unlearning toxic behaviors in a code review culture</a></li><li><a href="https://dev.to/vaidehijoshi/crafting-better-code-reviews">Crafting Better Code Reviews</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49caf786eb8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keep it simple as SOLID]]></title>
            <link>https://medium.com/@pedroabinajm/keep-it-simple-as-solid-4973458900d7?source=rss-d586e2762f00------2</link>
            <guid isPermaLink="false">https://medium.com/p/4973458900d7</guid>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Pedro Abinajm]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 20:46:43 GMT</pubDate>
            <atom:updated>2018-08-01T01:49:31.684Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*abpdiog68vX4gqvUwiLlUQ.jpeg" /></figure><p>A friend of mine had joined a company where its developers always complain when he wants to refactor some class to meet SOLID&#39;s principles.</p><p>Most of comments are about giving complexity where there is no need or the lack of time to do such a complex refactor. They don’t see value when he does such a change and face it as a waste of time. We’ll exercise here a class refactor which purpose is to see SOLID’s benefits and why they complain so much about it.</p><h4>SOLID</h4><p>This post requires some SOLID’s knowledge, if you don’t know it very well I strongly advice you to read about it before moving forward.</p><ul><li><a href="https://en.wikipedia.org/wiki/SOLID">Wiki</a></li><li><a href="https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design">Solid Article</a></li><li><a href="https://www.amazon.com.br/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code</a></li></ul><p>As you might know by now SOLID is about five object-oriented programming principles which purpose is to make your code easier to maintain, understand, test and scale. It should be amazing as those purposes are the most pursued when we try to code something. But why so many people complain about it?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cca1fdabb845b85dc4ecbc6fd2d1b4f0/href">https://medium.com/media/cca1fdabb845b85dc4ecbc6fd2d1b4f0/href</a></iframe><p>This class is a Retrofit interceptor used in Android which responsibility is to add headers before any call. It looks inoffensive, but it violates some SOLID principles:</p><ul><li><strong>Single Responsibility Principle</strong> is violated when this class fetchs for header values and adds it to request.</li><li><strong>Open/Closed Principle</strong> is violated because this class will require modification when we need a headers change.</li><li><strong>Dependency Inversion</strong> is also not respected because we have dependencies created by this class with LocationRepository, BuildConfig, GeoHash and TelephonyManager.</li></ul><p>Let’s see a further modification in this class.</p><pre>class HeadersInterceptor(<br>  <strong>private val alternativeHost: Boolean = false</strong><br>) : Interceptor {<br>    override fun intercept(chain: Interceptor.Chain?): Response? {<br>        val request = chain?.request()?.newBuilder()<br>        request?.let {<br>            configureAppHeaders(request)<br>            <strong>if (!alternativeHost) {</strong><br>                configureLocationHeaders(request)<br>            <strong>} </strong><br>            configureDeviceHeaders(request)<br>        }<br>        return chain?.proceed(request!!.build())<br>    }<br>...</pre><p>This simple modification illustrates us what kind of problems violating SOLID could bring. This flag was required because to modify which headers we want, we need to modify the interceptor class. There isn’t any control about what we want to send, the headers are all inside a monolithic class which only trend is to grow more and more.</p><p>It can easily escalate to every class using this interceptor.</p><pre>object ServiceFactory {<br>    fun &lt;T&gt; create(clazz: Class&lt;T&gt;, <strong>isAlternativeHost: Boolean</strong>): <br>        T = getRetrofit(context, <strong>isAlternativeHost</strong>).create(clazz)<br>    <br>    private fun getRetrofit(<strong>isAlternativeHost: Boolean</strong>) =<br>       Retrofit.Builder()<br>            .baseUrl(getEndpoint(<strong>isAlternativeHost</strong>))<br>            .client(getOkHttpClient(<strong>isAlternativeHost</strong>))<br>            .build()</pre><pre>    private fun getEndpoint(<strong>isAlternativeHost: Boolean</strong>)<strong> </strong>= <br>       <strong>if (isAlternativeHost) &quot;alternative_host&quot; else &quot;api_host&quot;</strong></pre><pre>    private fun getOkHttpClient(<strong>isAlternativeHost: Boolean</strong>)<strong> </strong>=<br>       OkHttpClient.Builder()<br>          .addInterceptor(HeadersInterceptor(<strong>isAlternativeHost</strong>))<br>          .build()<br>}</pre><p>Every class will now have a flag leaking to every one who doesn’t even need to know that we may have different endpoints somehow. It will bring boring code because we’ll be forced to add this to a function we don’t need, just because interceptor requires it. That flag is an useless detail we don’t need to know at this moment.</p><p>The first code sample is acceptable and we may choose to keep it, but at the moment we start adding complexity, as the second code sample show us, we should be concerned about SOLID and do a refactor in this class to meet its principles.</p><p>Let’s SOLID it, correcting those violations I&#39;ve mentioned above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d64b29b41309e7fd7c9c5221bf8c56a/href">https://medium.com/media/1d64b29b41309e7fd7c9c5221bf8c56a/href</a></iframe><p>HeadersInterceptor was converted to this nice interface which is closed for modifications and overrides intercept just for adding headers which means it now meets Single Responsibility and Open/Closed (SO)LID’s principles.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03e7b8c1d7f4b433280e372aa6188341/href">https://medium.com/media/03e7b8c1d7f4b433280e372aa6188341/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6610621b444058e9b84c93241cc317de/href">https://medium.com/media/6610621b444058e9b84c93241cc317de/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f7df2e74c39eb3fa619b6824f33e425/href">https://medium.com/media/8f7df2e74c39eb3fa619b6824f33e425/href</a></iframe><p>Now we’ll have a modularised HeadersInterceptor as it will provides us a way to choose which headers we want to send with Dagger’s help, as we used SOLI(D)’s Dependency Inversion Principle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb00146e85958dd1b23b77a3df1ec8b9/href">https://medium.com/media/fb00146e85958dd1b23b77a3df1ec8b9/href</a></iframe><blockquote>Oh no, should we really create all these classes just because of this? It is supposed to be simple, it’s just an interceptor! Keep it simple stupid!</blockquote><h4>IT’S NOT SIMPLE</h4><blockquote><em>What’s simple?</em> That’s the question I usually ask when I face a comment like that.</blockquote><p>What’s a simple code? What we should achieve to meet a simple code? What’s your criteria about it?</p><p>Many people will answer that simple code is easy to write, besides it might looks acceptable, that’s not simple code.</p><blockquote><strong>Simple code is easy to understand.</strong></blockquote><p>Compare every code I’ve posted above and tell me, what’s the simplest interceptor to understand?</p><p>It’s indeed that SOLID adds more difficult to implement, it forces us to think, <strong><em>but wait, is it not what we are paid for?</em></strong> Yes, we&#39;ll add complexity to write this simple class because in the future, someone who doesn’t know you, will have your code to maintain and he will need, more than you, to understand what’s this class responsibility. <em>We are adding complexity to the writer to give simplicity to the reader.</em> That’s what a simple code is about.</p><blockquote>Meh, but now we have to go through much more classes to understand it. It’s not easier to read</blockquote><h4>MANY CLASSES TO READ</h4><p>Why we should know what is HeadersInterceptor doing to add these headers? We just need to know that it adds these headers somehow. If we need to know more, then we’ll look at HeadersInterceptor and it’ll be there.</p><p>Having <em>everything in a single class just brings us details we don’t need or don’t want to know at that moment</em>. It just keeps it confusing and it demands more time to understand than we would take by going through different files. It’s a myth that more files brings more time to understand a code. <a href="https://www.amazon.com.br/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">(Clean Code, pg. 129)</a></p><p>If you are reading an article about cakes you just want to know <em>what’s a cake</em>. We don’t want to know how to do a chocolate cake. If you want details about a chocolate cake then you’ll search for it, or we’ll let it as a recommendation at the end of the article.</p><p>Our code isn’t different, <strong>we’ll give details to people when they want to know these details</strong>, giving needless details is just confusing.</p><h4>SOLID KISS</h4><p>As SOLID goes for a principles set which purpose is to achieve a readable, maintainable, testable and scalable code KISS says to us to keep simple and don’t add complexity where we don’t need it. Take complexity by having a code that does so much, that it’s impossible to understand what’s happening inside it, or when you do that one-liner code which does a lot of stuff, but only you and God <em>(some months later, just God) </em>understand what’s happening there.</p><p>It’s not unusual to hear people complaining about SOLID violating KISS, that’s not true. Both principles can coexist as they go through the same goal.</p><p><em>A code shall be simple, simple to understand.</em></p><p>Some good chocolate cake recommendations below</p><p><a href="http://cristalino.com.br/">Doceria Cristalino - Doces, Bolos e Salgados em Guarulhos/SP</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4973458900d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Packages]]></title>
            <link>https://medium.com/@pedroabinajm/clean-packages-9309cea3f61c?source=rss-d586e2762f00------2</link>
            <guid isPermaLink="false">https://medium.com/p/9309cea3f61c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Pedro Abinajm]]></dc:creator>
            <pubDate>Tue, 26 Jun 2018 16:44:03 GMT</pubDate>
            <atom:updated>2018-06-27T04:16:34.210Z</atom:updated>
            <content:encoded><![CDATA[<p>Packages are one of the most important architecture concerns besides sometimes are demoted to simple directories. We must keep them as clean and cohesive as our code.</p><p>I’ve been working on a legacy project where a lot of people worked on creating packages with their preferences and adding libraries by its own will. It leaded us to a very confusing project where even class creation was difficult because we couldn’t guess where we should create it. Nonetheless there were a lot of libraries responsible to do the same thing in different places.</p><p>Confusing packages may lead to a lot of problems, since duplicated classes, through searching issues until even programming principles violations, such as <a href="https://en.wikipedia.org/wiki/Single_responsibility_principle">SRP</a> or <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">SoC</a>.</p><p>I’ll explain a little bit about the current most used Android package design to show why we’re using it and its benefits.</p><h4>Let’s begin with the three major packages:</h4><ul><li><strong>Domain</strong> — This package represents our core business layer (UseCases, Interactors, Models, …)</li><li><strong>Data</strong> — Data fetching layer (Database, Network, Preferences, …)</li><li><strong>Presentation</strong> — Android user interface layer (Activity, Fragment, Dialog, Services, Views, …)</li></ul><h4><strong>Domain</strong></h4><p>It’s the first one not by accident. It’s indeed the most important one. Here we’ll have two major rules:</p><ol><li>It <strong>should</strong> be framework agnostic.</li><li>It&#39;s our core business layer, every business rule should be here.</li></ol><p>Why do we want it to be framework agnostic? Well, <strong>frameworks are evil! </strong>They change, they have problems, we can&#39;t control them. If you are an experienced developer ask yourself how many times have you changed your frameworks? How many times frameworks you use have changed or even deprecated? We don&#39;t want these changes to impact our source code in a way we should do it in every layer. A framework agnostic domain help us achieving this. It will push all framework handling to the corner layers (data and presentation) and it will guarantee us, for example, that if our database framework it&#39;s changed it&#39;ll only impacts data layer. Our business core and view will be untouched.</p><p>There are some exceptions, risky, yes, but there are. In Android, for example, we&#39;re used to add Rx framework on it. Risky, because if we decide to rip off Rx from our project… Well, we probably won&#39;t…</p><p>There is a small thumb rule, if you need a file that we&#39;ll be shared through all layers and it&#39;s framework agnostic than it probably must be placed here.</p><p>Every communication with domain must be through its models, they are its input and output. They&#39;re very important in our attempt to take frameworks out of here.</p><p><strong>Packages</strong></p><p>Inside domain we usually focus on its <strong>models</strong>, they are the stars, it&#39;s recommended that they should be in its root because they easily show to our developers what the project is talking about.</p><ul><li><strong>repository — </strong>It contains all of our repository interfaces. They must be here because our use cases need them and domain don&#39;t want to know anything about how it&#39;s implemented. So their implementations we&#39;ll be on data layer.</li><li><strong>interactors — </strong>Here we&#39;ll have our use cases and business classes. If there are more than one architecture in our project than we must group up every different interactor pattern in its own package inside here.</li></ul><h4><strong>Data</strong></h4><p>It keeps our data fetching, storage and everything related to it. Through network, cache, database, preferences and anything else correlated to data storage.</p><p><strong>Packages</strong></p><ul><li><strong>entity</strong> — Data models, which we usually translate it to JSON or database representations. They must be data classes with any other responsibility. Inside here you may have different subpackages for different entities. For example, if you have a database representation entity, than it should be inside a package telling us from which framework it comes from. The same is true for network representation entities.</li><li><strong>entity.converters — </strong>It will contain classes with the responsibility to convert our data entities to domain models. Converters package must be in the same level where the entity which is converting is.</li><li><strong>net — </strong>Every network class will be here. Every package inside here must represent the used framework if there is any.</li><li><strong>preferences — </strong>Here&#39;s where we&#39;ll have our SharedPreferences stuff</li><li><strong>database</strong> — Any database handler must be here. Every package inside here must represent the used framework if there is any.</li><li><strong>repository — </strong>Repositories implementations.</li><li><strong>repository.datasource — </strong>Repositories local and remote data sources. They&#39;ll be here because theirs only usage is inside repositories. Databases, net and preferences might be used only in data source but repository and data source are architectural decisions where preferences, net and database are intrinsic in every project doesn&#39;t matter which architecture we&#39;re using so they need to be architecture agnostic.</li><li><strong>repository.cache </strong>— Repositories cache handlers.</li><li><strong>sync</strong> — Android sync adapters stuff.</li></ul><h4>Presentation</h4><p>Time to Android to shine. Presentations packages will have UI stuff, such as activities, fragments, dialogs, adapters, etc.</p><p><strong>Packages</strong></p><p>Its inner packages must be feature driven. If we have a sign up flow, then we&#39;ll have a signup package containing every sign up class, such as SignUpActivity, SignUpFragment, SignUpService, SignUpPresenter, SignUpAnythingElse.</p><p>This feature driven decision will make or lives easier searching a bug when someone tells us that the user cannot sign up for any reason. And it&#39;s going to scream about our project features.</p><p>Every class that we&#39;ll be used through more than one feature will have its own package e.g. widgets, dependency inversion modules, extensions, common, views or any base class such as BaseActivity, BasePresenter, etc.</p><h4>Exercises give knowledge</h4><p>I&#39;ll let some questions here to help us understanding where every class should be, this way we can have fun thinking where these examples should be placed in this packages design.</p><ol><li>Where should we place crashes reporter and logger classes?</li><li>Where should we place location provider classes?</li><li>Where should we place events tracking classes?</li><li>Where should we place extensions?</li><li>Where should we place presenters?</li><li>Where should we place interactors?</li></ol><p>That&#39;s all folks. Hope I could help you understanding some packages concerns. Anything else? Help me leaving comments :)</p><p>Here is a very good reference about packages principles for further reading: <a href="https://en.wikipedia.org/wiki/Package_principles">https://en.wikipedia.org/wiki/Package_principles</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9309cea3f61c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>