90 points · by metadat · 4y ago · 118 comments
On the other hand, we have several hundred java projects, with a very low project failure rate.
Maybe java is missing some things that are trendy and you get used to using, the things we missed most in kotlin was working code that was easy to debug, repurpose and deploy.... Stupid issues like the compiler not working properly or just taking ages burnt to much developer time, and to hard to find staff to make it up.
But heh, maybe I'm old fashioned, it doesn't seem like a popular opinion. But nothing in this thought piece seems to address those fundamental issues.
Don't get me wrong, Kotlin has some nice language improvements, but overall I found it to be more confusing than helpful. A weirdly confusing co-routine implementation, new unintuitive syntax, lots of new keywords, etc.
I dunno. I'm sure it's a fine language if that's what you're starting with, but as a former Java dev that was actually productive, Kotlin was anything but a breath of fresh air.
Switching back to Java feels increasingly awkward at this point. I can do it, but there are no use-cases where I would prefer Java over Kotlin. I certainly don't enjoy it.
Sure, they've added features to the language and they help but it's just not even close to the language ergonomics that Kotlin has.
The val vs. var thing is super relevant because this is actually something that is more cultural than language related. As the author points out, you could just litter your Java code with final and it would be similarly safe code. But the reality is that very few people do that. Java makes you do the wrong/less safe thing by default. Kotlin has this opposite culture where you feel slightly guilty/dirty every time you even make something a var. Having a difference between mutable and immutable lists and maps is likewise something that Kotlin inverts. In Java you could always make lists and maps immutable but they'd be immutable by default. With Kotlin it's the reverse: everything is immutable unless you make it mutable.
It's this safe by default attitude that pervades Kotlin that just shows up in a lot of places. Nullability as part of the type system removes an entire category of bugs. The only time I still see NPEs, it usually involves some Java library that I'm using.
Considering how easy it is to switch from Java to Kotlin, it's not surprising that you see essentially all the major Java frameworks come with excellent Kotlin support. I use Spring Boot with Kotlin. It's quite obvious to me that using spring without Kotlin is a bad move at this point. There's so much good stuff you miss out on that is added to Spring via extension functions. E.g. having co-routines sit on top of webflux, makes the whole business of using asynchronous IO with Spring a lot less painful. Without that, I'd probably still be doing synchronous IO.
But "let" is already a thing in Kotlin (a scope function in the standard library).
In my experience, in practice "var" are an order of magnitude more rare than "val", so I'd be perfectly fine with "val" vs. "mutable". I wouldn't mind the verbosity - it would gently discourage the use of mutability, while making it very apparent wherever it's actually involved.
> in practice "var" are an order of magnitude more rare than "val"
Or rather, it should be that way. Agreed, and I think because the world has been moving more and more towards functional style over the past decades, I'd predict that the next big language that will make it to the mainstream will likely take the approach "immutability by default".
mut is a nice proposition, I'd certainly consider it if I were to design Kotlin
If a variable is const-declared, I react in exactly the same way and know that I don't have to look for further uses, which I find very valuable.
I even do stuff like this, which might be extreme but I find it coherent and nice:
void * allocate_and_fill(size_t size, unsigned char x)
{
void * const p = malloc(size);
if (p != NULL)
memset(p, x, size);
return p;
}
The above const-declares the local pointer p, so that it can never be intentionally clobbered inside the function, which would leak the memory. Since it's the pointer itself that is constant, not the data being pointed at, there is no problem in modifying that memory, and the return value is not const-declared in any way.Syntax wise the languages are quite similar (before we get to type systems).
At first I really hated how similar the keywords were (something like let/const seemed preferable).
After a few years of Scala you get used to it.
In fact val somehow feels "nice" and var feels "dirty" so you avoid it as much as possible.
This is a long-debunked myth. See e.g. https://docs.microsoft.com/en-us/typography/develop/word-rec...
Though note that val and var are more similar in terms of their letter content than they are in terms of their word shape.
If I wanted to mix in or use a new language, I would want something that was a substantial upgrade in terms of expressiveness and platform.
To me Kotlin is a bit like what Coffescript is to JavaScript.
What? What about `foo == null`?
If instead the compiler can guarantee that a value will never be null, then you don't have to check, leading to cleaner code. Scala does this with the Option type, Typescript by forcing you to declare a type as `string|null` if it can be null. These sort of things make your code safer and cleaner.
Looking at a method/property signature it should be explicitly and unambiguously clear whether or not null is an acceptable value - but in java there is no way to enforce this.
And there's 7-8 different annotations to mark nullability, all slightly different in some detail.
It's a bloody and messy hell.
kotlinc is way slower than javac but damn, it's still pretty fast compared to what else is out there.
I've recently been profiling kotlinc and there are files in our codebase that compile at 5loc/s!
Some frameworks like JPA are not up-to-date with this methodology, sadly. But Java direction with immutable records is obvious and they'll adapt.
It will be shallowly immutable, but applying it recursively will make it totally immutable. The reason I say that is that in practice it is not that different than FP languages, they just differ in the ratio of FP data structures.
Java in my opinion should evolve by keeping the original approach (a better C++) and leave programming language experimentation to the big three.
There are still pain points, but the language is leaps and bounds better than the Java 1.6 days.
Of course you can't have the pure/impure distinction enforced, but nothing that isn't a purely functional language is going to give you that.
The only really dumb limitation is that you can't have freestanding functions, but that's aesthetics more than substance.
Looks like Flix is in a galaxy of languages implementing Datalog, a variant of (or somehow related to) Prolog. I guess Flix is Turing-complete while Datalog is not?
Flix is a regular programming language, and supports datalog as a DSL basically, supported by the compiler and type system.
I think Kotlin actually has the potential to dethrone Java on the JVM, it is that good.
Kotlin is not much different from Java, conceptually. It is basically Java 2.0. Where Goovy does away with compile time typing, and Scala bolts a Haskell onto Java; Kotlin is "just a better Java".
No way.
I believe pron can do a better job articulating the reasons then I can so here is his comment: https://news.ycombinator.com/item?id=24197817
Groovy's lack of compile time safety is like throwing out the baby with the bathwater. It's just not worth it for me. Kotlin gets you most of the language features but without doing that.
https://docs.groovy-lang.org/latest/html/api/groovy/transfor...
https://livebook.manning.com/book/groovy-in-action-second-ed...
I really don’t get it - I am fairly certain that feature wise Kotlin is actually a bigger, more complex language with many exceptions/edge cases. Scala is a really elegant language in that many of its features are solved by a singular base, for example implicits. And frankly, other than that it is a very easy language - programs written in it can be complex due to its high expressivity.
So it's not "true" reified generics as in C#.
You can't go "if (T is Whatever)" and put it in your SomeClass<T>.
This is not Kotlin's fault, just legacy of Java with which it has to put up in order to maintain full interoperability.
Point 3) and 4) are in my opinion not that big of an issue. Annoying, yes, but not deal-breaker.
Null safety is really something that I miss in Java and what I consider the biggest flaw in the language. Again, there are libraries and tools that help with that, but it is not the same as something which is part of the standard.
well, that's not exactly true, because extension functions can't access private fields.
So we guarantee you you'll get a String back. And hear this: we also guarantee you, 100%, it's going to be non null. And we guarantee you that the reference to that non null String is going to be immutable.
Oh but wait: maybe you'll get a RuntimeException instead...
A good example is the state Dart is in right now. Almost everything has been transformed to null-safety including most of the community packages and it works really nicely.
IMHO, there's a more fundamental concept that everybody seems to be missing, which is that general purpose programming languages somehow fail at general purpose queries across trival, in-memory data structures.
A random example I like to bring up is: Can your LINQ-equivalent efficiently and idiomatically calculate both the "min" and "max" of a list without enumerating it twice?
Imagine you're writing some abstract library that can take any IEnumerable as the input(s). Will it scan a 1TB database table twice because the idiomatic coding style is:
var min = somelist.min();
var max = somelist.max();
This is such as basic, trivial example, yet C#, Java, Kotlin, etc... languages just fall flat on their face. Meanwhile, in SQL, a 48-year-old query language: SELECT min(...), max(...) FROM sometable
But this is just scratching the surface. Ideally, all LINQ-style data inputs should be treated as something like a B-Tree index. Something that can be "walked" (not just enumerated!) efficiently using prefixes, ranges, and similar conditionals. Multiple queries should be able share such as "walk" to minimise the cost of streaming data in from memory... or wherever. Data should be partitioned across CPU cores just as efficiently, and the query language should make this natural.I'm yet to see a language that scratches this itch.
The amount of time I’ve seen it complained about, yet in practice I am very seldom hit by that (just a note, Haskell also erases every type yet it doesn’t bother anyone there).
Does kotlin have them?
I would rather see the ecosystem adapt records. Or once Valhalla happens, one can probably have a near zero-overhead Property<T> field for properties inside a record, properly supporting everything required by Java Beans.
... so preoccupied with whether they could, they didn’t stop to think if they should.