One my pet peeves, shit like this sucks :
var f = MyStupidMethod();
One my pet peeves, shit like this sucks :
var f = MyStupidMethod();
val foo = new MyReallyLongUglyFactoryClass()
instead of: MyReallyLongUglyFactoryClass foo = new MyReallyLongUglyFactoryClass()
And you never have to use type inference. If you have a method where the return type isn't as obvious, you can always annotate it explicitly: val foo: Int = doSomeThing()
Do people exercise judgement about when to make the type explicit? Eh, depends on the team. But if you combine type inference with established conventions in a particular codebase (e.g. I/O calls always return IO[Foo]), you will rarely be left wondering what the type of something is.> var conn = openDatabaseConnection();
Are you actually confused about what conn represents? Does it matter what the exact type is, if you already know what it is and what you can do with it?
this line has zero readability
you're not writing code for compilers, you're writing code for people
Fundamentally, this is a story of technology getting better (type inference in compilers) so humans can do less work. We're not pushing the work to some other human place. We're not losing anything in safety, and we're gaining in readability, boilerplate and expressiveness. Its progress!
i agree, thats why i don't want to clutter my code with annotations designed for the compiler, not humans. Type inference is a _good_ thing for readability.
Since the actual size of the code base isn't an issue in the modern world, I personally like that the Kotlin ecosystem discourages the use of esoteric names and non obvious abbreviations. Once you write and read enough of it you stop making poor choices.
> var f = MyStupidMethod();
Yeh, but so does:
List<MyWeirdoFooClass> myWeirdoFoos = new ArrayList<MyWeirdoFooClass>();
Sometimes it's clear what it is. Sometimes you don't really care. Sometimes you do. You can still make it explicit when you need it to be explicit.