Kotlin- naming convention for boolean returning methods
Something about naming convention for properties in Kotlin, I know it's not for methods. But it's related:
From book Kotlin in Action (by Dmitry Jemerov & Svetlana Isakova) - section 2.2.1 Properties:
In Kotlin, properties are a first-class language feature, which entirely replaces fields and accessor methods.
Listing 2.5. Declaring a mutable property in a class:
class Person {
val name: String, // read only property: generates a field and a trivial getter
var isMarried: Boolean // writable property: a field, getter and a setter
}
Kotlin’s name property is exposed to Java as a getter method called getName. The getter and setter naming rule has an exception: if the property name starts with is, no additional prefix for the getter is added and in the setter name, is is replaced with set. Thus, from Java, you call isMarried().
Kotlin naming style assumes you use the Java naming conventions to the possible extend. I suggest you use this answer to the same question about Java.
UPDATE: they have released coding conventions http://kotlinlang.org/docs/reference/coding-conventions.html
For those using properties prefixed with can
, should
, etc. in mixed Kotlin/Java projects, you can also use @get:JvmName
to make the generated Java method more idiomatic for Java clients.
For example, say you have a class like this:
class User(
@get:JvmName("canView")
val canView: Boolean
)
Without the annotation, Java clients would be forced to call user.getCanView()
, but now they can call the more idiomatic user.canView()
.