092: Learning Kotlin – dealing with static-ness and (companion) objects costs

In this second episode of our learning Kotlin series, we talk about Kotlin’s support for static members or … lack thereof. Kotlin as a language was designed so that there’s no such thing as a “static member” in a class but there are times when having static members can be useful.

So what do we do in those cases? do we just avoid static members? are there better alternatives? what are the costs with some of these approaches?

Listen on to find out more!

Download directly

Show Notes

Static alternatives

Cost of approaches

Look at the end of these notes for code snippets

Misc:

Sponsors

Contact

Code snippets

Cost effectiveness

// ----------------------------------------
// THIS IS BAD
class Foo {
    companion object {
        val myVar = "testing"
    }
}

// calling from Kotlin
Foo.myVar

// calling from Java
Foo.Companion.getMyVar();  // yuck

// ----------------------------------------
// THIS IS OK

// notice the Jvm annotation
class Foo {
    companion object {
        @JvmField val myVar = "testing"
    }
}

// calling from Kotlin
Foo.myVar

// calling from Java
Foo.myVar; 

// ----------------------------------------
// THIS IS AWESOME

// notice the const keyword
class Foo {
    companion object {
        const val myVar = "testing"
    }
}

// calling from Kotlin
Foo.myVar

// calling from Java 
Foo.myVar; 
// compiler additionally inlines this

// myVar is not a primitive or String?
// use @JvmField or @JvmStatic for methods

Package level options

// inside BottomSheetView.Kt
class BottomSheetView {
    companion object {
        const val BOTTOM_SHEET_ANIMATION_TIMING = 500L
    }

    // ...
}


// accessed as:
animation.setTiming(BottomSheetView.BOTTOM_SHEET_ANIMATION_TIMING)

// ----------------------------------------
// INSTEAD DO THIS

// inside BottomSheetView.Kt
const val BOTTOM_SHEET_ANIMATION_TIMING = 500L

class BottomSheetView {
    // ...
}

// accessed as:
animation.setTiming(BottomSheetViewKt.BOTTOM_SHEET_ANIMATION_TIMING)

089: Learning Kotlin – Properties a first class language feature

In this mini Fragment, KG talks about his journey learning Kotlin as a newb. Given that Kotlin is most likely going to be the de-facto language for most developers, it makes sense to deepen our understanding of the language (as we have strived with Java over the years).

“Properties” in Kotlin are a first class language feature. But what does that actually mean? What are the nifty features we get with properties? How are these resolved from a Java class when there’s potential a name clash? What are some other gotchas and learnings from using properties? Listen on to find out:

Direct download

Shownotes:

Contact

085: Casual Kotlin conversation with Dan Kim

In this episode, we talk to Dan Kim about Kotlin. Dan is an Android developer at the company Basecamp and has some great Kotlin posts on the company’s famous blog Signal Vs Noise. He was pretty early, on the Kotlin train and has been working with the new language for quite sometime now.

Instead of trying to go into every single detail about Kotlin, the nuances of the language, it’s syntax etc. we take a more general approach and talk about starting out on Kotlin, how does on go about migrating an Android codebase to Kotlin, what are things we should watch out for when using the language. This and a whole lot more!

Download directly

Show Notes

Kotlin view (binding) libs

Resources

Contact

084: Kaush and Donn go to Google IO 2017

This was truly one of the most memorable IOs Google has ever conducted. In keeping with tradition, Donn and Kaushik talk with a bunch of awesome #AndroidDev and get their opinions/thoughts on IO and Android in general. As always, these are super fun episodes.

Download directly

Show Notes

Previous Google IO Episodes

Sponsors

Contact

Living Dangerously

What a baller

geared up and ready to 🎤

Find the KG (hint: his Pixel is more prominent in this picture than his face)

How so many Android ❤️s were won

Troll masters as they revel the name of Android O to us

Many stickers were collected

020: Talking Kotlin with Hadi Hariri

A tonne of folks have been asking for a show on Kotlin. We got the best person in the business to take us through what could possibly be our new hope.

Download

Show Notes

Jetbrains products

Smaller IDES

Hadi’s 3 tips for Intellij

  1. Don’t use the Mouse! Mouseless driven development [vimeo.com]
  2. Cmd Shift A – look up other commands
  3. Don’t use the Find box to find things: Prefer shortcuts like Cmd O/Cmd Shift O

Kotlin

Getting started with Kotlin

Kotlin tools

Sample projects with Kotlin

Misc

Awesome picks:

Hadi Hariri

Kaushik Gopal

  • When looking for solutions to a problem, search the source code first before StackOverflow
  • When working on a feature, change your launcher activity (temporarily) to the one you’re working on

Donn Felker

Contact us: