https://kotlinlang.org logo
Title
d

Daniel

05/03/2017, 12:26 PM
These kind of things shouln't go overboard, but extensions are such a good way to make the android api a bit more readable (especially the 'old' classes like many things in android.graphics)
k

kingsley

05/03/2017, 12:29 PM
ferranis: Yea. I usually find myself writing a number of extension functions on top of those good 'ol classes. Context, View and co. Makes life a lot easier
d

Daniel

05/03/2017, 12:30 PM
View in particular... why is there no view.show() method? setVisibility(View.VISIBLE) is so obscure and long
💯 1
k

kingsley

05/03/2017, 12:32 PM
ferranis: A good example is something like this:
var View.isVisible: Boolean
    get () = visibility == View.VISIBLE
    set(value) { 
        visibility = if (value) View.VISIBLE else View.GONE 
    }
...Given INVISIBLE isn't a state I use so often
d

Daniel

05/03/2017, 12:38 PM
Thats just the methods (directly on the view) that make things very readable. Also one i found useful in my project:
fun View.isTranslucent() = alpha < 1.0f
Extensions are just a great way to add domain specific things without cluttering the android api
k

kingsley

05/03/2017, 12:40 PM
I have a couple of them actually. Extension functions/properties just makes Android dev great again
I find it difficult getting much productivity out of a no-kotlin project these days
d

Daniel

05/03/2017, 12:42 PM
Kotlin in particular makes android dev great again!. Its just so much things you don't need to write or things you can express in much less code. Java has just too much boilerplate code.
k

kingsley

05/03/2017, 12:43 PM
Haha. *Kotlin. Yes ☺️
d

Daniel

05/03/2017, 12:44 PM
Also a very, very important plus for kolin: It makes tests more readable and expressive