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)

091 : Decompress – Reddit AMA highlights, package by feature not layer and testing!

In this decompress episode, DF and KG kick it off with a brief discussion of the highlights from the recent reddit AMA that the Android Engineering folk conducted. What were the interesting things they learnt or were surprised by etc.? They then go on to briefly discuss two topics they’ve always chatted about (off-air) packaging by feature (not layer) and most recent thoughts on testing. Listen on to find out more:

Download directly

Show Notes

360 | AnDev

AMA Reddit

Package by feature not layer

Sponsors

Contact

090: Make your apps instant with Zarah Dominguez

At I/O ’16 Google announced the super cool new feature Instant Apps. At IO’17 we started to see real world examples and third parties pull off this feature. In this episode, we talk to GDE Zarah Dominguez who’s company “Domain” was one of the partners for this program.

What is the Instant Apps feature? What are some usecases where this comes in handy? How does it actually work internally? What does it take for a developer to implement this feature in their own app? Listen on to find out!

Download directly

Show Notes

Sponsors

Contact

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

088: Offensive programming with Piwai from Square

In this episode of Fragmented we talk to our friend Piwai from Square.

Piwai’s a pro at testing and breaking apps (he built LeakCanary – so not terribly unexpected). He teaches us some strategies on debugging app crashes and briefs us on this concept he calls “offensive programming” which has helped him a lot with his Android development.

It’s good stuff and we hope you enjoy the show.

Download directly

Show Notes

Py’s libraries:

Misc resources:

Pending touches and UI event:

Contact