Skip to content

Instantly share code, notes, and snippets.

@jordanst3wart
Last active July 21, 2022 12:04
Show Gist options
  • Save jordanst3wart/27235e7d68a8372b4701aaee1543829e to your computer and use it in GitHub Desktop.
Save jordanst3wart/27235e7d68a8372b4701aaee1543829e to your computer and use it in GitHub Desktop.
Kotlin personal don'ts
// carely use get, and set, it's good with extension functions with no arguements, allowing you to not have the extra "()"
val foo2: Int get() {
println("Calculating the answer")
return 42
}
// just use this
fun getInt(): Int {
return 42
}
// don't use set, just use a method, I think it is more cleaner
class StateLogger1 {
var state = false
set(value) {
field = value
}
get() {return field }
}
// this is cleaner, and basically does the same thing
class StateLogger2(state: Boolean)
// don't use return@ notation... it's weird
val foo3 = run {
println("")
return@run 42
}
/*
* sparingly use object expressions, they replace java anonymous classes, which I have never used
* I feel like it is really always better to use another class
*/
/* sparingly use companion objects
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment