igor.wojda
07/30/2019, 1:31 PMis
prefix for Boolean returning methods is quite straight forward. I wonder what are you thoughts on adding is
prefix to Boolean properties?
// method
view.isVisible()
// property
view.visible
or
view.isVisible
karelpeeters
07/30/2019, 1:39 PMvisible
but it's an internal struggle every time 😒imple_smile:dalexander
07/30/2019, 1:42 PMStefan Beyer
07/30/2019, 1:45 PMview.isVisible
, but it depends on whether you need the accessors to be used (by java code or some lib like jackson)
// kotlin
class Foo(val cool:Boolean,val isHot:Boolean)
// java
public class Java {
public static void main(String[] args) {
Foo foo = new Foo(true, true);
foo.getCool(); // not very cool :(
foo.isHot();
}
}
you could add @getter:JvmName("isCool")
to the property, but this is uglier than in the first place ^^karelpeeters
07/30/2019, 1:47 PMdalexander
07/30/2019, 1:49 PMisFoo
pretty heavily.arekolek
07/30/2019, 2:14 PMisVisible: Boolean
rather than visible: Boolean
Because of java interop, but also like I would write hasChildren: Boolean
and not children: Boolean
Also, there’s #codingconventions 😉igor.wojda
07/30/2019, 2:22 PMarekolek
07/30/2019, 3:13 PMview.takeIf { it.isVisible }
reads better than view.takeIf { it.visible }