<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Philipp Hofmann on Medium]]></title>
        <description><![CDATA[Stories by Philipp Hofmann on Medium]]></description>
        <link>https://medium.com/@philipp.hofmann?source=rss-fd80f0dca539------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_PwbNhnwL7uWCtYUaimezA.jpeg</url>
            <title>Stories by Philipp Hofmann on Medium</title>
            <link>https://medium.com/@philipp.hofmann?source=rss-fd80f0dca539------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 23:22:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@philipp.hofmann/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Your Software Architecture Right]]></title>
            <link>https://medium.com/monsterculture/getting-your-software-architecture-right-89287a980f1b?source=rss-fd80f0dca539------2</link>
            <guid isPermaLink="false">https://medium.com/p/89287a980f1b</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Philipp Hofmann]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 13:06:04 GMT</pubDate>
            <atom:updated>2019-12-16T16:07:16.197Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJAfxV4qB-R6ajA8GdSKQA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/7nrsVjvALnA?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Denys Nevozhai</a> on <a href="https://unsplash.com/search/photos/highway?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>You don’t need to be an expert to code something that works. If the project is small and the complexity is low, you don’t need a senior developer to get the job done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*61U3JNHmAud_bhq9" /><figcaption><a href="http://themetapicture.com/the-life-of-a-software-engineer/">http://themetapicture.com/the-life-of-a-software-engineer/</a></figcaption></figure><p>Take a look at the cartoon above. The only software engineer who has never experienced this is the one who never coded a single line.</p><p>Getting software right is hard. Years of experience and lots of different skills are needed to master this. It is a pleasure to work on a project whose engineers got it right. You can add, change or remove features without trouble. The developers, product managers, business people, and customers are happy.</p><h3>When is the architecture right?</h3><p>This really depends on which kind of project you do. If you do a small prototype you are going to throw away, you don’t need the best architecture. I like the following tweet from<a href="https://twitter.com/abreslav"> Andrey Breslav</a>, the lead language designer of Kotlin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/0*HbdpEoAJ0Yb5O1f4" /></figure><p>In most of the cases though you are going to release and maintain the built system and add new features later on. Robert C. Martin states in his book <a href="https://www.goodreads.com/book/show/18043011-clean-architecture">Clean Architecture</a>:</p><blockquote>“The goal of software architecture is to minimize the manpower required to build and maintain the required system.”</blockquote><p>So how can we achieve that? There are lots of different coding and architecture skills, that bring us closer to this goal. It is important to understand, that being a superb coder doesn’t make you a great software architect and vice versa.</p><p>Some software architects use a method, called ATAM, to evaluate the quality of existing or future software architectures. <a href="https://en.wikipedia.org/wiki/Architecture_tradeoff_analysis_method">ATAM</a> stands for Architecture Tradeoff Analysis Method. It has 9 steps and can require up to 30 people for days of effort. For software engineers without proper knowledge about software architecture and the ATAM I created a simplified version called <strong>LAAM — Lean Architecture Analysis Method.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mQk--q-2fUnS_z9s5rfrjA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/YfCVCPMNd38?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ludde Lorentz</a> on <a href="https://unsplash.com/search/photos/architecture?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>LAAM to get it right</h3><p>LAAM<strong> </strong>should help software engineers to get their software architecture right. It consists of four steps.</p><ul><li>Collect quality metric goals</li><li>Brainstorm quality scenarios</li><li>Generate architectural approaches</li><li>Analyse approaches</li></ul><p>You can remember the steps by <strong>MSGA</strong> — <strong>M</strong>y <strong>S</strong>olution’s <strong>G</strong>onna be <strong>A</strong>wesome: <strong>M</strong>etrics, <strong>S</strong>cenarios, <strong>G</strong>enerate, <strong>A</strong>nalyse</p><h3>Collect quality metric goals</h3><p>As a starting point you need to define how to measure your architecture. You do this by coming up with a prioritised list of quality metric goals. Make sure to include all different stakeholder views: users, management, product owners, QA, developers, support, … Keep in mind you don’t actually have to invite all stakeholders into a meeting. Otherwise you are going to end up with a huge round. The following image shows a few examples for quality metrics:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qhDcEfRDd7rd64lq" /><figcaption><a href="http://iso25000.com/index.php/en/iso-25000-standards/iso-25010">ISO 25010 software product quality metrics</a></figcaption></figure><p>Some of the quality metrics are in conflict with each other. A few examples:</p><ul><li>High modifiability sometimes leads to lower performance. By having multiple layers of abstraction, models need to be mapped from the database to plain business objects, which leads to lower performance.</li><li>Concurrent high usability and high security is hard to achieve. Forcing users to use two factor authentication or long passwords has a negative effect on usability.</li><li>Having multiple servers with data replication for high availability and faster response time reduces the integrity of the data.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SKX7yu4wr4OljsHsUXhU2A.jpeg" /><figcaption>Dot Voting</figcaption></figure><p>After defining the quality goals, it is good to prioritise them. You can use dot voting for this. Every participant gets a fixed number of dots and can put one or more dot on the most important quality goal from his perspective. Make sure that everyone chooses where to put his dots before actually placing them. When everyone is ready and has chosen their most important quality goals, put all dots down simultaneously not thinking where the others put theirs. This way you avoid influencing each other and being a victim of the <a href="https://en.wikipedia.org/wiki/Bandwagon_effect">Bandwagon Effect</a>.</p><h3>Brainstorm quality scenarios</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8s-VzNIcca2gZ3JNLseODw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/-1_RZL8BGBM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kelly Sikkema</a> on <a href="https://unsplash.com/search/photos/brainstorming?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>At this step you collect different scenarios for your architecture. In the final step we are going to test our architecture against them. Especially here it is beneficial to include distinct stakeholders and more people to get various perspectives. Again keep in mind, you don’t have to set up a meeting for that. You can group your scenarios into three different types:</p><ul><li><strong>Typical</strong>: these are typical use cases such as the new feature needing to be able to handle 1000 concurrent users.</li><li><strong>Growth</strong>: this is anticipated changes related to growth. For example, the new feature needs to handle 100.000 concurrent users.</li><li><strong>Exploratory</strong>: here you think about extreme changes to your architecture. For example, adding a web application to your existing native apps.</li></ul><p>Like the quality goals, the scenarios need to be prioritised by whatever make sense for you. If you have too many scenarios, you can cut out the lower priority ones. It is more efficient to only analyse the top priority scenarios.</p><h3>Generate architectural approaches</h3><p>Come up with one or more architectural approaches for your task or project. You can also skip this step if you want to analyse an already existing architecture. How you come up with an architecture is open to you. I don’t cover that in this blog post. However, here is some advice:</p><p><a href="https://blog.codinghorror.com/dont-reinvent-the-wheel-unless-you-plan-on-learning-more-about-wheels/">Don’t Reinvent The Wheel, Unless You Plan on Learning More About Wheels</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_LCHRQiq3pF_pV1T.jpg" /></figure><p>Reinventing the wheel can be seen as an<a href="https://sourcemaking.com/antipatterns/reinvent-the-wheel"> anti pattern</a>.There are lots of great architectures out there that fulfil certain quality goals and are proved over the years by many good software engineers. For more information refer to these books and articles:</p><ul><li><a href="https://www.goodreads.com/book/show/85009.Design_Patterns?ac=1&amp;from_search=true">Design Patterns: Elements of Reusable Object-Oriented Software</a></li><li><a href="https://www.goodreads.com/book/show/70156.Patterns_of_Enterprise_Application_Architecture">Patterns of Enterprise Application Architecture</a></li><li><a href="https://www.martinfowler.com/articles/enterprisePatterns.html">Patterns in Enterprise Software</a></li></ul><p>The output of this step can be different mediums, starting from a verbal description, a simple sketch on a whiteboard up to a proper UML diagram. In my opinion it’s always good to try to do proper UML when you do an architecture diagram. I know it’s complicated and can be annoying, but there is less room for interpretation. Some tools I personally like to sketch my architectures are <a href="http://plantuml.com/">PlantUML</a> and <a href="https://www.draw.io/">draw.io</a>, which has a nice JIRA and Confluence integration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W6-WCkE3fZ18WqgE30yyqg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/T5nXYXCf50I?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Maarten Deckers</a> on <a href="https://unsplash.com/search/photos/architecture?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Analyse approaches</h3><p>Now you are ready to analyse the architectural approaches. At this step you want to find out if your approaches fulfil the quality goals and how the quality scenarios affect your architecture. Doing this together with another developer makes sense.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8c333d_YNEHG4q3UDb1wTA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/5fNmWej4tAA?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Helloquence</a> on <a href="https://unsplash.com/search/photos/software?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Go through each of your approaches, play through each of your scenarios and estimate the effect on your quality goals. During this step look for risks, sensitivity points and tradeoffs. A <strong>sensitivity point</strong> is a property of the architecture that is critical for fulfilling quality goals. A small change to it is likely to have a huge effect. For example the minimum length of a password or the bits for encryption have both an effect on security. So when the security goal is increased, they are very likely to change. A <strong>tradeoff</strong> is a property that is a sensitivity point for more than one attribute. If one thing increases, some other thing must decrease. For example:</p><ul><li>Redundant replication of data increase availability, but reduces integrity.</li><li>Complicated encryption algorithm with long key increases security, but reduces performance.</li><li>Layered architecture increases understandability and changeability, but reduces performance.</li></ul><p>Shortly document the outcome and then go on to the next approach. Finally, compare your different approaches and choose one. Having written down the facts helps you to make an objective decision. Now you should know if your architecture is going to have a good quality or not.</p><p>If none of your approaches are satisfying, try to come up with a new approach and don’t adjust your quality scenarios and goals. Maybe you find out that some of your quality goals are in conflict with each other. This case then is tradeoff. It’s not possible to have the highest usability with the highest security. In this case you have to go to your stakeholders and tell them that you need to make some sacrifices and lower one of the quality goals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l5ndOY1nXRqxAlvZ2HYiNA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/DoveRW4-cMo?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">emmad</a> on <a href="https://unsplash.com/search/photos/highway?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Conclusion</h3><p>To perform the LAAM, little preparation is needed and it can even be done under an hour already having a software architecture in place. Make sure to include various people to get different perspectives. Then apply the four steps: collect quality metric goals, brainstorm quality scenarios, generate architectural approaches and analyse the approaches. Maybe my mnemonic helps to remember the steps: <strong>MSGA</strong> — <strong>M</strong>y <strong>S</strong>olution’s <strong>G</strong>onna be <strong>A</strong>wesome: <strong>M</strong>etrics, <strong>S</strong>cenarios, <strong>G</strong>enerate, <strong>A</strong>nalyse</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KVE3tN4eZ2k5ElXaZ7pm-Q.png" /><figcaption>Photo by <a href="https://unsplash.com/photos/HkF6feHrGBE?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ryan Wilson</a> on <a href="https://unsplash.com/search/photos/cityscape?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><strong>Pro tip</strong>: Document each step of the LAAM. This guards you against future accusations and helps you to understand why you made the decision even one year later. If a product manager or other developers accuse you that the architecture is not right, you have some evidence to prove why you decided for a certain architecture. You can show for which quality goals and scenarios the architecture is built. If the goals and scenarios change, so might the need for your architecture to change.</p><p>Further Readings about the ATAM:</p><ul><li><a href="https://resources.sei.cmu.edu/library/asset-view.cfm?assetid=513908">Architecture Tradeoff Analysis Method Collection</a></li><li><a href="https://resources.sei.cmu.edu/asset_files/TechnicalReport/2000_005_001_13706.pdf">ATAM: Method for Architecture Evaluation</a> PDF</li><li><a href="https://www.goodreads.com/book/show/25380761-software-architecture-in-practice-3-e">Software Architecture in Practice</a>, Chapter 21</li><li><a href="http://www.softwarearchitectures.com/evaluation.html">Evaluating Software Architecture</a></li><li><a href="https://www.goodreads.com/book/show/18043011-clean-architecture">Clean Architecture: A Craftsman’s Guide to Software Structure and Design</a> (Robert C. Martin), Chapter 15</li></ul><p><strong><em>Got feedback? I’d love to hear from you what you think about this article. If you like it, clap for it and share it.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89287a980f1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/monsterculture/getting-your-software-architecture-right-89287a980f1b">Getting Your Software Architecture Right</a> was originally published in <a href="https://medium.com/monsterculture">Monster Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Decompile an APK]]></title>
            <link>https://medium.com/@philipp.hofmann/how-to-decompile-an-apk-131a84651112?source=rss-fd80f0dca539------2</link>
            <guid isPermaLink="false">https://medium.com/p/131a84651112</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[decompile]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[Philipp Hofmann]]></dc:creator>
            <pubDate>Wed, 15 Aug 2018 14:19:31 GMT</pubDate>
            <atom:updated>2018-08-15T18:47:04.936Z</atom:updated>
            <content:encoded><![CDATA[<p>There are several motivations to decompile an APK. Maybe you are interested in the code of an existing app or you want to know what others could find out decompiling your app. Don’t expect, that you can get the source code of all the apps on the Play Store though. Most apps use obfuscation to replace the class and function names with short random characters. Read more about code obfuscation here: <a href="https://developer.android.com/studio/build/shrink-code">https://developer.android.com/studio/build/shrink-code</a></p><p>This article describes how to easily decompile an apk. A basic knowledge about Android is needed to understand this article.</p><h3>1 . Let’s look into the APK</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-xPITaS0MJVazrDf" /></figure><p>An APK is a type of an archive file. You can change the file ending to .zip and then unzip it. The unzipped folder contains a classes.dex file with the Dalvik bytecode in it. Furthermore, the folder holds the compiled manifest and resources.</p><h3>2. Use dex2jar to decompile</h3><p>The<a href="https://github.com/pxb1988/dex2jar"> dex2jar</a> tools helps us to decompile those files. You can download it here <a href="https://sourceforge.net/projects/dex2jar/files/">https://sourceforge.net/projects/dex2jar/files/</a>. Now let’s decompile our app.</p><p>On Mac or Linux you might have to give the script the permission to be executed.</p><pre>sudo chmod +x d2j-dex2jar.sh d2j_invoke.sh</pre><p>Open your console or terminal and type:</p><ul><li>On Windows d2j-dex2jar.bat path/to/your-app.apk</li><li>On Mac or Linux d2j-dex2jar.sh path/to/your-app.apk</li></ul><p>The dex2jar tool generates a your-app-dex2jar.jar, which we can now decompile with Android Studio.</p><h3>3. View decompiled classes in Android Studio</h3><p>Open an existing project or create a new one in Android Studio and change to project view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/0*x9MaqVr_hD5f8tg0" /></figure><p>Copy the your-app-dex2jar.jar file somewhere into the source files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/0*ZxYx5KXxeiY_wEjm" /></figure><p>Right click on the jar file and select “Add as Library”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/0*K2G6oaEow_pssEp8" /></figure><p>After the gradle sync completed you can expand the jar and take a look at the decompiled code.</p><p><strong><em>Got feedback? I’d love to hear from you what you think about this article. If you like it, clap for it and share it.</em></strong></p><p>Follow me on <a href="https://twitter.com/muffls">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=131a84651112" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git aliases at mySugr]]></title>
            <link>https://medium.com/monsterculture/git-aliases-at-mysugr-686f9acf4b3e?source=rss-fd80f0dca539------2</link>
            <guid isPermaLink="false">https://medium.com/p/686f9acf4b3e</guid>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[command-line]]></category>
            <dc:creator><![CDATA[Philipp Hofmann]]></dc:creator>
            <pubDate>Fri, 03 Nov 2017 13:33:47 GMT</pubDate>
            <atom:updated>2017-11-06T17:45:10.006Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nWReuL4KVhAHums1UOTvOw.png" /><figcaption>Using git alias on the terminal</figcaption></figure><p>Some developers at mySugr love to use the command-line for git. If you don’t want to type all the commands in full length all the time, you can use Git aliases. Examples:</p><ul><li>git status turns into git s</li><li>git commit -m turns into git c</li><li>git checkout turns into git co</li></ul><p>The following shows our favourite Git aliases. Just add this to your .gitconfig file in your $HOME directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d85e31007d72471a9d07e71cdfb12d7/href">https://medium.com/media/2d85e31007d72471a9d07e71cdfb12d7/href</a></iframe><p>Thanks to <a href="https://www.xing.com/profile/Lukas_Streiter">Lukas Streiter</a> for the git log aliases.</p><h3>Push to origin</h3><p>A common scenario for us is to create a branch and then push it to the origin. If you use the aliases, you just type git p. But then Git tells you that your branch doesn’t have an upstream branch yet:</p><pre>user$ git psu<br>fatal: The current branch feature/login has no upstream branch.<br>To push the current branch and set the remote as upstream, use</pre><pre>  git push --set-upstream origin feature/login</pre><pre>user$</pre><p>What we usually did was copy git push --set-upstream origin feature/login or manually typegit psu origin feature/login , but this is very annoying and slow.</p><p>To avoid this you can set the push.default to current in your .gitconfig (see <a href="https://git-scm.com/docs/git-config#git-config-pushdefault">git-config documentation</a>). If you want to set it globally: git config --global push.default current .</p><p><a href="https://mysugr.com/"><em>mySugr</em></a><em> specializes in app-based, all-around care for people with diabetes — made by people with diabetes. Our apps, services, and access to the world’s best diabetes coaching at the tap of a finger all work together to ease the daily grind of diabetes. In short, we make diabetes suck less!</em></p><p><em>Interested in joining our engineering team? </em><a href="https://mysugr.com/jobs"><em>We’re hiring!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=686f9acf4b3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/monsterculture/git-aliases-at-mysugr-686f9acf4b3e">Git aliases at mySugr</a> was originally published in <a href="https://medium.com/monsterculture">Monster Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating an Android App from Java to Kotlin]]></title>
            <link>https://medium.com/monsterculture/moving-from-java-to-kotlin-on-android-f60c593c39f8?source=rss-fd80f0dca539------2</link>
            <guid isPermaLink="false">https://medium.com/p/f60c593c39f8</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Philipp Hofmann]]></dc:creator>
            <pubDate>Fri, 03 Nov 2017 13:33:06 GMT</pubDate>
            <atom:updated>2019-12-16T16:08:18.016Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*vKWCukAPlbDjUFLhiP827A.jpeg" /><figcaption>mySugr office in Vienna</figcaption></figure><p>One year ago when developing Android, you were limited to Java 6 with some features of Java 7. If you are used to Java 8, C#, Groovy, or Swift, you feel limited with Java 6. There is no type inference, lambdas, properties, extension methods, non-nullability, etc. Some developers were using <a href="https://github.com/orfjackal/retrolambda">Retrolambda</a> to ease the pain, which allows you to use Java 8 code with lambda expressions and method references on Java 7, 6 or 5. Others used <a href="https://projectlombok.org/setup/android">Lombok</a> to get rid of the boilerplate generated getters and setters.</p><p>Even still, using Java 7 with Retrolambda and Lombok was not satisfying for us at mySugr. That’s why Kotlin caught our attention. It was still a quite new language one year ago and we didn’t have any experience with it. Having cool features like C#, Groovy, and Swift do, and compiling to Java 6 bytecode, which means you can run it on Android, convinced us to take a closer look at Kotlin. Our biggest concern in the beginning was that Google did not officially support Kotlin on Android, even though the popularity of Kotlin was already growing. For example, Jake Wharton gave <a href="https://speakerdeck.com/jakewharton/android-development-with-kotlin-androidkw-number-001">a talk</a> in December 2015, that we Android developers are stuck with Java 6 and we needed a revolution like Kotlin. So we wanted to be a part of this revolution and push Kotlin, so that hopefully Google will officially support it soon. We also still had a few major concerns:</p><ul><li>Is it interoperable with Java?</li><li>How hard is it to move Java to Kotlin code?</li><li>Does it affect the performance and how big is the overhead?</li><li>Will it cause any problems? If yes, how big are they?</li></ul><h3>Let’s try Kotlin</h3><p>Our entire codebase was in Java, therefore we had the concern if Kotlin could play nicely alongside with Java. We started with configuring Kotlin for our app and wrote our first classes. The plan was that a new code is written in Kotlin and we steadily convert those classes from Java as we touch them. Soon we found out that both work fine together: you can call Java code from Kotlin and vice versa. Actually, the interoperability with Java is one of the core features of Kotlin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NeDR1x5SesymBkEw45FPQ.png" /></figure><p>The Kotlin plugin for the Android Studio has a feature for converting Java to Kotlin classes. You can find it under <strong>Code &gt; Convert Java File to Kotlin File</strong>. Also, when you paste Java code snippets to a Kotlin file, the plugin prompts you if you want to want to convert the pasted code to Kotlin. There were a few minor problems with nullability, not using lateinit, or overusing companion objects occur most of the time which then force you to make smaller changes to the converted code, but we never had major problems. On the whole, the conversion works fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mIEJKaGXgH8fgy3tEd9kRA.png" /><figcaption>Kotlin build process, from <a href="https://www.goodreads.com/book/show/29242249-kotlin-in-action">Kotlin in Action</a></figcaption></figure><p>What about the overhead and the performance? Since Java compiler doesn’t optimise the byte code during compilation, but leaves it to the java runtime, Kotlin compiler wasn’t something that worried us. What did worry us, however, is how Kotlin implements some features that are not available in Java 6, like lambdas. For lambdas, unless they are inlined, the Kotlin compiler generates an object on the heap for each lambda. If you were using Java, you would have to create an anonymous class. So there is not a big difference. The standard library and the runtime jar files are less than 1 megabyte and they contain around 6500 methods. So the overhead of Kotlin is small, especially compared to Android support libraries. According to the <a href="https://developer.android.com/kotlin/get-started.html">Android documentation</a>, Kotlin should not affect the performance of the app. Although, in a <a href="https://sites.google.com/a/athaydes.com/renato-athaydes/posts/kotlinshiddencosts-benchmarks">blog post </a>, Renato Athaydes benchmarks some hidden costs of Kotlin, just as Christophe B. also described it in a <a href="https://medium.com/@BladeCoder/exploring-kotlins-hidden-costs-part-1-fbb9935d9b62">blog post series</a>. Almost all of the features from Kotlin have a performance cost below 5%. Calling forEach on Ranges, for example, has a cost around 300% and should be avoided. So, overall this is not a show breaker for us. If you notice performance breakdowns, which we didn’t, it’s good to know those issues. Furthermore, you can always go back to write performance critical code in Java.</p><h3>Problems with Kotlin</h3><p>A lot of current blog posts demonstrate how fancy Kotlin is, but we also had some problems with it.</p><h4>Annotation Processing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*pzUMGxyVOUh0X-6FPgpnpw.png" /><figcaption>Enable Kotlin kapt in the gradle file</figcaption></figure><p>The biggest problem is that the Kotlin Annotation Processing Tool (KAPT) is still somewhat buggy. APT is needed for some of the most popular Android libraries, like Dagger, Retrofit, and Realm.</p><p>Last year, we wrote a small part of our app that calculates how much insulin a user should inject as a standalone module completely in Kotlin. When we integrated the module into the mySugr app, we had strange build errors. We could trace them back to Dagger and Kotlin APT. So we had two different options: Either use Java and Dagger, or Kotlin without Dagger. We liked Kotlin way more than Dagger. Therefore, we dropped Dagger and created our own dependency injection. We are going to show you this in another blog post.</p><p>We still have problems with Dagger in the mySugr app. Our current workaround is to write our modules and components for Dagger in Java, which is not a huge drawback for us. What is a little bit annoying is that we have to write our Realm entities in Java. But again, if we were using Java, we would have to write them in Java anyway.</p><p>What is working fine with Kotlin is Retrofit. Our entire code with Retrofit is written in Kotlin.</p><h4>Mockito</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*kERQQDm5nmkmIfshOhwH-Q.png" /></figure><p><a href="https://github.com/mockito/mockito">Mockito</a> often returns null when using methods like any(), eq()or argThat(). Because Kotlin has null safety, it throws a NullPointerException when null from Mockito is passed to non-nullable parameters. Another library, <a href="https://github.com/nhaarman/mockito-kotlin">Mockito-Kotlin</a>, is supposed to solve this problem. Having problems with Mockito-Kotlin and not wanting to be dependent on another library, we found a simpler solution. We just use the <a href="https://kotlinlang.org/docs/reference/null-safety.html#elvis-operator">Elvis Operator</a>. For example, we have a class LoginService with a method login. We want to mock the login method in a unit tests and use argThat(). The only thing we need to do is to append ?: “” after argThat()and it is working.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8eb5d77e7a3320233af26fe42d294f4c/href">https://medium.com/media/8eb5d77e7a3320233af26fe42d294f4c/href</a></iframe><p>There is also an issue with mocking Kotlin classes, which are final by default. Before, Mockito v2 a class needed to be open, so proxy classes can be generated for it. If you can’t use Mockito v2 this forces to declare your classes as open or to implement interface behind each class you intend to mock.</p><h4>Kotlin Compiler</h4><p>Until now, we only had one problem with Kotlin compiler. We experienced a strange bug with the Elvis operator, which caused a method to exit early if variable is null. When trying to reproduce it with similar code, outside of our code base, everything worked fine. Also, inspecting Kotlin generated bytecode showed nothing wrong. So, we are still not sure what was happening.</p><h4>Android Studio Plugin</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*RL2ge-4ddySqPZWWbbI0Ng.png" /><figcaption>Kotlin Plugin</figcaption></figure><p>Jetbrains provides Kotlin language support with a plugin for Android Studio. For each new version they release, they also publish a new version of the plugin. We experienced issues several times when the version of the runtime and the plugin didn’t match. When this happened, suddenly, the annotation processing was not working anymore. We also had strange issues with android data binding or other random compile errors. So, now, we try always to keep both runtime version and plugin version in sync. Since doing that, we don’t have any problems.</p><h3>Conclusion</h3><p>After over one year experience with Kotlin, we have to admit we had several problems. Some very easy to fix, others little bit harder. All in all, we could resolve the issues and it caused less problems than we expected. Android developers at mySugr love Kotlin and can’t imagine to live without it. We love it so much that we already started to use it also on the backend, where we use currently Java 8, and the pain is not so huge as with Java 6. When we have more experience, we are going to write about this in another blog post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DvIYrgwJ9EfAYv_JeL74nA.png" /></figure><p>In the end, we are proud to be one of the early adopters of Kotlin, and were very happy when Google announced the official support for it on May 17th, 2017 during Google I/O.</p><p>Thanks to <a href="https://medium.com/@madevcic">Marko Devcic</a> for the initial ideas and parts of this blog post.</p><p><a href="https://mysugr.com/"><em>mySugr</em></a><em> specializes in app-based, all-around care for people with diabetes — made by people with diabetes. Our apps, services, and access to the world’s best diabetes coaching at the tap of a finger all work together to ease the daily grind of diabetes. In short, we make diabetes suck less!</em></p><p><em>Interested in joining our engineering team? </em><a href="https://mysugr.com/jobs"><em>We’re hiring!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f60c593c39f8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/monsterculture/moving-from-java-to-kotlin-on-android-f60c593c39f8">Migrating an Android App from Java to Kotlin</a> was originally published in <a href="https://medium.com/monsterculture">Monster Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>