<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: AndroidPie</title>
    <description>The latest articles on Forem by AndroidPie (@groundzerocro).</description>
    <link>https://forem.com/groundzerocro</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F311102%2F7579f62b-9280-4bdd-9242-3776bd79b215.jpeg</url>
      <title>Forem: AndroidPie</title>
      <link>https://forem.com/groundzerocro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/groundzerocro"/>
    <language>en</language>
    <item>
      <title>Crucial bug or the opportunity to make things better</title>
      <dc:creator>AndroidPie</dc:creator>
      <pubDate>Sat, 05 Jun 2021 18:46:46 +0000</pubDate>
      <link>https://forem.com/groundzerocro/crucial-bug-or-the-opportunity-to-make-things-better-43j3</link>
      <guid>https://forem.com/groundzerocro/crucial-bug-or-the-opportunity-to-make-things-better-43j3</guid>
      <description>&lt;p&gt;I've been working on an client project for a few months now, and all this time we tested the code as much as we could, by myself and the client, and unit test coverage was quite high. &lt;br&gt;
Software is working as expected, client is happy and we are ready to go live. Suddenly, a mayor bug. Bug that can't be ignored! Do you take it a an inconvenience that should turn your stomach around, or do you take is as an opportunity to improve the software?  It is after all, your work, you are responsible for it, you should feel anxious when this happens, shouldn't you? It's an uncomfortable feeling.&lt;/p&gt;

&lt;p&gt;In that moment instead of negative look on it, I've tried to take a positive attitude. This looks like a perfect opportunity to revisit feature, where bug is occurring and improve it, and also, fix that darn bug. How often do you have that amount of motivation to revisit and improve code from the past, feature that you thought is done and ready to blast? Let me tell you, there is not better motivation then a crucial bug in your code, code that needs to go live in a few days... &lt;/p&gt;

&lt;p&gt;I have rewritten feature, as I did not like how me from the past have done it, and in the end, code size was smaller, less coupled and database contracts were simplified and more fluid.&lt;/p&gt;

&lt;p&gt;Depending on how you set your mind on a it, a problem can be a great opportunity, not the inconvenience.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Functions should have same level of abstraction</title>
      <dc:creator>AndroidPie</dc:creator>
      <pubDate>Sun, 08 Nov 2020 13:37:42 +0000</pubDate>
      <link>https://forem.com/groundzerocro/function-should-have-same-level-of-abstraction-1omj</link>
      <guid>https://forem.com/groundzerocro/function-should-have-same-level-of-abstraction-1omj</guid>
      <description>&lt;p&gt;Yesterday I've been reading Clean Code, by Robert C. Martin, also known as Uncle Bob, and one of the rules really got my attention:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In order to make sure our functions are doing “one thing,” we need to make sure that the statements within our function are all at the same level of abstraction. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I'd go even step further, and apply this rule not only to a function, but also to a class or specific block of code. Now, this rule is quite important, and it's easy to ignore this code structure requirement. Mixing levels of abstraction within a function or a class is always confusing. Readers may not be able to tell whether a particular expression is an essential concept or a detail. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Switching between levels of abstraction makes code harder to read. While reading the code you have to mentally construct the missing abstractions by trying to find groups of statements which belong together.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Quote from &lt;a href="http://principles-wiki.net/principles:single_level_of_abstraction#:~:text=All%20statements%20of%20a%20method,will%20result%20in%20smaller%20methods."&gt;principles-wiki&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This rule requires a coder to have a discipline. For example, once you realise your class is missing a value, that is easily obtained by a .map function, you will be tempted to do the mapping in your root class like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Presenter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Repository&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getMembersAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getMembers&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getMembers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getMembers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is wrong. In this case, there should be a class strictly responsible for that mapping, and work should be decoupled from the Presenter class. Root class, in our case Presenter class, should &lt;strong&gt;not&lt;/strong&gt; know about the .map function being invoked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Mapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Member&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;)&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Presenter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;mapper&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Mapper&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Repository&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getMembersAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getMembers&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getMembers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getMembers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Code examples in this article do not represent real world examples. Presenter layer should not be injected with a mapper and naming is simplified.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This kind of rule, not only does make our code cleaner and more readable, but it also opens a lot of room for a quality unit testing and higher unit test coverage.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>codequality</category>
      <category>cleancode</category>
    </item>
  </channel>
</rss>
