<?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: Vladimir Jovanović</title>
    <description>The latest articles on DEV Community by Vladimir Jovanović (@vladimirwrites).</description>
    <link>https://dev.to/vladimirwrites</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%2F147542%2F44011f7c-2573-4812-a082-35d032a73b5a.jpeg</url>
      <title>DEV Community: Vladimir Jovanović</title>
      <link>https://dev.to/vladimirwrites</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vladimirwrites"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Wed, 21 Jan 2026 09:06:28 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/-3708</link>
      <guid>https://dev.to/vladimirwrites/-3708</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/vmitro" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1134911%2F54d6050e-b0e0-420f-9a07-b61e07d63c3a.png" alt="vmitro"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/vmitro/i-profiled-claude-code-so-you-dont-have-to-or-how-i-learned-to-stop-worrying-and-love-the-strace-5dc0" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;I profiled Claude Code so you don't have to, or How I Learned to Stop Worrying and Love the strace&lt;/h2&gt;
      &lt;h3&gt;vmitro ・ Jan 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#ai&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cli&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#llm&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#performance&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>ai</category>
      <category>cli</category>
      <category>llm</category>
      <category>performance</category>
    </item>
    <item>
      <title>Firebase Predictions 🔮</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Fri, 22 May 2020 09:44:00 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/firebase-predictions-2k8</link>
      <guid>https://dev.to/vladimirwrites/firebase-predictions-2k8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HbEUey4M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vladimirj.dev/assets/blog/firebase_predictions_cover.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HbEUey4M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vladimirj.dev/assets/blog/firebase_predictions_cover.png" alt="Header" width="880" height="585"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Firebase provides a wide variety of tools, something for every developer and something for every problem. But did you know that it has a tool that enables you to see into the future 🔮😮?! Yes, you heard me right, the tool called Firebase Predictions enables you to predict future actions of your users.&lt;/p&gt;

&lt;p&gt;A lot of Android developers have never heard of Firebase Predictions or never used it, and this article will serve as a quick introduction. Apart from that, I will also explore some of the retention and monetization strategies that this tool makes possible.&lt;/p&gt;

&lt;p&gt;To be able to start using Firebase Predictions you need to have Firebase Analytics integrated into your app. What Firebase Predictions does, is apply machine learning on your analytics data and create user segments depending on how likely those users are to execute a specific action within the next 7 days. In other words, for every analytics event, it can give you a group of users who are most likely and a group of users who are least likely to execute that event.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x1f7jG6k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://vladimirj.dev/assets/blog/firebase_predictions_segments.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x1f7jG6k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://vladimirj.dev/assets/blog/firebase_predictions_segments.gif" alt="User Segments" width="852" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now armed with that knowledge, you can react to your users’ anticipated actions and needs using other Firebase tools and always stay one step ahead. &lt;/p&gt;

&lt;p&gt;You have the option to use Remote Config and adjust user experience for specific user segments, or to use push notifications and in-app messages to inform those users about new deals tailored just for them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Retention and Monetization Strategies
&lt;/h3&gt;

&lt;p&gt;The best way to present the power of Firebase Predictions is on an example. Let’s say that we have an app that is selling something. That can be a product, subscription to a pro version of the app, or in-app currency. And let’s say that we are tracking this purchase event in Firebase Analytics.&lt;/p&gt;

&lt;p&gt;Using Firebase Predictions we can assign the value to the users on how likely they are to make a purchase in the next 7 days. Knowing this, we can start adjusting the behavior of the app for those users.&lt;/p&gt;

&lt;p&gt;If the users are not likely to convert, we can explore other monetization strategies, such as for example ads. So using Remote Config we can show ads to those users. If the users are a bit more likely to convert we can try nudging them by, for example, sending them vouchers using push notifications and in-app messages. And if the users are super likely to convert, we can just leave them alone, and make sure that they are not disturbed by ads and push notifications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I2lXBglI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vladimirj.dev/assets/blog/firebase_predictions_app_removal.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I2lXBglI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vladimirj.dev/assets/blog/firebase_predictions_app_removal.png" alt="Screenshot" width="305" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a similar way, you can also employ a user retention strategy. The only difference is that, in this case, you would run a prediction on the app removal event and adjust the user experience depending on how likely the users are to uninstall your app.&lt;/p&gt;

&lt;p&gt;Finally, you can run Firebase Predictions on any event, and since every app is unique make sure to explore different ways to improve your application using Firebase Predictions.&lt;/p&gt;

&lt;p&gt;Now you’re probably thinking: “This Firebase Predictions thing sounds amazing. So what’s the catch? How much does it cost?” The best thing about Firebase Predictions is that it’s completely free, and you can start using it today.&lt;/p&gt;

&lt;p&gt;If you would like to learn more about Firebase Remote Config check out my Pluralsight course: &lt;a href="http://pluralsight.pxf.io/xgdk1"&gt;&lt;strong&gt;&lt;em&gt;Firebase on Android: Remote Config and A/B Testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Thanks for reading! If you enjoyed this story, please share it! Also, feel free to leave a comment 💬 below.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>android</category>
      <category>mobile</category>
      <category>predictions</category>
    </item>
    <item>
      <title>/* intentionally left empty */</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Wed, 20 Mar 2019 09:44:00 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/-intentionally-left-empty-3ki3</link>
      <guid>https://dev.to/vladimirwrites/-intentionally-left-empty-3ki3</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2560%2F1%2A_c7QqMOJmXlA5Kef58JtJw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2560%2F1%2A_c7QqMOJmXlA5Kef58JtJw.png" alt="Header"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A long time ago somewhere in India empty spaces were creating a lot of problems. Numbers were being written without zeros, and believe me, it’s hard to write numbers when you replace zero with an empty space.  &lt;strong&gt;11&lt;/strong&gt; and &lt;strong&gt;1 1&lt;/strong&gt; looked almost the same. That’s why zero was created.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In its early beginnings, zero meant &lt;strong&gt;“intentionally left empty”&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s now travel back to the present, and see if empty spaces are causing trouble in the life of an average software developer. There are probably places in your code base where it’s not clear if something is a mistake or if it was left intentionally empty.  Sometimes we don’t need the implementation of &lt;code&gt;initialize()&lt;/code&gt; in every child method, so we would just create an empty implementation instead of an abstract method.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;I know that comments are not great, but in this case, I would suggest adding them. With the added comment, there is no confusion whether the empty method is a mistake or not.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Another example when we need an empty method is when we want to omit the behavior of the parent’s implementation. This clearly breaks &lt;a href="https://en.wikipedia.org/wiki/Liskov_substitution_principle" rel="noopener noreferrer"&gt;Liskov substitution principle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AToXLL1aet69THe2qxuwCmQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AToXLL1aet69THe2qxuwCmQ.jpeg" alt="1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, sometimes you can’t control all the code that you are using, so you have to make compromises.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Then, there are those notorious listener implementations, with a lot of methods that are usually not needed. Here is one example from the Android world:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally, when working on a new feature, you can’t build it all at once. Inevitably, you will have parts of the code that are unfinished. This is not really a problem, it just needs to be clearly marked as unfinished with a simple &lt;code&gt;TODO&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Please don’t leave your methods empty. If the method is intentionally left empty, simply leave a comment for your fellow developers or for your future self.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you enjoyed this story, please click the ❤️ button and share to help others find it! Feel free to leave a comment 💬 below.&lt;br&gt;
Have feedback? Let’s be friends &lt;a href="https://twitter.com/VladimirWrites" rel="noopener noreferrer"&gt;on Twitter&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>tools:title=”RemoteSampleData”</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Sat, 10 Mar 2018 09:44:00 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/toolstitleremotesampledata-18bd</link>
      <guid>https://dev.to/vladimirwrites/toolstitleremotesampledata-18bd</guid>
      <description>&lt;p&gt;What I’ve learned from my previous &lt;a href="https://dev.to/vladimirwrites/toolstitlelayoutpreview-5ae9"&gt;article&lt;/a&gt; is that the best way to gain new knowledge about a certain topic is to write about it. When I first wrote the article, I had no idea that you can create custom sampledata for your Android project. (If you don’t have a clue what &lt;code&gt;sampledata&lt;/code&gt; is, please read &lt;a href="https://dev.to/vladimirwrites/toolstitlelayoutpreview-5ae9"&gt;tools:title=”LayoutPreview”&lt;/a&gt;) And then someone sent me &lt;a href="https://blog.stylingandroid.com/tool-time-part-2/"&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It sounded like a really cool feature, so I made the list of my favorite characters from Lord of the Rings, used it as &lt;code&gt;sampledata&lt;/code&gt;, and got this glorious layout preview.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Emhsygh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AcZHVJzVAvIfQMI47DEZo1A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Emhsygh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AcZHVJzVAvIfQMI47DEZo1A.png" alt="LotR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Later on, I wanted to include it in my other projects, but the only option that I had was to copy/paste the &lt;code&gt;sampledata&lt;/code&gt; from one project to another, and that didn’t make any sense. Then I did what every (lazy) developer would do, asked a &lt;a href="https://stackoverflow.com/questions/48874434/use-sample-data-directory-from-a-library"&gt;question on StackOverflow&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After 10 views and no answer in sight, I’ve decided to sacrifice a bit of my reputation and start a bounty. And it worked. I got my answer, which I will share with you.&lt;/p&gt;

&lt;p&gt;To use &lt;code&gt;sampledata&lt;/code&gt; between multiple projects you first have to host it and then have a Gradle script which will download it into your project’s &lt;code&gt;sampledata&lt;/code&gt; folder. This is the code which does that:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The first script will delete &lt;code&gt;sampledata&lt;/code&gt; once you do a clean build, and the second one will create &lt;code&gt;sampledata&lt;/code&gt; folder in case it doesn’t exist, and then download sample files into it. It works like a charm and from now on you can go crazy with your layout previews. I know that from now on I will never again use &lt;code&gt;@tools:sample/lorem/random&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9ot6QOTQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AmRs5qWCaRL0rpaflBjwfZQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9ot6QOTQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AmRs5qWCaRL0rpaflBjwfZQ.png" alt="Developers developers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This code can be found in &lt;a href="https://github.com/VladimirWrites/tools-sample"&gt;GitHub repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I’ve also added some sample data and will keep adding more. If you notice that something is missing or could be improved, feel free to contribute. This could be a great opportunity for novice developers to make their first contribution 😉.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you enjoyed this story, please click the ❤️ button and share to help others find it! Feel free to leave a comment 💬 below.&lt;br&gt;
Have feedback? Let’s be friends &lt;a href="https://twitter.com/VladimirWrites"&gt;on Twitter&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>androiddevelopment</category>
      <category>androidlayout</category>
    </item>
    <item>
      <title>tools:title=”LayoutPreview”</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Sun, 18 Feb 2018 09:44:00 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/toolstitlelayoutpreview-5ae9</link>
      <guid>https://dev.to/vladimirwrites/toolstitlelayoutpreview-5ae9</guid>
      <description>

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d9qFnLEO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AKE1HSefSP2PFKHOcATMyow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d9qFnLEO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AKE1HSefSP2PFKHOcATMyow.png" alt="Header"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As every Android developer, I also started building my layouts by hard-coding values into them. Later on, I have realized that I should probably extract them into resources. Next step was not to have values in layouts if they are going to be changed from the code (always keep the state of your view in code). But at that point, my layout preview got broken. The layouts were full of TextViews without texts, &lt;code&gt;ImageViews&lt;/code&gt; without images, etc. And then I discovered the power of &lt;code&gt;tools:&lt;/code&gt;. Fast forward one year and I had layouts full of &lt;code&gt;tools:text="Test text"&lt;/code&gt;, &lt;code&gt;tools:text="Jake Wharton"&lt;/code&gt;, &lt;code&gt;tools:src="@drawable/ic_random_res"&lt;/code&gt; … you get the point. Is there a better way to do this, you may ask?&lt;/p&gt;

&lt;p&gt;Actually, there is. And it’s pretty easy. There are predefined sample resources that you can use to make your layout preview nice and clean. By using these, we can go from this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;to this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;And why is this better? If your &lt;code&gt;TextView&lt;/code&gt; is inside a repeatable element like, for example, an item inside &lt;code&gt;RecyclerView&lt;/code&gt;, and you set up your preview correctly, then your &lt;code&gt;TextView&lt;/code&gt; will have a different text in every item. Speaking of &lt;code&gt;RecyclerView&lt;/code&gt;, let’s make a deep dive into making a preview of your &lt;code&gt;RecyclerView&lt;/code&gt; as sleek as possible, using this and some other tricks.&lt;/p&gt;

&lt;p&gt;It all starts with a normal and rather ugly &lt;code&gt;RecyclerView&lt;/code&gt; in your layout XML file. In a preview, it looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZFQsu86f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2At_LdKfy3_FhtdYSClfRalQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZFQsu86f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2At_LdKfy3_FhtdYSClfRalQ.png" alt="1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It would look much nicer if we could show the real item used in our &lt;code&gt;RecyclerView&lt;/code&gt;, and even more so if that item uses sample texts &lt;code&gt;tools:text=”@tools:sample/lorem”&lt;/code&gt; and &lt;code&gt;tools:text=”@tools:sample/lorem/random”&lt;/code&gt; for &lt;code&gt;TextViews&lt;/code&gt; inside. And as a result, we get the following preview:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---WEZ5n81--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2Ah07HZjRlaiMwdouPyVyOCg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---WEZ5n81--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2Ah07HZjRlaiMwdouPyVyOCg.png" alt="2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It looks much better, almost like a real application. The only problem is that our application in horizontal orientation has &lt;code&gt;GridLayout&lt;/code&gt; with two spans. Can we do something in that regard? Of course, we can. By adding &lt;code&gt;tools:layoutManager=”GridLayoutManager”&lt;/code&gt; and &lt;code&gt;tools:spanCount=”2"&lt;/code&gt;, we are getting exactly what we want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FOlKfbCL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AkqjxF4AQWgs07NzvH3jXiA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FOlKfbCL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AkqjxF4AQWgs07NzvH3jXiA.png" alt="3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, almost. Our &lt;code&gt;Activity&lt;/code&gt; has some menu items in the &lt;code&gt;Toolbar&lt;/code&gt;, and if we could display these as well, it would be perfect. Accomplishing this isn’t really that difficult. Simply adding &lt;code&gt;tools:menu=”menu_test”&lt;/code&gt; to the root element of your layout does the trick. It’s important to know that for this to work you need to have predefined menu item &lt;code&gt;@menu/menu_test.xml&lt;/code&gt;, and your &lt;code&gt;Toolbar&lt;/code&gt; needs to be defined in a theme and not added in layout’s XML. The final result looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hyFzINrd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AwIn852IO79_vJaHKVdCPtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hyFzINrd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AwIn852IO79_vJaHKVdCPtg.png" alt="4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The final code looks like this (minus some margins, styles etc., that are removed to make it a bit more compact):&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;As you can see, &lt;code&gt;tools:&lt;/code&gt; gives you great power to prototype and experiment with your layout without writing a single line of Java or Kotlin code or adding unnecessary states to your view’s XML. If you start using it now, you will have a much more pleasant time developing UI on your new project, and it will be a breeze to modify it later on.&lt;/p&gt;

&lt;p&gt;Documentation for all tools attributes is available &lt;a href="https://developer.android.com/studio/write/tool-attributes.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The full source code of this and some other examples can be found in the &lt;a href="https://github.com/VladimirWrites/tools-sample"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you enjoyed this story, please click the ❤️ button and share to help others find it! Feel free to leave a comment 💬 below.&lt;br&gt;
Have feedback? Let’s be friends &lt;a href="https://twitter.com/VladimirWrites"&gt;on Twitter&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;


</description>
      <category>android</category>
      <category>androiddevelopment</category>
      <category>androidlayout</category>
    </item>
    <item>
      <title>PRObably the Language Of God</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Tue, 24 Oct 2017 09:44:00 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/probably-the-language-of-god-44b6</link>
      <guid>https://dev.to/vladimirwrites/probably-the-language-of-god-44b6</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S8GF1ew4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2A5WdZRFMF5s_15nOUAxEDbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S8GF1ew4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2A5WdZRFMF5s_15nOUAxEDbg.png" alt="Prolog" width="320" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;During my university days, when I was studying Mathematics and CS, software development was a refreshment of applied science in a sea of theoretical math. But then in my 4th semester came &lt;a href="https://en.wikipedia.org/wiki/Prolog"&gt;Prolog&lt;/a&gt;. For those who hadn’t heard of Prolog, it’s the most inapplicable programming language in the universe (at least that’s what I thought). Created in the early 1970s, it was one of the first &lt;a href="https://en.wikipedia.org/wiki/Logic_programming"&gt;logic programming languages&lt;/a&gt;. It’s the most mathematical thing in the world of computer science.&lt;/p&gt;

&lt;p&gt;Seven years after my first encounter with Prolog, I found some old &lt;code&gt;.pl&lt;/code&gt; files, I opened them and was amazed that at one point in my life I had understood and more surprisingly had written those lines. So I decided to take one week of my life, and check again if Prolog is worth learning in the 21st century. At that point, I created &lt;a href="https://github.com/VladimirWrites/PrologSamples"&gt;GitHub repository&lt;/a&gt;, downloaded &lt;a href="http://www.swi-prolog.org/download/stable"&gt;Prolog compiler&lt;/a&gt;, and started.&lt;/p&gt;

&lt;p&gt;The main building blocks of Prolog code are facts and rules. A fact is something like an &lt;a href="https://en.wikipedia.org/wiki/Axiom"&gt;axiom&lt;/a&gt;, a statement that is taken to be true. Meanwhile, a rule is analogous to a theorem, and its truthiness can be derived from facts.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;These are the examples of a fact and a rule. The next step would be to load a file containing facts and rules into Prolog and make queries on it. For this case, the examples of queries would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;?- guitarist("Saul Hudson").
true.
?- musician("Saul Hudson").
true.
?- guitarist(X).
X = "Saul Hudson".
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As you can see, &lt;code&gt;guitarist&lt;/code&gt; does not behave like a function. That’s because it’s not a function, it’s a relation. Prolog is a relational programming language. To better explain this, let’s take a look at the following example:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;&lt;code&gt;factorial&lt;/code&gt; defines a relation between some natural numbers. What does that mean? The fact &lt;code&gt;factorial(1,1)&lt;/code&gt;. means that &lt;code&gt;1&lt;/code&gt; is in relation &lt;code&gt;factorial&lt;/code&gt; with &lt;code&gt;1&lt;/code&gt;. And what about the second line?! Well, it can be read like this: “Numbers &lt;code&gt;N&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt; are in relation &lt;code&gt;factorial&lt;/code&gt; if &lt;code&gt;N&amp;gt;1&lt;/code&gt; and &lt;code&gt;N1 is N-1&lt;/code&gt; and &lt;code&gt;N1&lt;/code&gt; and &lt;code&gt;R1&lt;/code&gt; are in relation &lt;code&gt;factorial&lt;/code&gt; and &lt;code&gt;R is N*R1&lt;/code&gt;” 😧. Could that be expressed in an understandable way?! In practice, it means that if you query this set of rules, you can calculate factorial.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;?- factorial(5,R).
R = 120 .
?- factorial(1,R).
R = 1 .
?- factorial(20,R).
R = 2432902008176640000 .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are a couple of beginners examples of Prolog code. I hope this is sufficient to show you how Prolog works, and what it has to offer. If you find this interesting, and if you are curious enough to do something on your own, feel free to add it to the &lt;a href="https://github.com/VladimirWrites/PrologSamples"&gt;repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, should you learn Prolog? Well, it’s the 21st century, and you should be learning whatever you can find on the internet. But seriously, is it worth learning? I think it is. It’s a niche concept that never really took off, but it somehow feels fresh and modern. For you, it will probably be a totally new approach to software development, that will get you out of your comfort zone, and force you to think in a different way while giving you another perspective on how software can be written.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you enjoyed this story, please click the ❤️ button and share to help others find it! Feel free to leave a comment 💬 below.&lt;br&gt;
Have feedback? Let’s be friends &lt;a href="https://twitter.com/VladimirWrites"&gt;on Twitter&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>prolog</category>
      <category>functional</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Variable looked at me and said: “Say my name!”</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Tue, 17 Oct 2017 09:44:00 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/variable-looked-at-me-and-said-say-my-name-4301</link>
      <guid>https://dev.to/vladimirwrites/variable-looked-at-me-and-said-say-my-name-4301</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i0TFOaIH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AH789DsYnZjSp3GChn0e-hA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i0TFOaIH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AH789DsYnZjSp3GChn0e-hA.jpeg" alt="Header"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While I was learning basics of programming at my high school, I was being taught how to solve problems: sort an array, reverse a String, convert Roman numerals to Arabic, etc. It was never expected from me to write code that would be altered or checked by another person. Usually, it was enough for the code to work, and to return correct output for a given input.&lt;/p&gt;

&lt;p&gt;Some years later my university days started. I studied Mathematics and CS, and on my first CS exam I did all tasks, I tested them, and they worked, so I was expecting my first A+. But I got a B. I ran to my Assistant Professor’s office to tell him that he had made a mistake.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;I came to him, all confident, and said: “I saw the exam results, and I think you have made a mistake. I am sure that my code works as expected.”&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;“Yes, it does,” he answered.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;“So why did I then get a B?”&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;“Because it took me 60 minutes to see why it worked.”&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And why is that, you may ask?! Well, the longest variable’s name in my code had two characters in it, and its name was &lt;code&gt;s1&lt;/code&gt;. At that point, I realised that from that day on, my code would be read by others, so I started commenting it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nGGmeE4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2ALO8ENinrxsVeJq3h4_l3vA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nGGmeE4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2ALO8ENinrxsVeJq3h4_l3vA.gif" alt="No"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I learned some things the hard way, but you don’t have to.&lt;/p&gt;

&lt;p&gt;Let’s start from the beginning. Why do we need a variable’s name longer than one character? Because, usually, code that you write professionally will be read by someone else, or worse, by you, one year later. Maybe while you are writing it, it’s all clear to you. But that isn’t because your code is clear and easy to understand, that’s because you have just written it.&lt;/p&gt;

&lt;p&gt;Whenever you feel the urge to put a comment over your variable declaration, think about giving your variable a more descriptive name. The main problem with the comment that describes your variable is that it will be at one place in your code, and your variable will be at multiple locations. A developer that reads your code at a later point in time will need to constantly convert &lt;code&gt;vn&lt;/code&gt; into &lt;code&gt;variableName&lt;/code&gt; in his mind while trying to understand the code.&lt;/p&gt;

&lt;p&gt;Do not expect that giving your variables longer names will automatically make your code better. Naming is hard, and it will take you much more time to find a decent name for your variable than to write a comment.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“There are only two hard things in Computer Science: cache invalidation and naming things.” — Phil Karlton&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some of the basic principles to follow when naming your variables are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use pronounceable names for all variables. &lt;code&gt;dayMonthYear&lt;/code&gt; is a much better name than &lt;code&gt;ddmmyyyy&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The name should tell you what the object does, instead of how it does it.&lt;/li&gt;
&lt;li&gt;Names should be meaningful within their context. &lt;code&gt;name&lt;/code&gt; is a pretty good variable’s name inside class &lt;code&gt;User&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Be consistent. Most words have synonyms. Pick one and use it throughout your project.&lt;/li&gt;
&lt;li&gt;Use a name that is as short as possible, but descriptive enough. Use &lt;code&gt;birthday&lt;/code&gt; instead of &lt;code&gt;dateOnWhichUserIsBorn&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Don´t use negative logic for your variable’s name. Use &lt;code&gt;isEnabled&lt;/code&gt; instead &lt;code&gt;isNotEnabled&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Whenever you have two variables that differ just by number, refactor your code immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In some cases, variables can and should have a short name.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If a variable represents a loop-count, its name should be &lt;code&gt;i&lt;/code&gt;, or &lt;code&gt;j&lt;/code&gt; for the inner loop.&lt;/li&gt;
&lt;li&gt;In a function where arguments traditionally have a one-char-name.
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Sometimes it’s really hard to explain a variable’s purpose inside its name, and in that case, you need to write a comment.
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While you are writing your code, the most important thing to have in mind is that you are writing your code first and foremost for humans to understand, and secondly for a machine to interpret. Therefore, when your code works and does what it’s meant to do, spend a couple of minutes and make it easier for human beings to understand.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you enjoyed this story, please click the ❤️ button and share to help others find it! Feel free to leave a comment 💬 below.&lt;br&gt;
Have feedback? Let’s be friends &lt;a href="https://twitter.com/VladimirWrites"&gt;on Twitter&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>cleancode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Handling configuration changes using static references</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Mon, 09 Oct 2017 10:44:00 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/handling-configuration-changes-using-static-references-1d6e</link>
      <guid>https://dev.to/vladimirwrites/handling-configuration-changes-using-static-references-1d6e</guid>
      <description>&lt;p&gt;&lt;a href="https://i.giphy.com/media/3otPoQqrl8oggqDKg0/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3otPoQqrl8oggqDKg0/giphy.gif" alt="Header"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When writing about the preservation of data on configuration change, there are two cases to cover. First, if there is a fixed number of small objects that need to survive change, use &lt;code&gt;onSaveInstanceState&lt;/code&gt;, and that’s it, end of story, problem solved. However, the real problem comes when you need to preserve big objects whose size is unknown. There are a couple of correct approaches to this problem depending on your requirements. But that isn’t what this text is going to be about. This text is going to be about one pretty popular and rather wrong approach. We all know it is a bad one, but not all know why. The internet is full of questions on this topic, and a couple of days ago I also got asked about it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;What if you hold a static reference to the data in my Activity to preserve them on screen rotation? Why is that bad?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;“Don’t do that, it’s bad! Memory leaks! Danger! 🚨” was my first reaction. But then he/she said: “Yeah, yeah … I know, but I will be super careful, and I will hold only data, no &lt;code&gt;Context&lt;/code&gt;, or anything that has reference to the &lt;code&gt;Context&lt;/code&gt;. Is it still bad?” You can bet it is! But that got me thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“Why is it still bad?”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Why is it bad to have a static reference to some data inside your &lt;code&gt;Activity&lt;/code&gt;? I was thinking for some time and then &lt;code&gt;💡.turnOn()&lt;/code&gt;. It’s bad because of 🥁🥁🥁 &lt;strong&gt;memory leaks&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/aVtdz7iNVPI1W/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/aVtdz7iNVPI1W/giphy.gif" alt="Fail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, this is not your classical Java/Android memory leak that &lt;a href="https://github.com/square/leakcanary/tree/master/leakcanary-android"&gt;Leakcanary&lt;/a&gt; will warn you about. This leaked memory can still be accessed, and although it is not needed anymore, the OS can’t do GC on it. The main problem with having a static reference to an object inside an &lt;code&gt;Activity&lt;/code&gt; is that it’s really hard to know when to release it.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Think about it. You can’t do that &lt;code&gt;onDestory()&lt;/code&gt;, because you need your data to survive a configuration change. Should you do it when the next &lt;code&gt;Activity&lt;/code&gt; is opened? Maybe, but probably not, because you will need those objects when you come back to that &lt;code&gt;Activity&lt;/code&gt;. So, when should you do it then? Well, you shouldn’t! Android should take care of it, and remove it from memory when there is no free memory left. But it can’t because you have static references to those objects. In the end, the OS will remove it from the memory in the only way it knows how, it will kill your application.&lt;/p&gt;

&lt;p&gt;And at some point, on some device, that’s exactly what’s going to happen. You will get &lt;code&gt;OutOfMemoryException&lt;/code&gt;, and your application will crash. Just to be clear, next step &lt;strong&gt;should not&lt;/strong&gt; be adding &lt;code&gt;android:largeHeap="true"&lt;/code&gt; into your &lt;code&gt;AndroidManifest.xml&lt;/code&gt;. It should be fixing your application. You can read more about proper handling of configuration changes &lt;a href="https://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To sum up, having static references to objects is really dangerous, and it’s even worst to do it inside the objects which have a lifecycle such as &lt;code&gt;Activities&lt;/code&gt;, &lt;code&gt;Fragments&lt;/code&gt;, &lt;code&gt;Services&lt;/code&gt; etc. Please use your static variables responsibly.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you enjoyed this story, please click the ❤️ button and share to help others find it! Feel free to leave a comment 💬 below.&lt;br&gt;
Have feedback? Let’s be friends &lt;a href="https://twitter.com/VladimirWrites"&gt;on Twitter&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>memoryleak</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Short methods FTW</title>
      <dc:creator>Vladimir Jovanović</dc:creator>
      <pubDate>Mon, 02 Oct 2017 22:44:00 +0000</pubDate>
      <link>https://dev.to/vladimirwrites/short-methods-ftw-jop</link>
      <guid>https://dev.to/vladimirwrites/short-methods-ftw-jop</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LFR8MDd8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AlEFA9LXXUbGBMnJcEw6fAg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LFR8MDd8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AlEFA9LXXUbGBMnJcEw6fAg.jpeg" alt="Header"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some 5 years ago, I got my first intern job in a small startup. We were building a computer vision prototype in Matlab, and my assignment was to write C/C++ code that was supposed to do different types of transformations on video frames. I wrote a 300-lines-long monstrosity of a method that was doing all kinds of transformations and calculations on a matrix. It worked, and I was happy. Then my boss came to me and said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every method that you write should be less than 25 lines long.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And I laughed, I laughed hard, right in his face. I was such a &lt;a href="https://www.urbandictionary.com/define.php?term=plonker"&gt;plonker&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/zI6X93e09lDag/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/zI6X93e09lDag/giphy.gif" alt="Plonker"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And let me tell you something, 25 lines make one big, long method. Actually, most should be much shorter, around 10 lines, maybe even less. 25 lines should be the upper limit. And why is that?! Well, here are some of the reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First of all, it fits easily on your screen, so it’s easy to read.&lt;/li&gt;
&lt;li&gt;Its purpose can be expressed in one simple sentence, and that makes it (in most cases) easy to understand.&lt;/li&gt;
&lt;li&gt;It doesn’t need comments, because&lt;a href="https://en.wikipedia.org/wiki/Single_responsibility_principle"&gt;it does only one thing&lt;/a&gt;, and that thing can be described within its name.&lt;/li&gt;
&lt;li&gt;It’s easy to test.&lt;/li&gt;
&lt;li&gt;And lastly, because &lt;a href="https://en.wikipedia.org/wiki/Robert_Cecil_Martin"&gt;Uncle Bob&lt;/a&gt; said so.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;“The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that.” — Robert C. Martin&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, not all short methods are good. For example this one:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;Long method bodies are a classical &lt;a href="https://en.wikipedia.org/wiki/Code_smell"&gt;code smell&lt;/a&gt;: it’s not in itself a problem, but it’s an indication that there’s probably a problem there. — &lt;a href="https://softwareengineering.stackexchange.com/users/2234/joachim-sauer"&gt;Joachim Sauer&lt;/a&gt; (has nothing to do with this &lt;a href="https://en.wikipedia.org/wiki/Joachim_Sauer"&gt;Joachim Sauer&lt;/a&gt;, I think 🤔)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One thing that’s mind-boggling is that the vast majority of developers knows that the long methods are bad, but very few actually follow this rule. Quite often, I see good developers writing huge methods because “It’s a UI” or “It’s in a test” or “It’s Java ✋”. And at first glance, it doesn’t look that bad. Code is well organised and each line logically follows the previous one. That’s because the developer who has just written that code has its context and understanding in his head, so he doesn’t need to get it from the code. When another developer tries to change that part of the code one year after it’s been written he/she is …&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/8JfMnpTXorVDy/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/8JfMnpTXorVDy/giphy.gif" alt="Fail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;going to fail. Why?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Because there is no time to invest in proper analysis of that method. (New feature needs to be done by yesterday).&lt;/li&gt;
&lt;li&gt;There are no tests to support refactoring. Not because it’s hard to cover a 100-lines-long method with tests (btw. it is hard), but because it’s much easier to split it into 10 methods, and write tests for each of them. Therefore, there is a good chance that that person didn’t even try to test it. And if he/she did, it’s likely that our developer would be making changes on 10 short methods.&lt;/li&gt;
&lt;li&gt;Misleading comments are everywhere. First of all, there has to be at least a couple of comments in a long method (it’s really unprofessional to write a long incomprehensible method without comments 😄). And it’s quite probable that code has already been changed, but developers are really scared of changing other people’s comments, so comments will stay the same. They will be sitting there, telling you a story of some other badly written code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;So please, for the love of Uncle Bob, write your methods short.&lt;/strong&gt; P.S. I promise that I will refactor long methods in &lt;a href="https://github.com/VladimirWrites"&gt;my projects on GitHub&lt;/a&gt;. 🤞&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you enjoyed this story, please click the ❤️ button and share to help others find it! Feel free to leave a comment 💬 below.&lt;br&gt;
Have feedback? Let’s be friends &lt;a href="https://twitter.com/VladimirWrites"&gt;on Twitter&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>cleancode</category>
      <category>designpatterns</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
