If you’re like me, you’ve grudgingly put up with Java for years, for the sake of getting things done on Android. With Kotlin picking up steam as a viable, modern alternative, things are looking much better for all of us. Whenever possible, I do all my Android work in Kotlin.
To reap the fullest benefits of Kotlin, though, we can’t just fall back on old habits; it’s very easy to write code in a familiar Java style. In fact, allowing this was a design goal of Kotlin, to make it easier to transition between languages. But the real power and beauty of Kotlin is where it differs from Java, sometimes drastically. Let’s take a look at some examples of code patterns I’ve run across in production code, and different ways we can improve upon them.
Fellow nerd and game developer Alex Ferbrache (@AlexFerbrache) asked Andy Nguyen (@pixelatedpost) at San Diego’s Pocketwatch Games (@pocketwatchg) to file LEADtoFIRE bugs in the form of interweb click-bait headlines. The results are magical and speak for themselves.
My current favorites: “Once you see this GIF you’ll realize units have spawned wrong this whole time!” and “When I was losing a match I thought it couldn’t get any worse. Then something amazing happened.”
Alex says he regrets the dark magic he’s unleashed upon the world. I say, bring it on! You can follow the original posts and discussion threads here and here.
Some of you may have noticed that AndroidStudio really wants you to develop for Lollipop–so much so that if you try to create a new project for any of the 4.x versions, it will be broken out of the box. Now, I’m not sure how widespread this problem is, so as a disclaimer, I’ll say I have this problem every time, with the most up-to-date version of AndroidStudio from the Beta channel, on my machine. Here’s some relevant system configuration data:
- Mac OS X 10.8.5
- AndroidStudio 1.1.0
- javac 1.6.0_65
- Android SDK Build Tools 21.1.2 (with a few older versions still installed)