<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Trevor Nemanic</title>
    <description>The latest articles on Forem by Trevor Nemanic (@trevornemanic).</description>
    <link>https://forem.com/trevornemanic</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%2F137352%2Fa564877e-4e04-40c6-a8ee-77aa90d87209.jpg</url>
      <title>Forem: Trevor Nemanic</title>
      <link>https://forem.com/trevornemanic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/trevornemanic"/>
    <language>en</language>
    <item>
      <title>12 Quick Tips From the Gradle Enterprise Workshop</title>
      <dc:creator>Trevor Nemanic</dc:creator>
      <pubDate>Thu, 14 Nov 2019 15:54:56 +0000</pubDate>
      <link>https://forem.com/trevornemanic/15-quick-tips-from-the-gradle-enterprise-workshop-469k</link>
      <guid>https://forem.com/trevornemanic/15-quick-tips-from-the-gradle-enterprise-workshop-469k</guid>
      <description>&lt;p&gt;The team at Gradle held their Enterprise Workshop to help diagnose build performance issues, shorten the feedback cycle between compiling and running code, and improve toolchain reliability. Furthermore, there was a short introduction by Airbnb about how they use Gradle Enterprise and treat developer productivity. This post will cover many of the small build performance tips presented by Airbnb and Gradle, without focusing on the offerings of Gradle Enterprise.&lt;/p&gt;

&lt;p&gt;Airbnb's tips&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Detect flakey tests and get rid of them. Airbnb uses a private tool, called Arborist, to do this, but it can be done manually too.&lt;/li&gt;
&lt;li&gt;Build scans are incredibly important to finding slow Gradle tasks. They provide historical data which allow build performance engineers to triage the highest impact issues. &lt;/li&gt;
&lt;li&gt;Build scans provide a convenience for diagnosing build issues. A software engineer does not need to be colocated with the build engineer to find an issue, allowing for faster turnaround time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Gradle's tips&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Toolchain efficiency importance grows as team size grows. More developers lead to a larger code size, number of libraries, and complexity of modules.&lt;/li&gt;
&lt;li&gt;Developer happiness is directly related to developer productivity. A developer does not want to wait for code to compile, and even worse does not want to see build times increase over time.&lt;/li&gt;
&lt;li&gt;Build performance improvements are difficult to pitch to those in product since it does not directly tie in with metrics like user revenue or new user growth. However, wasted developer time is much easier to pitch as it controls how much can be completed in a development cycle.&lt;/li&gt;
&lt;li&gt;To calculate build performance improvement, a simple equation such as build time * num local builds = total loss can help convince those in product. A team of five people can gain ten to twenty hours per week of valuable programming time with a 25 percent improvement in build performance. &lt;/li&gt;
&lt;li&gt;Build scans (&lt;code&gt;./gradlew build --scan&lt;/code&gt;) analyze your build and suggest performance enhancements. If you use Gradle and haven't used build scans before, then I hope you try it and see the magic yourself. Even better, they're free!&lt;/li&gt;
&lt;li&gt;An easy gain in build performance is to convert some of your eager Gradle API usages to lazy API usages. Use build scans to see the difference.&lt;/li&gt;
&lt;li&gt;Another build performance tip is to move file system and network access out of the Gradle configuration phase and into execution.&lt;/li&gt;
&lt;li&gt;Timestamps (&lt;code&gt;System.currentTimeMillis()&lt;/code&gt;) generated in Gradle tasks can prevent the task from being cached, causing a huge performance hit. The Gradle build system can be told to ignore the "volatile" property. &lt;/li&gt;
&lt;li&gt;Performance regressions easily happen over time. A developer can add a useful annotation library, unknowingly causing huge amounts of generated code to be built. The most reliable way to prevent build performance loss over time is to measure it and flag regressions.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>gradle</category>
      <category>enterprise</category>
      <category>performance</category>
      <category>android</category>
    </item>
    <item>
      <title>Tips to survive a super commute (90+ minutes)</title>
      <dc:creator>Trevor Nemanic</dc:creator>
      <pubDate>Sat, 23 Mar 2019 18:32:05 +0000</pubDate>
      <link>https://forem.com/trevornemanic/tips-to-survive-a-super-commute-90-minutes-b1</link>
      <guid>https://forem.com/trevornemanic/tips-to-survive-a-super-commute-90-minutes-b1</guid>
      <description>&lt;p&gt;Super commuters commit at least 90 minutes grinding their way to and from work. The commute creates unnecessary stress and upsets work-life balance. This post is aimed at improving the lives super commuters by giving them useful day-to-day techniques. Personally, I have been super commuting for 11 months and have developed several tips out of necessity. They support me in a variety of ways, including lowering stress, improving productivity, and saving valuable time at home.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Focus on work while commuting to work.&lt;/strong&gt; &lt;br&gt;
I work on the train and it prepares me to be ready to hit the ground running in the office. The Harvard Business School found this practice of "pre-work" to ease mentally switching between home-life and work-life. They also found that listening to music or browsing social media may increase chances for a stressful work day. On your next commute, spend time catching up on emails and doing whatever sets you up to be successful. If you're in a car, you can use an email reader to listen to your emails out loud, and write your responses in a voice note.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. De-stress on your way home.&lt;/strong&gt; &lt;br&gt;
This will prepare you to transition back into your home life and negate the side-effects of commuting. I have been practicing mindfulness with Headspace and it helps me de-stress in only three to ten minutes. Once practiced, it is more effective than trying to rest or zone out. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Have an end goal in mind.&lt;/strong&gt; &lt;br&gt;
One of the worst parts about super commuting is the feeling that you have committed the rest of your life to living in limbo. Instead, have a long term plan for reducing the distance and time between you and your job. Whether it be to increase your income so you can move closer or improve your job so it can be physically closer to you, make sure you have something in mind. Then, you can have a more positive outlook on the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Make a to-do list of things you want to do at both work and home.&lt;/strong&gt;&lt;br&gt;
This will separate the two concerns and increase productivity. I prefer to keep my personal list on my phone and work list on my laptop. Therefore, I stay focused on whichever part of my life I am presently at.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Set reminders in your phone to help you switch focus.&lt;/strong&gt;&lt;br&gt;
 Super commuting eats away your free time, so it is important to judiciously utilize your commute time. When I have a stressful day at work, I will set a calendar appointment to use Headspace right when I get to my train. Then, I will feel refreshed and can focus the remaining hour and 15 minutes on productive home tasks (planning the next vacation, what I'm doing for dinner, etc). &lt;/p&gt;

&lt;p&gt;I hope these tips are as beneficial to you as they are to me. Did I miss something which makes your super commute effective? Let me know in the comments! You can also &lt;a href="https://twitter.com/TrevorNemanic"&gt;follow me on Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Further reading:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Harvard Business School
&lt;a href="https://hbswk.hbs.edu/item/stuck-in-commuter-hell-you-can-still-be-productive?cid=wk-rss"&gt;https://hbswk.hbs.edu/item/stuck-in-commuter-hell-you-can-still-be-productive?cid=wk-rss&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>career</category>
      <category>productivity</category>
      <category>commuting</category>
    </item>
    <item>
      <title>The Most Exciting Features Coming to Android Q</title>
      <dc:creator>Trevor Nemanic</dc:creator>
      <pubDate>Fri, 15 Mar 2019 00:25:57 +0000</pubDate>
      <link>https://forem.com/trevornemanic/the-most-exciting-features-coming-to-android-q-3kmc</link>
      <guid>https://forem.com/trevornemanic/the-most-exciting-features-coming-to-android-q-3kmc</guid>
      <description>&lt;p&gt;Google has publicly released Android Q Beta, the newest version of Android. With it comes many nice-to-have improvements for users. Google has largely focused on privacy, security, and performance, while preparing for the latest trends like foldables. Without further ado, let's dive into the best features in Android Q.&lt;/p&gt;

&lt;h2&gt;
  
  
  Foldables
&lt;/h2&gt;

&lt;p&gt;Foldable phones have made their great debut in 2019. Whether you love them or hate them, expect to see a lot of news about companies, developers, and users trying out this new form factor. Developers won't be able to test foldables on the existing Android emulator yet (Google is working on that).&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TAvrEKMp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/hwet3nwtbpxjhrra07zm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TAvrEKMp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/hwet3nwtbpxjhrra07zm.png" alt="Foldable phone image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Granular Control for Location Permissions
&lt;/h2&gt;

&lt;p&gt;Google has responded to the outcry of users to protect their privacy. So long to the creepiness of giving away your location at all times. Now, the location permission option will have an additional option to only give location when the app is in use. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t2hmkBF5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/la1grucazdkpad5rk2ym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t2hmkBF5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/la1grucazdkpad5rk2ym.png" alt="Location permission option"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  WiFI Performance Modes
&lt;/h2&gt;

&lt;p&gt;Mobile gaming has emerged as a powerhouse in the app landscape. However, latency has remained an issue since many gamers rely on WiFi. Android Q will ship with the ability for apps to tell the device to use low-latency or high-performance modes. This will greatly improve the experience of mobile gamers everywhere. &lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic Depth Format
&lt;/h2&gt;

&lt;p&gt;Android phones have come a very, very long ways in terms of camera quality. Android Q will usher in another significant advancement: Dynamic Depth Format. This new format will allow apps to provide improvements to blur and similar features. Dynamic Depth Format will give app developers with the tools to actually see depth, something they have been simulating to various degrees of success. Expect to see much greater Augmented Reality and 3D images too.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CsIekA_b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/09ys24piia55u93zn63b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CsIekA_b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/09ys24piia55u93zn63b.png" alt="Dynamic Depth Format"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Interested in trying these features out on your own? &lt;a href="https://www.google.com/android/beta"&gt;Sign up for the beta!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Further reading&lt;br&gt;
Official Post by Google: &lt;a href="https://android-developers.googleblog.com/2019/03/introducing-android-q-beta.html"&gt;https://android-developers.googleblog.com/2019/03/introducing-android-q-beta.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>google</category>
    </item>
    <item>
      <title>Beginner Kotlin Runtime Check Tutorial: Require, Check, Assert</title>
      <dc:creator>Trevor Nemanic</dc:creator>
      <pubDate>Wed, 13 Mar 2019 14:51:55 +0000</pubDate>
      <link>https://forem.com/trevornemanic/beginner-kotlin-runtime-check-tutorial-require-check-assert-387l</link>
      <guid>https://forem.com/trevornemanic/beginner-kotlin-runtime-check-tutorial-require-check-assert-387l</guid>
      <description>&lt;p&gt;We often assume the state of our program is acceptable when our functions are called. Sometimes we assume the state or input can be invalid, so we do something like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;doThing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bar&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;foo&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="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;....&lt;/span&gt; &lt;span class="c1"&gt;// what you meant to do&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Both these assumptions can lead to hard-to-find errors and unreadable code. Fortunately, the Kotlin standard library provides three basic functions for ensuring everything is in order: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Require: My function needs parameters to be valid in this way. Throw an &lt;code&gt;IllegalArgumentException&lt;/code&gt; when false.&lt;/li&gt;
&lt;li&gt;Check: My function's dependency is in the correct state to be called. Throw an &lt;code&gt;IllegalStateException&lt;/code&gt; when false.&lt;/li&gt;
&lt;li&gt;Assert: My function's result is valid. Throw an &lt;code&gt;AssertionError&lt;/code&gt; when false. Also, runtime assertions have to be enabled on the JVM with &lt;code&gt;-ea&lt;/code&gt; or enabled with Native.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In addition to validation of a condition, each one of these functions has an optional lazy argument for an error message if evaluated to false. All three runtime check APIs are the same. Here is an example from &lt;code&gt;require&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&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="k"&gt;inline&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&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="n"&gt;lazyMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's take a look at each runtime check in depth, then write code to fire a laser cannon&lt;/p&gt;

&lt;h1&gt;
  
  
  Require
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Require&lt;/code&gt; is used for parameter validation. It ensures its parameter is in a valid state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;fireLaser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cannonNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cannonNumber&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"Must pass a valid cannon number: $cannonNumber &amp;lt; 0"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;....&lt;/span&gt; &lt;span class="c1"&gt;// fire laser beams!!!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Check
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Check&lt;/code&gt; makes sure our function's dependencies can be called safely. It is used to verify everything is ready to go.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;fireLaser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// setup above&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;laserCannonManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isReadyToFire&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"You must arm the lasers before firing!"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;....&lt;/span&gt; &lt;span class="c1"&gt;// fire laser beams!!!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Assert
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Assert&lt;/code&gt; does the last bit of validation before a function is done or returns. It is your last chance before handing control to another part of the program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;fireLaser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// setup above&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;fired&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;laserCannon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fire&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fired&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"cannon did not fire successfully"&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;h1&gt;
  
  
  Why runtime checks?
&lt;/h1&gt;

&lt;p&gt;They provide runtime assurance which can be useful in addition to unit tests. The checks force the program to fail fast and give the developer more info than a stacktrace from a distant failed component.&lt;/p&gt;

&lt;p&gt;Obviously, these checks shouldn't be everywhere and should be added judiciously. Crucial functions which exist in a complicated space would benefit the most. See below how all three runtime checks  ensure proper usage of our core laser cannon functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;fireLaser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cannonNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// first, validate parameters&lt;/span&gt;
    &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cannonNumber&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"Must pass a valid cannon number"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// then, verify working dependencies&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;laserCannonManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isReadyToFire&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"You must arm the lasers before firing!"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;guidanceSystem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;canLockOn&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"Cannot lock on target"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// call laser code safely&lt;/span&gt;
    &lt;span class="n"&gt;laserCannonManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cannonNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;guidanceSystem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lockOn&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;laserCannon&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;laserCannonManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cannons&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cannonNumber&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;fired&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;laserCannon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fire&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// fire laser beams!!!&lt;/span&gt;

    &lt;span class="c1"&gt;// lastly, make sure our cannon fired flawlessly&lt;/span&gt;
    &lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fired&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"cannon did not fire successfully"&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;Hopefully you have a comfortable understanding of these runtime conditions. Feel free to post any questions you have in the comments!&lt;br&gt;
Did you like what you read? You can also &lt;a href="https://twitter.com/TrevorNemanic"&gt;follow me on Twitter&lt;/a&gt; for Kotlin and Android content.&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>beginners</category>
      <category>android</category>
    </item>
    <item>
      <title>Learn Kotlin Inline Functions in 3 Minutes</title>
      <dc:creator>Trevor Nemanic</dc:creator>
      <pubDate>Mon, 25 Feb 2019 16:23:19 +0000</pubDate>
      <link>https://forem.com/trevornemanic/learn-kotlin-inline-functions-in-3-minutes-51cm</link>
      <guid>https://forem.com/trevornemanic/learn-kotlin-inline-functions-in-3-minutes-51cm</guid>
      <description>&lt;p&gt;Kotlin allows functions to be passed and returned from other functions. This feature is called "first class" support for functions and brings in advantages of functional programming. To learn about &lt;code&gt;inline&lt;/code&gt;, we will go over the hidden costs of functional programming, see how &lt;code&gt;inline&lt;/code&gt; can help reduce those costs, then wrap up with places where it should not be used.&lt;/p&gt;

&lt;p&gt;A higher-order function comes with run-time penalties. First, memory is allocated for lambdas as function parameters. They are compiled to either &lt;code&gt;Function&lt;/code&gt; classes or anonymous classes, and both cost memory. Additionally, anonymous classes are slower than &lt;code&gt;Function&lt;/code&gt; classes and used only when local variables are captured. Lastly, virtual calls add unnecessary cost.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;inline&lt;/code&gt; keyword was added to Kotlin to reduce the associated costs of higher-order functions. It modifies the Java bytecode by injecting the function and its parameters directly where the function is called, the call site. Using it is easy, just add &lt;code&gt;inline&lt;/code&gt; before your function:&lt;/p&gt;


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


&lt;p&gt;To see how &lt;code&gt;inline&lt;/code&gt; impacts bytecode, consider two functionally equivalent higher-order functions, &lt;code&gt;filter&lt;/code&gt; and &lt;code&gt;filterNotInline&lt;/code&gt;. The former is part of the Kotlin standard library and the latter is a copy of it with &lt;code&gt;inline&lt;/code&gt; removed.&lt;/p&gt;


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


&lt;p&gt;Decompiling this code will show how inlining works under-the-hood. Also, it was compiled to JVM bytecode and decompiled to Java for readability. Since &lt;code&gt;filter&lt;/code&gt; is inlined, its code is copied directly. Here's the call site at the first &lt;code&gt;println&lt;/code&gt; statement.&lt;/p&gt;


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


&lt;p&gt;The less efficient version requires overhead via a function call to &lt;code&gt;filterNotInline&lt;/code&gt;, which contains code similar to the above.&lt;/p&gt;


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


&lt;p&gt;Inlining is usually great for performance, but there are good reasons why functions are not inlined by default:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using an inlined function increases code length because the function is copied to every call site. This is especially true for long functions.&lt;/li&gt;
&lt;li&gt;Inlining applies to all lambda parameters of the inlined function. So, an inlined function with three lambdas as parameters will copy them all. You can use &lt;code&gt;noinline&lt;/code&gt; on individual parameters to prevent copying.&lt;/li&gt;
&lt;li&gt;Regular &lt;code&gt;return&lt;/code&gt; statements are not allowed. You must use a label if you wish to return from your inlined function.&lt;/li&gt;
&lt;li&gt;Inline functions do not have access to data less visible than themselves.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In addition to functions, properties can be inlined too! This can be done at the individual getter and setter or the entire property.&lt;/p&gt;


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





&lt;p&gt;By now you should have an understanding of the benefits and tradeoffs of &lt;code&gt;inline&lt;/code&gt;. Feel free to post any questions you have in the comments!&lt;br&gt;
Did you like what you read? You can also &lt;a href="https://twitter.com/TrevorNemanic"&gt;follow me on Twitter&lt;/a&gt; for more Android content.&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>beginners</category>
      <category>learn</category>
    </item>
  </channel>
</rss>
