<?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>DEV Community: Boris </title>
    <description>The latest articles on DEV Community by Boris  (@boryans).</description>
    <link>https://dev.to/boryans</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%2F930743%2F06661d3b-6564-425d-9394-3a776f06b36a.png</url>
      <title>DEV Community: Boris </title>
      <link>https://dev.to/boryans</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/boryans"/>
    <language>en</language>
    <item>
      <title>What time to workout as a programmer?</title>
      <dc:creator>Boris </dc:creator>
      <pubDate>Tue, 31 Jan 2023 19:26:58 +0000</pubDate>
      <link>https://dev.to/boryans/working-out-vs-programming-40co</link>
      <guid>https://dev.to/boryans/working-out-vs-programming-40co</guid>
      <description>&lt;p&gt;Programming is a good way to stretch the synapses between your brain cells but usually comes with a price to pay. As everything in life is Ying-Yang and requires some balance.&lt;/p&gt;

&lt;p&gt;We, humans, are made for work. By work, I mean physical work. If you go a couple of thousands of years into the past you would see that men would fight for food and territory and women would collect berries as well. In other words "You have to deserve your food on the table". Those days are way behind us, but our bodies aren't.&lt;/p&gt;

&lt;p&gt;If you exercise on the daily basis, let's say 15 minutes of stretching or some calisthenics you will achieve a tremendous amount of motivation for other stuff in life. A cure for laziness would be a daily workout. Treat it as a daily stand-up meeting with your team. &lt;br&gt;
Slap that favorite podcast, do some exercises, and thank me later. &lt;/p&gt;

&lt;p&gt;Often decision-fatigue kick in after your busy working hours and you depleted your if-else blocks in your brain. Usually, those logical blocks would re-fill after a good sleep. &lt;/p&gt;

&lt;p&gt;If you are not familiar with decision fatigue you can read more &lt;a href="https://en.wikipedia.org/wiki/Decision_fatigue"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Technical details: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;15 minutes are less than 2% of your day.&lt;/li&gt;
&lt;li&gt;better mood&lt;/li&gt;
&lt;li&gt;good drive to start the day&lt;/li&gt;
&lt;li&gt;keeping your heart happy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What type of workouts are good: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;running (yes, try run 15 minutes with regular pace)&lt;/li&gt;
&lt;li&gt;stretching / yoga&lt;/li&gt;
&lt;li&gt;HIIT(high interval intensity training)&lt;/li&gt;
&lt;li&gt;Tabata&lt;/li&gt;
&lt;li&gt;Jump rope&lt;/li&gt;
&lt;li&gt;Calisthenics circuit training&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Anyway, I suggest that kind of workout be done either fasted as first thing in the morning or first thing after your breakfast. That way you can kickstart your day, get that adrenaline + dopamine booster and you'll be ready to battle the day. Otherwise, decision fatigue will take over especially after long working day.&lt;/p&gt;

&lt;p&gt;Peace&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Early return patterns</title>
      <dc:creator>Boris </dc:creator>
      <pubDate>Mon, 30 Jan 2023 16:57:56 +0000</pubDate>
      <link>https://dev.to/boryans/early-return-patterns-5ejh</link>
      <guid>https://dev.to/boryans/early-return-patterns-5ejh</guid>
      <description>&lt;p&gt;"First write the code for people, then for the machine."&lt;br&gt;
I don't know who originally said this but it's legitasf.&lt;/p&gt;

&lt;p&gt;How many times you saw some piece of code and like what!? What is this supposed to do?&lt;/p&gt;

&lt;p&gt;One good tip that I accepted from a senior developer in my team is to use that early return statement which is my favorite thing if I have small to medium business logic inside my functions.&lt;/p&gt;

&lt;p&gt;You have a function that does something bigger, and it does it well but not too well.&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="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getListOfArticles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hasInternet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Boolean&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;Article&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hasInternet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//big piece of code. Maybe some data manipulation before &lt;/span&gt;
     &lt;span class="c1"&gt;//returning the list of Articles from the API.&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;emptyList&lt;/span&gt;&lt;span class="p"&gt;()&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 OK, but if you want to make life easier for somebody else that will read your code in half a year we can use that early return pattern which comes in handy sometimes and it looks 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="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getListOfArticles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hasInternet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Boolean&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;Article&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;hasInternet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;emptyList&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;//Big piece of code here for manipulating the data&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way is more intuitive to read "if there is no internet,  just return an empty list of articles" or do whatever you need in your app. Just return early as possible and you will make your program &lt;a href="https://www.martinfowler.com/ieeeSoftware/failFast.pdf" rel="noopener noreferrer"&gt;fail fast&lt;/a&gt;.&lt;br&gt;
 That means: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Easier to read&lt;/li&gt;
&lt;li&gt;Easier to spot code smell&lt;/li&gt;
&lt;li&gt;Easier to debug.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's one more interesting example using a happy path design&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"The happy path for a function would be where none of the validation rules raise an error, thus letting execution continue successfully to the end, generating a positive response."&lt;/em&gt;&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="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;logIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argument1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?,&lt;/span&gt; &lt;span class="n"&gt;argument2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?,&lt;/span&gt; &lt;span class="n"&gt;argument3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
 &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argument1&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;argument2&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;argument3&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; 
   &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//do something and log in the user&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// throw exception&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;Now happy path applied:&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="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;logIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argument1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?,&lt;/span&gt; &lt;span class="n"&gt;argument2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?,&lt;/span&gt; &lt;span class="n"&gt;argument3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argument1&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//maybe throw different exceptions&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argument2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argument3&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="c1"&gt;//do the happy path of the function here&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some patterns that are considered as early return: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mauriziopireddu.com/clean-code/the-bouncer-pattern" rel="noopener noreferrer"&gt;Bouncer pattern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://deviq.com/design-patterns/guard-clause" rel="noopener noreferrer"&gt;Guard clause&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Happy path &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You have your own style of writing software but be aware that this is popular for a reason and it has a lot of benefits inside the codebase. It will force you to think more with that "TDD" mindset.&lt;/p&gt;

</description>
      <category>cryptocurrency</category>
      <category>crypto</category>
      <category>web3</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Composition over Inheritance</title>
      <dc:creator>Boris </dc:creator>
      <pubDate>Sun, 09 Oct 2022 21:33:11 +0000</pubDate>
      <link>https://dev.to/boryans/why-composition-over-inheritance-2ne2</link>
      <guid>https://dev.to/boryans/why-composition-over-inheritance-2ne2</guid>
      <description>&lt;p&gt;We should be careful how we construct and design our classes in OOP world. If we have simple application or we are building MVP project I wouldn't even bother with this topic at all since code should be short and workable. But we will leave that for other blog post. Now let's define what are these two concepts.&lt;/p&gt;

&lt;h2&gt;Starting with Inheritance&lt;/h2&gt;

&lt;p&gt;Inheritance is a concept in OOP which one child class(subclass) inherit &lt;strong&gt;everything&lt;/strong&gt; from the parent class(superclass). When we say everything it means, properties and functions of that superclass. The best is to present with the good old example:&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="k"&gt;open&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&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;eat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Njam njam"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Animal&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;bark&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Woof!"&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;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Running.."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Animal&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;meow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Meow!"&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;jump&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Jumping.."&lt;/span&gt;&lt;span class="p"&gt;)&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;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;goofy&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Goofy wants to eat ${goofy.eat()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;dizzie&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dizzie wants to eat ${dizzie.eat()}"&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;We have Animal class as a parent class to the Dog and Cat subclasses. And this is great, we inherited eat() method from the Animal class. &lt;/p&gt;

&lt;p&gt;Now the requirements in the project has changed and somebody wants a robot dog which needs to clean around the house and another robot that play some music! &lt;br&gt;
Ah great... Okay, let's define the same thing as above using &lt;strong&gt;inheritance&lt;/strong&gt;.&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="k"&gt;open&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Robot&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;stop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Stopping"&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;move&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Moving"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DogRobot&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Robot&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;bark&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Woof!"&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;clean&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cleaning around the house"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MusicRobot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Robot&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;playMusic&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"LalaLalLa"&lt;/span&gt;&lt;span class="p"&gt;)&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;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;goofyRobot&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DogRobot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Robot is ${goofyRobot.clean()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Robot is ${goofyRobot.move()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;musicRobot&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MusicRobot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Robot playing ${musicRobot.playMusic()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Stopping robot... ${musicRobot.stop()}"&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;We have our design now. Everything looks cool and suddenly, guess what? Requirements changed again. &lt;br&gt;
Client asks for a robot that can bark, play games, play music, cook, clean around the house. 🙈&lt;/p&gt;

&lt;h2&gt;Composition to the rescue.&lt;/h2&gt;

&lt;p&gt;Composition is concept which we are constructing object "from the outside" and we don't inherit anything from other classes instead we are composing it. Let's see the example:&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;SuperRobot&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;dogRobot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;DogRobot&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;musicalRobot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MusicRobot&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;playMusic&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Super robot will play some old school music: ${musicalRobot.playMusic()}"&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;bark&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Barking around the house ${dogRobot.bark()}"&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;clean&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cleaning the house... ${dogRobot.clean()}"&lt;/span&gt;&lt;span class="p"&gt;)&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;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;superRobot&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SuperRobot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="n"&gt;dogRobot&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DogRobot&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
   &lt;span class="n"&gt;musicalRobot&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MusicRobot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Playing music: ${superRobot.playMusic()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Barking: ${superRobot.bark()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cleaning: ${superRobot.clean()}"&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;To achieve this in Kotlin with the inheritance concept is not possible since Kotlin does not support multiple inheritance.&lt;/p&gt;

&lt;p&gt;The downsides of the inheritance are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we can only extend one class&lt;/li&gt;
&lt;li&gt;we are setting contract for the subclasses which should be respected&lt;/li&gt;
&lt;li&gt;we take everything from the parent class&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros of using Composition over Inheritance:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;composition is more secure because we don't depend on the class implementation at all, only on the external observables.&lt;/li&gt;
&lt;li&gt;with composition we are more flexible, when we inherit, we take everything, but when we are composing then we can choose 
what we need for constructing.&lt;/li&gt;
&lt;li&gt;unit testing with composition is easier because we already know from which classes some methods are used.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;General rule in the OOP is using composition over inheritance. Use inheritance only when you must and if you need strict contract which subclasses should respect. In any other case strive for composition.&lt;br&gt;
Easier to remember is like this: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use inheritance when a class &lt;strong&gt;"is"&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;use composition when class &lt;strong&gt;"has"&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding :)&lt;/p&gt;

</description>
      <category>android</category>
      <category>cleancode</category>
      <category>kotlin</category>
      <category>java</category>
    </item>
    <item>
      <title>3 Android Studio plugins for productive development</title>
      <dc:creator>Boris </dc:creator>
      <pubDate>Sun, 02 Oct 2022 20:06:59 +0000</pubDate>
      <link>https://dev.to/boryans/3-android-studio-plugins-for-productive-development-229c</link>
      <guid>https://dev.to/boryans/3-android-studio-plugins-for-productive-development-229c</guid>
      <description>&lt;h2&gt;Rainbow brackets&lt;/h2&gt;

&lt;p&gt;The codebase usually gets bigger and bigger and you should take care of nested for loops or some other nested function scopes. This plugin will color every scope you have with the different brackets color so you can easily track in which scope you are working. &lt;a href="https://github.com/izhangzhihao/intellij-rainbow-brackets"&gt;Read more about this plugin&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;WakaTime&lt;/h2&gt;

&lt;p&gt;This is my favourite one. It tracks how much time you spent on your project, on which classes and which lines of code. There is free and paid version so you can choose which features you want. I am currently using free version and it's great! If you want to know how much time you spent daily on some tasks or you should log your time if you are working in a company which requires logging, then just try it. &lt;br&gt;
&lt;a href="https://wakatime.com/developers"&gt;Read more here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Json to Kotlin&lt;/h2&gt;

&lt;p&gt;Another great plugin that helps you generate Kotlin classes out of nothing 🧐. Just kiddin'. If you provide any JSON string/JSONSchema or any URLs that returns a JSON string/JSONSchema as a response you can generate the classes. It saves so much time. But anyway, sometimes you should refactor a bit if you have too much repeating data classes which are redundant. &lt;a href="https://github.com/wuseal/JsonToKotlinClass"&gt;Read more here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Key promoter X&lt;/h2&gt;

&lt;p&gt;Title said three, but you get to fourth one. Bonus plugin for the long term investment in learning the AS shortcuts.&lt;br&gt;
If you want to be more productive, you should learn to use shortcuts in Android Studio. This plugin will alert you everytime you open something in AS if there is a shortcut for that action. You can, of course, disable alerts but the more you have it, the more you learn. If there are no shortcuts for some action, the Key promoter X will provide option for your custom shortcut. &lt;br&gt;
&lt;a href="https://plugins.jetbrains.com/plugin/9792-key-promoter-x"&gt;Read more here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy coding! &lt;/p&gt;

&lt;p&gt;You can follow me on: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/boris-janevski/"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/borYans"&gt;Github&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>android</category>
      <category>productivity</category>
      <category>analytics</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Reduce cognitive load with Kotlin Extension functions.</title>
      <dc:creator>Boris </dc:creator>
      <pubDate>Sun, 25 Sep 2022 13:05:44 +0000</pubDate>
      <link>https://dev.to/boryans/reduce-cognitive-load-with-kotlin-extension-functions-3dfo</link>
      <guid>https://dev.to/boryans/reduce-cognitive-load-with-kotlin-extension-functions-3dfo</guid>
      <description>&lt;p&gt;We are 80% reading the code and 20% writing the code. That's why we should take care about cognitive load which our code reproduce. One way is to write intuitive and readable code. &lt;/p&gt;

&lt;p&gt;A very useful Kotlin feature are Extensions functions. Let's see what extensions are and how to use it in your code to make it more readable.&lt;/p&gt;

&lt;p&gt;"Kotlin provides the ability to extend a class or an interface with new functionality without having to inherit from the class."&lt;/p&gt;

&lt;p&gt;If we want to check if some money amount is valid for transaction we can create simple check function that return a Boolean like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun isValidAmount(amount: BigDecimal) = amount &amp;gt; ZERO &amp;amp;&amp;amp; amount &amp;lt;  PAYMENT_MAX_AMOUNT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or we should disable / enable some view from the screen&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun hide(amountView: View) {
  amountView.visibility = View.GONE
}

fun show(amountView: View) {
  amountView.visibility = View.VISIBLE

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These two functions are absolutely correct but we can go even further with Kotlin extensions in order to make code a bit more intuitive and readable. Now let's see how these two functions will look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun BigDecimal.isValidAmount() = this in ZERO..PAYMENT_MAX_AMOUNT

//and applied in code
val amount = BigDecimal(1000)
if(amount.isValidAmount()) {
// make a payment
} else {
 //show message to the user
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and hiding the view function will look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Hides the view
fun View.hide() {
  visibility = View.GONE
}

// Shows the view
fun View.show() {
 visibility = View.VISIBLE
}

// Hides or show the view based on the flag
fun shouldShow(show: Boolean) {
  if(show) visibility.VISIBLE else visibility.GONE
}

// when applied 
if(amount.isValidAmount()) {
    amountView.show() 
} else {
    amountView.hide()
}

// or even further with one liner
amountView.shouldShow(amount.isValidAmount())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see how this improves readability in our code. &lt;/p&gt;

&lt;p&gt;Under the hood there is nothing special. If we decompile the Kotlin bytecode into Java source file we can see nothing but regular methods with passed arguments.&lt;br&gt;
So there is no performance benefit, it's just a pure Kotlin synthetic sugar!&lt;/p&gt;

&lt;p&gt;You can play with them and use it everywhere inside the app where you think that is necessary to improve readability. They are excellent for Utility classes where you need a lot of checks and validations. &lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>backend</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Write safe code with immutable properties in Kotlin?</title>
      <dc:creator>Boris </dc:creator>
      <pubDate>Thu, 22 Sep 2022 17:41:46 +0000</pubDate>
      <link>https://dev.to/boryans/write-safe-code-with-immutable-properties-in-kotlin-3if6</link>
      <guid>https://dev.to/boryans/write-safe-code-with-immutable-properties-in-kotlin-3if6</guid>
      <description>&lt;p&gt;This topic is highly underrated so it's good to know why we should try to use immutable properties.&lt;/p&gt;

&lt;p&gt;I would like to point some safety measures when it comes to writing in Kotlin. Kotlin has awesome API's that allows us to write clean, safe and readable code.&lt;/p&gt;

&lt;p&gt;One of safety guns in Kotlin is defining immutable properties &lt;strong&gt;val&lt;/strong&gt; or read-write properties &lt;strong&gt;var&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val num = 10
num = 5 //this is not allowed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The properties in Kotlin are encapsulated by default. That means that even &lt;em&gt;num&lt;/em&gt; is read-only property, it can have custom &lt;strong&gt;getter&lt;/strong&gt; or it can hold mutable object like &lt;code&gt;mutableListOf()&lt;/code&gt; which you can operate on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val list = mutableListOf(2,3,4)
list.add(5) //this gives us more flexibility
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or even we can specify custom getter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Rectangle(val width: Int, val height: Int) {
    val area: Int 
        get() = this.width * this.height
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With above examples we've seen that Kotlin is protecting us by default if we use &lt;strong&gt;val&lt;/strong&gt; property.&lt;/p&gt;

&lt;p&gt;The big question is, why we should use it in our classes which holds state? &lt;/p&gt;

&lt;p&gt;Let's see this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var num = 0
for(i in 0..1000) {
thread {
 Thread.sleep(10)
num++
  }
}
Thread.sleep(3000)
println(num) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In example above there are high chances that &lt;em&gt;num&lt;/em&gt; will not be &lt;strong&gt;1000&lt;/strong&gt; because some threads will change value of this property and we will not have consistent app after all. &lt;/p&gt;

&lt;p&gt;The same applies with coroutines. The value will be modified as well. &lt;/p&gt;

&lt;p&gt;Limiting mutability in Kotlin:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;val keyword (we can make custom getter or use delegation)&lt;/li&gt;
&lt;li&gt;copy keyword applied on data class objects&lt;/li&gt;
&lt;li&gt;mutable collections (&lt;code&gt;mutableMapOf()&lt;/code&gt; &lt;code&gt;mutableListOf()&lt;/code&gt;...etc)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Prefer object and classes that are immutable over mutable. But if you need to change them, consider making immutable data classes and use a &lt;em&gt;copy&lt;/em&gt; to change the state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class User(
val name: String,
val surname: String,
val address: String
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's say that user has changed his address in the meantime so we want to change this immutable &lt;em&gt;adress&lt;/em&gt; property with &lt;em&gt;copy&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val johny = User(
"John",
"Johnny",
"Beverly Hills 74"
)

val johnyWithNewAdress = johny.copy(adress = "Holywood 12")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another big mistake when it comes to mutability is down-casting immutable collection. This is huge mistake and please don't do it. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val list = listOf(1,2,3,4,6)
if (list is MutableList) {
list.add(5) //DON'T DO THIS
}

//Do THIS INSTEAD
val list = listOf(1,2,3,4,6)
val newList = list.toMutableList()
newList.add(5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here our list is not modified by outside, instead it creates copy of new list which you can easily modify.&lt;/p&gt;

&lt;p&gt;There are some exception to this rules but chose it wisely, sometimes we need object to be fully mutable. Baseline is that we should limit mutability as much as possible.&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>backend</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
