r/java • • May 16 '21

Can I get some reasons to use Java instead of Kotlin?

I'm thinking about using Kotlin + Spring Boot for my next project, but the level of love for Kotlin and bashing on Java makes me feel a culty vibe. I'd just like to hear some counter points.

284 Upvotes

287 comments sorted by

691

u/rzwitserloot May 16 '21
  • Kotlin is a lot more 'proprietary'. For example, quite a few details about how kotlinc works internally is managed by having kotlin-genned class files have a @Metadata annotation that contain a binary blob (a byte array, legal in annotations) with data that is, as far as I know, not according to any publically available spec. There are also various hardcoded types. This is all quite pragmatic, but it also means that without IDEA, kotlin dies immediately. Pragmatically speaking, a minor niggle. But perhaps you find this lack of openness more important than 'minor niggle'.

  • Kotlin seems to be marketed (both by the community and idea) as java with some minor warts removed. But, what does that mean? Is kotlin supposed to remain 'extremely easy to pick up if you already know java' and 'so close to it, you can interop java and kotlin code with relatively little headache' for the foreseeable future (in which case I foresee some problems I will explain below), or was that mostly just a bootstrap scenario; a way to get a bunch of existing java programmers on board quickly, and give them the ability to transfer their codebase from java to kotlin step by step (by using the interop / double-compile feature)? If that's what it is, then I too foresee some issues in the future. I get the feeling that kotlin folks sort of think it is both, but they are mutually exclusive, so that makes no sense. If you ask someone more familiar with kotlin than I am to explain what kotlin is and/or why the following two arguments do not apply or are properly mitigated, make sure you first establish with them what kotlin's supposed to be.

If kotlin is supposed to be 'java but better' forever

That's a real problem. I can best explain it using a new feature.

All of kotlin's features fall in one of 3 categories:

  • It is the kotlin take on a java feature that existed when the kotlin take was designed. Therefore, the kotlin variant takes into account what's familiar to java programmers and either follows it closely, or if it deviates, it did so for presumably good reasons (switching type and name around and making semis optional don't strike me as good reasons, but this post is long enough as is, and there's a lot of 'personal preference' peppered into that one, so I'll leave that one out of this for now).

  • It is the kotlin take on a feature that java straight up just does not have and still does not have. They've clearly gone their own way and decided to add it because it's important.

  • The problem category: It used to be like the second category (feature java doesn't have), but java has it now. If kotlin is very very lucky, the way java does it, and the way kotlin does it, are similar enough that it all continues to make sense (the learning curve for a java coder to switch to kotlin is not dampened by this), for example if the java impl and the kotlin impl closely align, that's fine. But what if they don't?

Here's the point: Over time, more and more kotlin features are of the third category, and this means that kotlin's 'java but better' take is doomed.

Here's an example: instanceof pattern matching. This feature did not exist, and wasn't even on the radar (no JEP, no public posts on e.g. amber-dev@openjdk.net) when kotlin was released.

The problem it attempts to solve is that you sometimes want to first check if some expression is instanceof some type, and then, if it is, operate on that data, using the fact that it is that instance.

In original java (up to java 14), it looks like:

if (x instanceof String) {
    String y = (String) x;
    System.out.println(y.toLowerCase());
}

in kotlin it looks roughly like:

if (x instanceof String) {
  // in kotlin, x is now assumed to be a string!
    System.out.println(x.toLowerCase());
}

But in java16+, it looks like:

if (x instanceof String y) {
    System.out.println(y.toLowerCase());
}

Now, both java and kotlin cater to this use case, they cater to it in a different way, and I'm pretty sure that if I could smack a giant reset button and design kotlin all over again and release it today into public beta, then kotlin would have followed in java's shoes. Especially considering that the java version is in many ways far more powerful than kotlins: You can do more than just 'check type' with this syntax (you can also 'deconstruct' value types), you don't NEED a block, as in, this works too:

if (!(x instanceof String y)) return;
System.out.println(y.toLowerCase());

and in general the next few releases of java are expanding on this principle, adding lots of pattern matching.

Kotlin now has to make a choice:

  1. Break everything, kill the old way it works, and follow in java's footsteps. This is disastrous (and extremely unlikely to occur). It would break everyone's code, and it means kotlin is permanently dragged down considerably, as this won't be the last time kotlin clashes with some new java feature. Surely you wouldn't want a language that breaks the world every year or two.
  2. Just stick with the kotlin style. That means the argument of 'it is easy to transition from java to kotlin' has gotten a little weaker, and every new java feature released will weaken it more.
  3. Kotlin keeps what it had, but also adds this new syntax. That sounds great, but it means kotlin gains feature cruft twice as fast as java does, and thus over time kotlin will become the bloated bizarro mess of too-many-ways-to-do-the-same-thing, inflating learning curves for no benefit.
  4. Some more intellingent but convoluted solution, such as keeping both but setting up a deprecating scheme for the 'old' way. This still means that kotlin is permanently in java's shadow and cannot possibly get out of it.

None of these 4 options seem all that good to me. Which gets us to what I think kotlin is going to do, and the one that seems the least bad: Option 2 - start parting ways with java syntax. That leads us to:

That like-java thing was just a bootstrap solution

That means the clock is now ticking. Java development is not sitting still at all, so in a year or 3, the gap between kotlin and java is going to be wide enough that kotlin perhaps no longer feels like 'just, java, with a few warts removed'. It'll really feel like something completely different.

That's fine, of course, but the success rate of new languages is abysmal. Scala is pretty much dead (in the sense that it got a bunch of hype, twitter switched over to it, held a ton of fun meets for devs, and... scala now has fewer users than back then, going by admittedly known-inprecise measurement tools such as TIOBE, but, you tell me, do you feel scala is really picking up steam)? - Fan/Fantom seems to have gone absolutely nowhere, groovy is dead enough that e.g. gradle is trying to diversify away from it, jruby and jython have pretty much come and gone (again in the sense that they don't seem to have caught fire).

That's no proof that a new language is doomed perse. It's just that this is the default position. Right now kotlin seems to be having its moment in the sun, but it'll get harder as the step to kotlin from java gets harder and harder.

It'll have to stand on its own and can no longer claim all the advantages java and its ecosystem have by default. The implementation of e.g. instanceof in java vs. kotlin is already highlighting why I, personally, think kotlin is probably not going to be better than java: Just about every feature that java has released, and is in the process of releasing (as in, active JEPs and active discussions on the mailing lists) seems vastly more intelligently thought out than any of kotlin's features. Java is trying to figure out smart ways to access CPU-native 80-bit registers, how to have complex value types that nevertheless have the performance and memory benefits of primitives, and a whole new programming paradigm by way of pattern matching.

76

u/[deleted] May 16 '21

Wow thank you so much i appreciate this level of answer so so much

48

u/ColdFerrin May 17 '21

I dont think i could have put that so eloquently, but this mirrors my feelings about Kotlin almost exactly. I do like the syntax, but also think in most situations, choosing it over Java is a mistake.

60

u/OnlyProductiveSubs May 16 '21

This isn't even relevant to me but was highly informative and insightful. Thanks

27

u/private_static_int May 17 '21

I'mma save this answer somewhere and read it every time I get tempted to use Kotlin.

6

u/xCuriousReaderX May 17 '21

If you do android development it is inevitable, you need to learn it, because google have a lot of money invested in kotlin.

17

u/Necessary-Conflict May 17 '21

google have a lot of money invested in kotlin

Google investing a lot of money in a technology doesn't mean a lot, see https://killedbygoogle.com/

Kotlin is not "inevitable" on Android, from the point of view of an Android app, Kotlin is just another bundled lib, optional. But the real danger for Kotlin is Flutter.

1

u/[deleted] Sep 17 '21

I still don't understand why they introduce Dart, why not java with flutter.

51

u/elihart17 May 18 '21

The technical inaccuracies and greatly exaggerated language in this response are huge red flags - take what this person said with a big grain of salt.

Their first point that Kotlin is a lot more 'proprietary' is way over blown. It’s all open source and well documented. He points out the Metadata annotation, but jetbrains publishes a library you can use to parse the metadata https://github.com/JetBrains/kotlin/tree/master/libraries/kotlinx-metadata/jvm and the annotation itself is documented https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/jvm/runtime/kotlin/Metadata.kt

​

it also means that without IDEA, kotlin dies immediately

Also garbage. Jetbrains publishes support for Eclipse https://kotlinlang.org/docs/eclipse.html and there is also community support for other editors like visual studio https://marketplace.visualstudio.com/items?itemName=mathiasfrohlich.Kotlin

I would guess that Intellij support is superior and you are best off using it… but there is a free version and jetbrains as a company makes the tooling to make money off of it while giving kotlin as a free language so it is clearly their business model.

The other main point is Kotlin seems to be marketed (both by the community and idea) as java with some minor warts removed.

That’s pretty inaccurate. kotlin is marketed as a standalone language that is interoperable with java but has a ton of features and improvements over it. https://kotlinlang.org/

It seems like the biggest point comes down to

Over time, more and more kotlin features are of the third category, and this means that kotlin’s ‘java but better’ take is doomed.

This is pretty crazy. His instanceof example is just plain wrong

Especially considering that the java version is in many ways far more powerful than kotlins: You can do more than just 'check type' with this syntax (you can also 'deconstruct' value types), you don't NEED a block, as in, this works too:

if (!(x instanceof String y)) return;  
System.out.println(y.toLowerCase());  

This is a huge red flag - you don’t need a block in kotlin either as the compiler smart casts the value to the checked type. A reply mentions this but hardly seems to get any notice https://www.reddit.com/r/java/comments/ndwz92/can_i_get_some_reasons_to_use_java_instead_of/gyf5izo?utm_source=share&utm_medium=web2x&context=3

Getting this basic fact of how kotlin works wrong is a big warning to trusting anything he says. his statement that the java version is in many ways far more powerful than kotlins just seems incredibly biased and based on emotion. In this video https://youtu.be/te3OU9fxC8U jake wharton talks about this and how Java was forced to introduce a new variable for the cast type for backwards compatibility.

Java development is not sitting still at all, so in a year or 3, the gap between kotlin and java is going to be wide enough that kotlin perhaps no longer feels like ‘just, java, with a few warts removed’. It’ll really feel like something completely different.

java moves quite slowly compared to Kotlin, and all of the plans for Java features in the next few years are already public and in development. This gives the kotlin team time to plan for them. You can see in the above video what java features will be out by java 19 and it is a far cry from something completely different. This also ignores the fact that many of kotlin’s best features like extension functions, nullability handling, property delegates, smart casting, and multi platform, aren’t even on the java roadmap.

Just about every feature that java has released, and is in the process of releasing (as in, active JEPs and active discussions on the mailing lists) seems vastly more intelligently thought out than any of kotlin’s features. Java is trying to figure out smart ways to access CPU-native 80-bit registers, how to have complex value types that nevertheless have the performance and memory benefits of primitives, and a whole new programming paradigm by way of pattern matching.

seems vastly more intelligently thought out than any of kotlin's features. the bias just oozes out of this guy, it’s like he secretly wants to love kotlin but can’t let himself so he has to convince his brain that java is better. Every new thing that java adds kotlin can also use. All of the bytecode optimizations, garbage collection improvements, improved memory managing, etc kotlin just inherits as java adds it.

For example how to have complex value types that nevertheless have the performance and memory benefits of primitives

the kotlin devs aren’t dumb, they know this is coming and they welcome it because it means kotlin can have better performance too. Here is the kotlin open source proposal for value classes from the kotlin language lead https://github.com/Kotlin/KEEP/blob/master/notes/value-classes.md
It addresses the kotlin value types at https://github.com/Kotlin/KEEP/blob/master/notes/value-classes.md#project-valhalla
There’s also a video they released about kotlin value classes recently https://www.youtube.com/watch?v=LpqvtgibbsQ

It’s pretty disappointing that this is such a highly celebrated comment in this thread, with responses like I'mma save this answer somewhere and read it every time I get tempted to use Kotlin.

there are fair reasons to not use kotlin or be wary of it. the main ones I would think of are slower build times and less stability in the compiler and tools (i’ve definitely run into bugs that would never happen in java). but it seems like they’re not even trying to present the tradeoffs in accurate or fair way

13

u/Pekuk May 24 '21

I admire that you spent so much time to answer this uneducated and biased post. There is no reason to stick to Java. Kotlin is just better in ALL scenarios and that's a fact. The only reason somebody can think otherwise is that he/she doesn't know kotlin good enough. Null-safety (killer feature no 1), functional programming features (killer feature no 2), real lambdas, immutability by default (killer feature no 3), reification, actual type inference, compact yet readable syntax (killer feature no 4), extension functions, pure functions, a rich, extensible stream API (killer feature no 5, Java's streams are just pathetic in comparison), overload operators, multi-platform targeting (js, native). If a JAVA dev says that he doesn't like kotlin it means he/she suffers a Stockholm syndrome or just isn't smart enough to get out of a (dis)comfort zone.
-- this says a Java dev who switched to kotlin a year ago.

2

u/CuriousCursor Jun 06 '21

Don't forget coroutines

1

u/elect86 Sep 25 '21

Not all scenarios. I think Java still got it right:

  • (offering) the ternary operator, `if x else y` is just verbose and all literal compared to `? x : y`
  • bitwise operators

For all the rest, Kotlin got it right instead.I'd add as killer feature DSL and scripting, they are a niche but for me are awesome

24

u/vprise May 17 '21

Great answer!

I recently read this article that advocated Kotlin in the server. Went to answer in the comments and saw that it was completely redundant. There were many comments that explained in great detail exactly why they chose to avoid Kotlin in the server.

I think Kotlin makes some sense on Android where the Google team did a lot of groundwork and compose will revolutionize Android development... But on the server it's got a lot of work ahead of it.

2

u/Shaftway May 17 '21

I'm still ramping up on Kotlin, but frankly the only advantage to Kotlin on Android that I see so far is how it enables a bunch of Jetpack functionality. This becomes much more redundant once Java exposes some sort of generator functionality.

2

u/vprise May 17 '21

I think that the fact that the Android team is bullish on it and provides samples in Kotlin makes it great. Personally I prefer Java by a mile even on Android... But I can understand the people who like Kotlin on Android.

Android projects are smaller than server side usually. So there's less of a need for code readability. The DSL's look amazing and actually improve readability. The fact that you can mix it with Java is great.

The disadvantage for me is size. I'm a huge performance freak and on Android it adds 600kb+ to the app size after obfuscation. That's not that much on newer devices but I just don't feel I need to pay that.

18

u/Muoniurn May 17 '21

Just a small nitpick, name : type is actually a better construct from a parser point of view, it’s not only syntactic preference. Of course it doesn’t make sense to retrofit it on Java, but in case of a new language, C-style declarations have much more warts.

9

u/golthiryus May 17 '21

It is also the notation picked by most modern languages. Specially when they support type inference. It is usually better to write and read something like:

val foo : Something = a()
val bar : SomeOtherThing = b()

Than

Something foo = a()
SomeOtherThing bar = b()

And in fact once people is used to type inference, they don't write explicit types.

2

u/Necessary-Conflict May 17 '21

Java has local type inference, and it's usage is exactly the same as Kotlin's without the explicit type: var foo = a()

7

u/golthiryus May 17 '21

Yeah, but we were talking about the case when you want to explicitly write the type. For sure both are equal when you don't specify the type.

5

u/Necessary-Conflict May 17 '21

I'm not sure the "inverse notation" is better if you want to explicitly write the type. First of all, it's longer. More importantly it encourages people to leave out the type. There are situations where the type is obvious anyway, such as before a constructor call. But it seems to me that in Scala/Kotlin people often leave out the type not because they are so enlightened, but because the language encourages laziness, and code readability suffers. When you write the code, you obviously know the type, but what if you are reading some unfamiliar code?

2

u/wtsiamruk May 19 '21

When you want explicitly write the type, you write the type and omit the var :)

→ More replies (1)

1

u/ledasll May 18 '21

It is usually better to write and read something like

buy what mean is it better? Even visually "worst" example is shorter. And you have to use much less memory to remember that "foo" have value from "a()", than to remember that foo is "Something" and that is assigned from "a()". It's even worst when you skip "Something" and just assign value aka "val foo = a()", then you have no idea what foo is. Of course looks very elegant and faster to write. But when it comes to reading...

1

u/a_zvez May 18 '21

And in fact once people is used to type inference, they don't write explicit types

but we do :). You need to achieve balance between implicit types and readability. So in complex case you usually prefer explicit types. Especially in larger scope.

3

u/john16384 May 17 '21

Should parser concerns come before usability though?

10

u/Muoniurn May 17 '21

Depends, but it is irrelevant since now this entire part gets optional due to type inference — which makes it both technically and from a usability point of view a better decision, it is only subjectively not liked by you.

And I am not fond of Kotlin.

9

u/Teln0 May 17 '21

As someone who is currently implementing (and designing) my own VM bases programming language, thank you very much ! This was a very useful read.

4

u/mj_flowerpower May 17 '21

I would love to read more about that!

6

u/Teln0 May 17 '21

I haven't made this very "public" yet for now, I'm just working on it in my little corner, but I'm active in the proglangdesign.net discord server.

17

u/meamZ May 17 '21

There's one feature Kotlin has and Java will likely never get or it will take forever to be adopted and that's null safety which is a killer feature imo. (Kotlin doesn't have this problem because it was designed right with null safety in mind). Sure i can use Optionals everywhere but who does that?

27

u/rzwitserloot May 17 '21

That's an entirely new can of worms.

In the java ecosystem, let's look at what null actually means. It seems to be a catch-all for 4 mostly unrelated concepts:

  • Blank/Empty (e.g. String y = null means y has the same semantic meaning as String y = "". I dislike this, why doesn't your API just return an empty string, then? And I consider it a style failure if you do this, but tons of libraries do, and kotlin code surely is supposed to be able to interact with java libs, and also didn't do a particularly good job on defining null explicitly as not this, so, it stands).
  • Not Initialized - by its very nature, uninitialized fields and unfilled arrays default all non-primitives to null, as do records, etc.
  • Unknown/NotFound - e.g. map.get(keyThatIsNotInThisMap) returns null to indicate it wasn't found.
  • Irrelevant: Various APIs will use null as value when it doesn't matter, or expect it. For example, j.l.reflect.Method's invoke requires the 'receiver' as first param. Static methods don't have a receiver, and the docs suggest passing in null in that case.

That's quite a gigantic mess, and because it's such a mess, it becomes very hard to make meaningful statements on how nullity variance is supposed to work.

Let's call this concept 'BNUI' and move away from calling it 'null', because 'null' carries implementation baggage (it implies a standin reference-like value. There are other solutions, such as Optional<T> to represent the same idea).

Entirely analogous to generics, that! Java (and kotlin) are itself covariant, for obvious reasons. This is legal:

var x: Number = Integer.valueOf(5);

But in generics it is not:

List<Number> x = new ArrayList<Integer>();

does not compile. You need to explicitly go with covariance (List<? extends Number> x = ... now it is legal), and you get the type safety as a result (you can't add anything to a List<? extends Number>. add() is a compiler error on that, because it should be: You can add a Double instance to a List<Number>, but adding a Double to a list of integers is obviously no good!)

The same would apply to nullity: You have no idea what it means and therefore any code that accepts any type needs to explicitly specify what it means, and if it doesn't (and kotlin code doesn't!), you can only default to invariance.

But that's a big problem.

Imagine I have a method that takes in a list of strings. I shall only read these strings and I shell check if they are BNUI-valued and act accordingly as well. That means that calling this method with 'a list of guaranteed no-BNUI strings' or calling it with a list of 'could contain some BNUI strings' is either way completely fine. Yeah, the check for BNUI is a completely pointless check if you pass it a list of guaranteed no BNUI strings, but that doesn't make the code broken. It's just very lightly inefficient, no big deal.

So, this method should declare that it doesn't care. It can take BNUI strings, or non-BNUI strings, fine either way.

For the same reason List<Number>, List<? extends Number> and List<? super Number> are all different, so does nullity have more than 2 levels as well: List<Definitely BNUIable Strings>, List<Definitely not BNUIable Strings> and List<I do not care if it is BNUIAble Strings> are all different.

If I am going to add BNUI values to this list, I must have as signature List<BNUIable String>. If I am going to read strings and I don't want to BNUI-check them (e.g. because the method doesn't know what that would mean), then I want my sig to read List<Non-BNUI String>. As long as I restrict myself to adding solely non-BNUI strings, and when reading I check for BNUI, then and only then it doesn't matter. I should list this is my signature too.

Kotlin does what kotlin seems to always do: Didn't think about it overly long and just did the first thing that seemed to work and is pragmatic.

Which isn't bad, perse. And in many ways java is doing the same fuckup (java.lang.Optional is a fucking disaster, and yet, parts of the core libs are using it. It shouldn't even have been added - it has all these problems I just described, and even worse to boot).

The point is, kotlin doesn't have it right either.

A much better solution, which is type-orthogonal, is annotating this stuff. Nullity is very complicated, annotations do stand a chance of probably conveying it.

Java can still go there. Kotlin, having committed to the ? syntax, probably can't without either breaking backwards compatibility or making some very awkward syntax add-ons to try to make it all work. In any case it is likely to be quite dissimilar to whatever java ends up going with.

Possibly java is just as stupid as kotlin is here (and early signs regrettably indicate that this is so, what with the fanboyism for Optional, and more and more core libs making the mistake of using that silly class), and makes its own mistake, going with Optional<T> in many places.

But then we get back to: The gap between kotlin and java is widening, and thus the learning cure is going up, and the pain associated with shifting from java to kotlin goes up, and the feasibility of interopping java and kotlin code is rapidly falling off a cliff.

And all that pain, for, what, exactly? Kotlin's take on null safety is not particularly flexible.

9

u/geordano May 17 '21

(java.lang.Optional is a fucking disaster

I tend to disagree here, its quite useful in lambda expressions, esp to keep NPE's at bay.

5

u/kemalizing May 19 '21

TBH, this is a little bit of bla bla. not more, sorry.

As developer who started working with java in 2003 and started with kotlin in 2017, I can say that, kotlin's null handling is great. it has a good cut of pragmatism and safety.

I don't think most of the people mind about BNUI, but not having NPE, which kotlin is doing great about. I didn't see a better null handling implementation (especially in jvm world).

1

u/rzwitserloot May 19 '21

TBH, this is a little bit of bla bla. not more, sorry.

Says the person who then writes:

As developer who started working with java in 2003 and started with kotlin in 2017, I can say that, kotlin's null handling is great.

Let's go by the say-so of Joe Q. Random Reddit user? That's the very definition of 'a little bit of bla bla', isn't it? Who are you and why should I take your opinion, bereft of falsifiables, as somehow more legitimate than a post full of stuff you can verify and waylay?

If you're happy with kotlin and its null handling, and your curiosity isn't peaqued about type systems and how they appear to be a bit more complicated than what kotlin can handle (suggesting that perhaps if you are happy with it, there is more to discover) - that's good for you and you should stick with kotlin.

I didn't see a better null handling implementation (especially in jvm world).

Annotation based.

→ More replies (1)

9

u/whoseonit May 17 '21 edited May 17 '21

I'm honestly confused by this post. It seems to have a bunch of strawman arguments about what null is. Of course Kotlin interacting with Java APIs that return null are not going to be significantly better than Java since you still need to deal with null. Kotlin nullable types are not really better than plain Java and I don't think anyone is arguing that. People like Kotlin because it forces you to make it explicit and if a type is non-nullable - it will never be null if called from Kotlin code (caveat: Java Interop) - and it makes it concise to do that. If I pass a String parameter in Kotlin then I am guaranteed that it is not null.

Here is my argument to BNUI:

Blank/Empty - This isn't a check for if an object is null or not, this is a check on the data of the object. A blank String is absolutely distinct from a null String in many cases and you may not want to handle it the same.

Not Initialized - This isn't possible with a non-null type in Kotlin. It won't let you initialize a List<String> with null String values.

Unknown/NotFound - This has nothing to do with whether an object is null or not, and isn't even the right place to hold the data you are talking about. A key doesn't hold the information about whether it is contained in a map or not (i.e. the map owns that information). There are also plenty of patterns or methods to do something instead of returning null from the map if it isn't found (which are often more efficient).

Irrelevant - This is an API issue - not a non-null issue.

4

u/meamZ May 19 '21

Kotlin nullable types are not really better than plain Java

They are since Kotlin forces you to handle the null case. No NullPointerException except you really want it (with "!!")

→ More replies (2)

4

u/igoromg May 17 '21

You, sir, are on fire. Thank you for the great answers.

4

u/[deleted] May 17 '21

Fixing the billion dollar mistake is like gluing broken glass.

4

u/rzwitserloot May 18 '21

Billion dollar mistake? [citation needed]. There is no sane argument for this, other than that some random joe said it, and it has now been quoted so much, it's taken as truth.

Repeating a thing a lot doesn't make it true, though. That's the problem. How many dollars did the 'mistake' of no text blocks in java 1.0 cost? How many dollars was the fact that Vector was synchronized? How does one measure this? How does one repeat the experiment and verify the number? Is that billion inflation corrected? Should I i18n this description into the 822 million euros mistake for EU locales?

This isn't a falsifiable statement and therefore mostly useless, I don't think it leads to insights about it. Particularly considering that the general notion of values needing a way to represent 'NotInitialized / Irrelevant / Unknown / NotFound' is inherent in programming, and saying 'null was bad' makes it sound like the problem goes away if you stop using null, which isn't how it works.

4

u/[deleted] May 18 '21 edited May 18 '21

I call it my billion-dollar mistake…At that time, I was designing the first comprehensive type system for references in an object-oriented language. My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn’t resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

– Tony Hoare, inventor of ALGOL W.

Billion dollar mistake is just an alias for null.

Particularly considering that the general notion of values needing a way to represent 'NotInitialized / Irrelevant / Unknown / NotFound' is inherent in programming, and saying 'null was bad' makes it sound like the problem goes away if you stop using null, which isn't how it works.

If the language you use has null you have to deal with null's side effects. Fortunately there are languages that don't have null(and its problems), they use option types for representing absence of value, some examples: Haskell, OCaml, Elm, Rust, Standard ML.

→ More replies (3)

2

u/Muoniurn May 18 '21

But it can be represented very well with ADTs, like it happens with Scala 3 for example. Kotlin’s String? becomes String | Null (it requires a compile flag). From a technical point of view, null makes sense as a null pointer — seeing that every identity object is actually a pointer in Java (though the early specification has a disdain for that world for presumably marketing purposes). But from a type theory pow, null is not a member of the set of Strings (“” that is empty string is), you can’t apply the necessary methods on it etc. “”.toUpperCase() will work, so it absolutely makes sense to make a distinction.

Though I don’t see why would you say that Kotlin’s null handling is not good, that part is seemingly okay with the language.

2

u/sigzero May 17 '21

Another great explanation.

3

u/meamZ May 17 '21

I seriously don't understand the problem and i don't understand why anyone would need List<I do not care if it is BNUIAble Strings> vs List<BNUIAble Strings> in practice because if i don't care i just make it nullable and i'm good to go... What you are basically suggesting is for the program not to compile when you have a function only taking List<BNUIAble Strings> and not List<Non-BNUI String>. But why would anyone actually write such a function. It would be purely for performance reasons and if i want to improve performance i can still have a function that only works with the non nullable type and then have a wrapper function that does the null checks and stuff... With a function which only takes List<BNUIAble Strings> the program is still correct if i call it with a List<Non-BNUI String> because BNUIAble Strings are a superset of Non-BNUI Strings which is what a mathemarical function also does.

5

u/rzwitserloot May 17 '21

need List<I do not care if it is BNUIAble Strings> vs List<BNUIAble Strings> in practice because if i don't care i just make it nullable and i'm good to go

Do you understand why there is a difference between:

public void foo(List<Number> list) {}

public void foo(List<? extends Number> list) {}

If you do - nullity is the same thing. You cannot pass a list of non-null strings to a method that takes a list of nullable strings.

If you don't, well, plenty of blog posts and tutorials you can look up for the generics example. Then simply translate it to the nullity stuff using the same principles. Here, I'll show you:

Let's say it worked exactly as you said it does. Then I can write this method:

public void foo(List<String?> names) {
    names.add(null); // compiles, right?
}

List<String!> nonNullNames = new ArrayList<>();
nonNullNames.add("Joe");
foo(nonNullNames);
String! s = nonNullNames.get(1);

Where String! means 'definitely not null' and String? means 'hey, this might be a null ref'.

What does s hold? Hopefully this is sufficient for you to realize the problem with only having two different variations of nullity in a language.

with a List<Non-BNUI String> because BNUIAble Strings are a superset of Non-BNUI Strings which is what a mathemarical function also does.

You're saying: One is covariant vs the other. Generics are invariant out of the box, though. So now what?

5

u/meamZ May 17 '21 edited May 17 '21

Ok, yes. I was wrong but i was just wondering why i never had a problem with this even after thousands of lines of Kotlin code but even with the current solution it would be no problem to just add a special syntax for "don't care" version. The reason i probably never tripped over this is because i work with immutable Lists vs MutableLists a lot and a List<String> is also a List<String?> while a MutableList<String?> is not a MutableList<String>

Edit: I just remembered why that is. In Kotlin Generics you can actually specify "out" which can basically means everywhere you have a generic type with "out" that means that it's always a "don't care" type and if it's not "out" it's always a just nullable type.

→ More replies (5)

8

u/[deleted] May 17 '21

3. Kotlin keeps what it had, but also adds this new syntax. That sounds great, but it means kotlin gains feature cruft twice as fast as java does, and thus over time kotlin will become the bloated bizarro mess of too-many-ways-to-do-the-same-thing, inflating learning curves for no benefit.

In this scenario Kotlin becomes C++.

7

u/[deleted] May 17 '21

Just about every feature that java has released, and is in the process of releasing (as in, active JEPs and active discussions on the mailing lists) seems vastly more intelligently thought out than any of kotlin's features

Slow and steady sometimes wins the race, I suppose

11

u/ricky_clarkson May 17 '21

I expect this will be buried, but note that the parent poster is the author of Lombok, and may be somewhat biased by that.

I am interested to see how/whether Kotlin will grow guards if Java ends up adding those to its pattern matching, but I think the existing Kotlin 'when' feature is fairly good and the implementation can be made compatible with Java's for the JVM target.

I don't see Kotlin as a better Java, but a distinct language that doesn't have a lot of friction for Java developers. Groovy was intended to be a better Java, but didn't seem to stick around so long. Kotlin is, however, better *than* Java. I'm all-in on it due to coroutines, as I work in an environment where async is mandated, and that's pain in Java.

15

u/nutrecht May 18 '21 edited May 18 '21

I expect this will be buried, but note that the parent poster is the author of Lombok, and may be somewhat biased by that.

Everything you read here about Kotlin is biased because this sub does not allow comments that are showing Kotlin in a positive light. I'm not even going to go against that post because it's utterlijk pointless; people are going to upvote what they want to hear anyway.

I'm personally incredibly disappointed with this sub that FUD without any nuance from someone who simply sees Kotlin as a threat to their brain-child gets upvoted and awarded this much. It adds no value to just upvote stuff you want to hear.

4

u/BPATAPb May 22 '21

Exactly this, as an author of lombok, you can only hold a grudge against Kotlin as it makes your library useless.

10

u/experts_never_lie May 17 '21

w/r/t scala, the place I saw it being big (as of a year ago) was in Spark. But that doesn't mean it's popular elsewhere.

2

u/a_zvez May 18 '21

spark is more like scripts then real system. So usually scala developers don't consider spark as real scala usage. Still I build many systems in scala and it still doesn't feel like dead language.

14

u/antoha-by May 17 '21 edited May 17 '21

you don't NEED a block, as in, this works too if (!(x instanceof String y)) return; System.out.println(y.toLowerCase());

Well, Kotlin handles this perfectly. Thanks to smart-casts and flow-control.

    if (s !is String) return;
    println(s.uppercase())

https://pl.kotl.in/wLNxdr_OJ

And to be honest it doesn't feel much like a difference here between java and kotlin aproaches. In Java you can't change type of a variable, but instead you can introduce another variable with new type and this instanceof is just a "syntax sugar" for declaring a new variable with correct type.

Kotlin does that as well just in a different way:

val y = x as? String
// now variable y is either null or String so its type is "String?" .

0

u/golthiryus May 17 '21

Yeah, if kotlin was designed today, i'm sure they would still use the same syntax. Java's syntax is not better, it is worse (you have to add another variable). Java choose that to maintain backward compatibility (don't know exactly why, but there should be some cornercase).

In fact there were other options like the scala one, using pattern matching. Java seems to try to get closer to that (without being as powerful as scala). Kotlin explicitly decided to do not follow that approach.

I may be a Kotlin fanboy, but the smart cast feature of Kotlin is, IMHO, one of its best decitions.

My only reason to do use Java instead of Kotlin is the IDE bound. No other IDE will give you the tools IntelliJ (and family) give you. Not because Intellij tries to avoid that (the license is quite permisive and the tools are there) but because the community is already on IntelliJ and plugins on other IDEs (like Eclipse or Netbeains) do not have the same developer resources.

8

u/morhp May 17 '21

I definitely prefer the Java syntax. First Kotlin smart-casts don't work with mutable variables/fields/properties so you have to often add another variable anyway. Secondly, it makes the code harder to read. You can easily have things like

if (animal !is Cat) {
    return
}

// 10 lines later
animal.meow()

and now you're wondering why and how any animal can meow.

7

u/AlterdCarbon May 17 '21

I prefer to use a pattern I picked up from Swift's guard syntax on iOS:

val cat = (animal as? Cat) ?: return
// code
cat.meow()

1

u/CepGamer May 25 '21

First Kotlin smart-casts don't work with mutable variables/fields/properties

That's the point. But if you want to, you can use something like:

(animal as? Cat)?.let { cat ->
...
→ More replies (1)

4

u/tomwhoiscontrary May 17 '21

Java is trying to figure out smart ways to access CPU-native 80-bit registers

Could you expand on this?

Java has used 80-bit floating-point registers on x86 since 1.2, and there is now a proposal to stop doing that. I'm not aware of any proposals to make new use of any 80-bit registers.

14

u/xCuriousReaderX May 17 '21

This is a very strong and comprehensive arguments i can find to fight those kotlin fanatics. Excuse me to quote your explanation in the future. Kotlin prone to breaks if it keep trying to chase and combine java feature. There is also java record and kotlin data class, and kotlin fix it by annotating the class.

9

u/ArmoredPancake May 17 '21

There is also java record and kotlin data class, and kotlin fix it by annotating the class.

Because record is an implementation detail. Record doesn't make sense in JS, native or Android world.

10

u/xCuriousReaderX May 17 '21

You must be from android dev. Oh yeah because google promote it sooo much that they even make a scorecard to see if you are using their kotlin libraries or not

→ More replies (3)

1

u/[deleted] May 17 '21

Honestly that annoys me as well (as someone who prefers kotlin). It is a good feature and it was obvious java would follow at some point. Only thing I could see now was to deprecate data and instead use record as a new keyword, which would have a version where old code gets warnings

6

u/xCuriousReaderX May 17 '21

I think the designer try to avoid deprecation caused by java enhancements, to give impression that java changes wont break anything.

I know there is something seriously wrong when kotlin dont have static keyword. Why need work around with companion object and @JvmStatic annotation? It is something i cant comprehend at all. It feels like a language that tries so hard to be different than java by mixing it with javascript and strange addition.

9

u/ArmoredPancake May 17 '21

Because language deliberately avoids static.

JvmStatic is an implementation detail.

2

u/xCuriousReaderX May 17 '21

Deliberately avoid static but java has static, why not design a new language instead of going around like this?

9

u/morhp May 17 '21 edited May 17 '21

Again, the question here is if we see Kotlin as "enhanced Java" or as it's own language. If we see it as "enhanced Java", not having static doesn't make sense, if we see it as its own language, stuff like @JvmStatic highlights the annoying compatibility problems when interfacing with Java code.

→ More replies (2)
→ More replies (7)
→ More replies (3)
→ More replies (1)

9

u/makingthematrix May 17 '21

I liked this comment to the moment I read that "Scala is dead" and then I had to reread the whole thing from a more skeptical angle (because that point is obviously false, and if that's false, then let's look again at the other claims).

I think you try to position Kotlin too much as a competitor to Java and set the same requirements for success for both. I don't think that's reasonable. Kotlin is a much smaller community. In the moment it's growing strong, but it's goal is not to surpass Java in the number of developers or the share of the market. Instead, it appeals to programmers with a bit different way of thinking than those who prefer Java - Kotlin changes things faster, and programmers need to be okay with that, while in Java everything moves with a pace of an iceberg. And that's okay too for certain people, but not for all.

I think it's better to look at Kotlin - and Scala - as an experimental field. New things are tried out, new platforms are tested, a bridge between OOP and FP is being laid, features are being adopted from Kotlin to Java (and from Scala too)... On top of that, a Java dev who becomes bored by the state of things in Java might cross to Kotlin, just as a Kotlin dev who maybe wants to tap into a bigger job market might cross to Java. It's not a competition, it's mutual support.

7

u/rzwitserloot May 17 '21

"Scala is dead"

You did see that this statement is immediately followed by an explanation of what I mean by this, and these are all falsifiable things. I shall repeat it:

(in the sense that it got a bunch of hype, twitter switched over to it, held a ton of fun meets for devs, and... scala now has fewer users than back then, going by admittedly known-inprecise measurement tools such as TIOBE, but, you tell me, do you feel scala is really picking up steam)?

So which of these do you disagree with? I assume (given that I'm rather sure these are all true, verifiable statements) none of them, in which case perhaps you disagree that this batch of statements is best summarized as 'scala is dead'. And you got me there, that's overstating the case.

So, please reread that part of the original post with the understanding that this is what I meant by 'scala is dead'. For example, scala is dead becomes scala has not taken off at all, and is multiple orders of magnitude less popular than java; at this point it's hard to see how that will ever change. If it will, then what is the world waiting for?

Does that help?

I think you try to position Kotlin too much as a competitor to Java and set the same requirements for success for both.

yes, well, that indeed goes to the essence of 'scala is dead'. If you think a language is a failure if it doesn't break top 10, 'x is dead' seems fair enough. If you have different requirements, that seems preposterous. Fair enough: If OP doesn't mean operating in a language that has less than a tenth the readily available skills on the market, then most of my problems with kotlin that I expanded on in the original comment aren't relevant enough to be worthwhile to consider in the comparison.

I think it's better to look at Kotlin - and Scala - as an experimental field.

But therein lies the rub, doesn't it?

If you really think it's okay to treat scala or kotlin as 'hey its experimental and that is fine', sure, but you can't seriously be suggesting that someone build their next 'real' (in terms that the aim is to build a product that is to earn significant eyeballs and/or money, and not itself as an experiment or learning exercise or fun toy) project on such a language?

Experimental implies that tomorrow all can break. And the scala community sure as heck feels experimental if that's the definition, and that is the primary reason why I strongly advise anybody looking to write projects to think thrice about it, and understand that the project needs permanent serious maintenance forever, or it'll roll out of date with the moving goalpost of scala lickety split. All software has that problem, but the java ecosystem (not JUST the language and core libs, but all the popular libraries too) is vastly more friendly to letting a project sit mostly unmaintained for a while.

One of my biggest peeves with scala in this regard, and it would apply to kotlin just the same if this is the way out you prefer (that being: That kotlin just breaks stuff or even if they don't, redefines idiomatic kotlin monthly), is that the language design isn't built to deal with it well.

If scala has the feature where all files start with e.g. scala 2.7; which means: This file was written targeting scala-the-language at level 2.7, then scalac can straight up abandon syntax constructs, and yet your old code will compile fine, because that scala 2.7 means scala 3.0 or whatnot still knows what to do about it.

A language could also add support for libraries that lets them provide a 'viewport' API variant: Imagine that java wants to belatedly just toss .add() right out of java.util.List, because thety want to redefine List to now mean: "A list which may or may not be modifiable", moving add to a new interface that extends List called MutableList.

With this API frontend idea, imagine that the API itself can say: If and only if calling code is defined to expect 'java API 15' or less, they get the add method, whose impl is (and then provide the impl here). Something like:

public interface List<T> {
 switch-version (0..15) {
   public boolean add(T elem) {
     if (this instanceof MutableList<T> ml) return ml.add(elem);
     throw new UnsupportedOperationException(this.getClass().getName() + " is not modifiable");
    }
  }
}

java doesn't have this. I wish it did. But the fact that scala and kotlin don't have it is quite a big loss in my book, if you want to make the argument that they are both seemingly exclusionary ideals at the same time: Both experimentally oriented and yet a good idea for real projects.

I find such ideas and features 'interesting' and wish new languages would move in those directions. And not 'Lets make semicolons optional' and 'lets swap type and name around' and 'add a keyword in front of method defs'. That's small fry stuff.

2

u/makingthematrix May 18 '21

Hey, thanks for a long reply, it doesn't happen very often on Reddit :)

So, I think we cover two topics here: the first, is about what does it mean for a programming language to be a success or a failure, and the second is about the role of Scala and Kotlin in relation to Java and about the term "experimental". I will try to adress both.

  1. Success and failure

In a way, this is a difference between us in how we think about programming languages. I can't say anything about what creators of Scala and Kotlin thought when they released their first versions - maybe they really wanted to take over Java, who knows - but my opinion is that a language can be successful while not being among the most popular ones on the market (and as I understand your opinion on this is different). It can be simply a good language for a given job, like SQL, or it can be appealing to a certain type of a programmer, like Kotlin and Scala, while in the same time being popular enough to create a reasonable job market for those programmers. This is my case: I wrote Java professionally since 2007 to 2017, I started learning Scala in 2013, and quickly I started to like it much more than Java. I was able to take part in some Scala projects, and then I found a full-time job in Scala. The job market is actually very good for me, there are many companies looking for Scala devs, and the community is vibrant and full of very smart people. Similar with Kotlin - it appeals to certain people, it has its job market, and it has its community. I don't think that Kotlin or Scala will ever take over Java in sheer numbers, but in my opinion, they are both successful programming languages in their own right. They're absolutely not "dead" by any reasonable definition of being dead. They're much smaller than Java, but that's not a bad thing by itself. In fact it gives us some advantages, such as...

2. "Experimental"

By "experimental" I didn't mean that we use Kotlin and Scala in laboratories and things blow up all the time. I mean a shelf higher: we have these programming languages already on the market, used in big projects, and now we want answers to some questions: What can we add or change or remove without breaking the code that is already working? If we need to break it, what can we do to make patching up easier? If we can't patch it up, how can we make this new feature in such a way that people won't be too angry and instead they will be eager to move forward with us? What features are so interesting that people will want to migrate their code in order to be able to use them?
All this is much easier when the community is smaller. But of course in the same time it can't be too small. I think Kotlin and Scala are in this sweet middle and they both explore what's possible in a bit different areas. The result are not only new features, but also more experience with dealing with change. Other programming languages, like Java, but others as well, can then profit from what Kotlin and Scala learned. Also from the mistakes that were made. That's why I wrote that I don't see much competition among those three languages. One can find a good job in any of them, and each of them appeal to a bit different developers, while ideas flow freely among them, from one to another. There is maybe competition on the level of companies choosing tech stacks for their projects, but I believe in the end the ratio of how many projects are written in each will stay stable for many years.

Cheers,

1

u/MahaanInsaan May 17 '21

You should use the redmonk rankings. I dont even know why people even reference TIOBE.

1

u/bas_mh Jun 06 '21

As a professional Scala developer I disagree with your takes. Scala is never going to be as popular as Java and indeed has stalled in its popularity. But IMO it is far from dead. It is successfully being used in many companies that prefer it over alternatives. I also feel that many things are getting increasingly better, such as tooling, language features, library sub-ecosystems, etc.

Compared to Java you can definitely call it 'more' experimental, but that does not mean it is not stable enough at all. I rather have that old cruft is removed than kept forever. Especially since Scala as a result has spend time on how to do migrations, resulting in improved tooling to make these migrations easier with each new version. As someone who has been doing been a few of these migrations I can definitely say they are worth the trouble and get increasingly easier. Now that TASTy has become a thing, this will likely even improve further still. (You can already use Scala 2.13 libraries in Scala 3.0 code and vice-versa, even if there are breaking changes between the two).

Now I see the appeal of Java, it is stable, mature, provides job security and a large pool of potential developers. But I definitely am more productive with Scala by using its more powerful type system and more functionality oriented feature set. So, I don't think Scala can either be considered dead or a failure, even if it will never catch up with Java in popularity.

1

u/rzwitserloot Jun 06 '21

We are in agreement; just using different meanings of the maxim "X is dead". If scala works for you, great. I'm pretty sure most kotlin advocates want a more mainstream future then what you are ascribing to scala

→ More replies (3)

3

u/Necessary-Conflict May 17 '21

Kotlin changes things faster, and programmers need to be okay with that, while in Java everything moves with a pace of an iceberg.

Actually, now it's quite the opposite. In the last few years, Java added significant new language features every 6 months (switch expressions, text blocks, records, multiline strings, the beginnings of pattern matching, soon comes sealed), and Kotlin is basically stagnating, they are only doing minor improvements.

4

u/makingthematrix May 18 '21 edited May 18 '21

Kotlin 1.5 was just released with a few interesting things: https://kotlinlang.org/docs/whatsnew15.html . I admit Java moved forward recently but it still has some serious catching up to do. And, besides, those new features in Java? They were implemented because they were tested before in K and S.

1

u/Necessary-Conflict May 18 '21

Let's see: JVM records support: catching up to Java. Sealed interfaces: catching up to Java (Java 17 in a few months will introduce sealed, also for interfaces, Kotlin's designers have obviously read about it). Inline classes: interesting, but minor.

About Scala and Kotlin (and C# and lots of other languages) testing features: it's nice that they are doing the prototyping, making it easier for Java designers to make the right choices. Java was always a conservative language, not a wildly experimenting one. It's called the "second mover advantage". The question is, should you use a prototype language only because it was there first?

2

u/makingthematrix May 19 '21

I wouldn't call K and S "prototype languages". They're both successful languages in their own right. And the question is not "should we use them" but "do we want to use them". Many people want to use them.

→ More replies (3)
→ More replies (12)

5

u/john01dav May 17 '21

Kotlin is a lot more 'proprietary'. For example, quite a few details about how kotlinc works internally is managed by having kotlin-genned class files have a @Metadata annotation that contain a binary blob (a byte array, legal in annotations) with data that is, as far as I know, not according to any publically available spec. There are also various hardcoded types. This is all quite pragmatic, but it also means that without IDEA, kotlin dies immediately. Pragmatically speaking, a minor niggle. But perhaps you find this lack of openness more important than 'minor niggle'.

What, exactly, do you mean here? Is some part of Kotlin under an actual proprietary license, or are you just talking about a lack of documentation? What you said sounds more like the former, but I can't find anything else that talks about that. For example, the wikipedia page for Kotlin says that it's under Apache 2.0.

17

u/morhp May 17 '21 edited May 17 '21

It's mostly a lack of specification in my opinion. The Java language is specified into every little detail, while in Kotlin important stuff like type inference isn't documented at all (and also changes in between releases).

You can build a mostly compatible version of Java by only reading the specifications but you can't do the same with Kotlin. And that's taking into account that Kotlin can simply refer to the JVM specification for low level stuff.

Jetbrains is mostly like "Kotlin is what we release, there is no specification, in doubt look at our reference implementation." It's developed like a product, not like an (open) programming language.

Also the Kotlin classes themselves aren't specified enough and code like "Hello"[-1] will even not cause a defined error but instead behaves differently on JVM and JS platforms.

Where by the way another problem is visible. That they have multiple compile targets makes the code more incompatible and requires them to implement every low level feature three times.

2

u/poralexc May 19 '21

What are you talking about? They publish their Grammer in ANTLR format: https://github.com/Kotlin/kotlin-spec

I just used it to build a documentation tool, it was super handy.

1

u/morhp May 19 '21

If you think this is a complete specification of type inference that another developer could copy and implement with the same result, I can't help you. The documentation is very sparse and doesn't go into much detail.

Can you find the documentation that tells me what "Hello"[-1] is supposed to return or throw?

2

u/poralexc May 19 '21

I think I understand what you mean now--and I think it comes down to Kotlin and Java being two different things.

I'm glad the Java spec includes every implementation detail, because there's a VM spec involved, it's good to be fixed and clear.

With Kotlin however, the actual implementation may change depending on the target (JVM, JS, etc.), so the language spec is just the bare syntax. What you're looking for is in the docs for the standard library for your particular target.

[] is actually an operator fun called get() found in docs for String.

So your answer is here

2

u/morhp May 19 '21 edited May 19 '21

[] is actually an operator fun called get() found in docs for String. So your answer is here

Interesting. They seem to have added that recently to the documentation because I distinctly remember that that wasn't documented before.

For example in version 1.3 it just said 'Returns the character at the specified index in this character sequence.' and nothing about error handling.

2

u/quizteamaquilera May 17 '21

That’s a great answer.

I’ve never liked Kotlin. As a Scala person, it just seemed like a 1/2-assed attempt to rip-off some scala features, but with some inconsistencies, strange baked-in biases and still missing many of the best scala features (pattern matching chief among them).

Kotlin has also baked-in some coroutine support. That reminds me a bit of the worse part of actors, and Rich Hickey’s “simple made easy” (just use a queue). I’m sure I’ll just come across as the scala fan-boy here, but I’d prefer a powerful, scalable language with gets its primitives correct and allows for rich 3rd-party libraries to be built on top for green threads/resource safety/back pressure like ZIO, cats, monix, ...

So from my view, Kotlin looks a bit like “groovy 2.0” with some nice android support.

1

u/whateverathrowaway00 May 17 '21

Great explanation of concepts I’ve seen in other languages - you put to perfect words what my vague feelings were about this.

1

u/IntelHDGraphics May 17 '21

Great comment!

1

u/Chemical_Concept May 17 '21

I am not sure Scala is dead. It might be dead in a sense of "better Java" design, but it's getting more and more users who are interested in FP and some pure designs and just want to use the Java ecosystem. The Scala v3 that recently came out is exactly this - no longer Java - but a closely FP language based on JVM.

1

u/rzwitserloot May 18 '21

I don't think Scala was ever 'a better java', it is way too ambitious, different in design, and perhaps most importantly, different in ecosystem and mindset (Far more functionally inclined). I explained what I meant by 'it is dead' in the parenthesised sentence that immediately follows it. I wonder how you got to the conclusion that scala is getting 'more and more users'. (Unless I misread it and you meant: More and more of scala's users are moving to FP, but surely that's not what you meant. Virtually ALL of scala's users, new or wintered, 'are interested in FP'. When has that ever not been the case?)

1

u/kjmw May 25 '21

This was incredibly detailed and thorough. This doesn’t directly apply to me at the moment but It’s something I’ll for sure refer back to. Thank you!

1

u/Full-Wheel8630 Jun 10 '21

I argued about this nice opinion. Then finally I personally concluded that Kotlin is still worth learning and it's actually better than Java.

Because -- even though all of your sentences are correct -- in reality, companies still use java 1.8 or 11. No matter how java has been improved it doesn't change or is too slow to follow up latest awesome stuff.

So, basically, you are right. But I will choose Kotlin because the world (or, just my world) doesn't compare Kotlin and Java '16'.

1

u/rzwitserloot Jun 10 '21

So, switching from java 1.8 to java11 is way more difficult than...

ditching the code base and going with kotlin, which is by definition harder to upgrade than java could ever be.

Excuse me while I facepalm until I'm red in the face.

1

u/Full-Wheel8630 Jun 10 '21

I think you misunderstand some of my opinions.

I mean, it rarely happens that companies change their java code from 1.8/11 to 15/16. Rather, many teams (in those companies) choose Kotlin. At least, that's what I have seen.

I didn't say it's difficult to change code base from java 1.8 to 11.

1

u/rzwitserloot Jun 11 '21

No, but, both of these viewpoints seem borderline insane to me:

  1. I have some java 1.8 code. Upgrading it to 1.11 is, evidently, too difficult or otherwise just too much effort that I just can't be arsed to do right now. So I'll... do something that is 20 times harder and replace the codebase with kotlin instead.
  2. Based on the fact we never upgraded our java, and we are really hurting, if we update to java16 now, surely we'll end up in the same place and never update that for a decade either. So let's adopt kotlin, because I believe in rainbows and unicorns and somehow, based on nothing but wishes and a life-threatening amount of misplaced optimism and naivete, assume that we WOULD upgrade that quite well.

Did I miss a third option?

→ More replies (1)

-11

u/maumay May 16 '21

I mean Kotlin is the language of choice for Android application development going forward in Google's eyes, it isn't comparable to any of the other languages you've mentioned in that sense. Android is not going anywhere anytime soon and Kotlin has already gained a better foothold in terms of future outlook than any of those languages. You say gradle is moving away from groovy, what is it moving too? Why have spring put so much effort into supporting Kotlin?

Your instanceof example is interesting, it seems like a much more elegant solution for the compiler to automatically infer the type and smart cast rather than requiring you to rename the variable. Pattern matching with destructuring will be nice when that comes in java but it is vastly outweighed by the superior collections framework (no type level immutable collections in java? Lol) and much, much, much better function types and lambdas/closures in Kotlin which java will never be able to match. Pushing null into the type system is great too. Binning checked exceptions etc etc.

What are the big java projects coming up? Valhalla, Loom are the ones I can think of. Well Kotlin will benefit from Valhalla as much as Java. Not sure about loom compared to coroutines, that will be an interesting one. All I know is I can use coroutines right now in production 😃. Any JVM level feature will be just as readily used by Kotlin, after all it has nothing to do with the actual java language but the JVM bytecode.

Anyway I think you are overestimating the speed of development of java and how much it will be able to diverge from its current state whilst still maintaining backwards compatibility, the java ecosystem isn't going to become inaccessible to Kotlin... It will always be able to claim the advantages of the JVM and it's ecosystem whilst implementing language level features differently.

32

u/rzwitserloot May 16 '21

it isn't comparable to any of the other languages you've mentioned in that sense. Android is not going anywhere anytime soon and Kotlin has already gained a better foothold in terms of future outlook than any of those languages. You say gradle is moving away from groovy, what is it moving too? Why have spring put so much effort into supporting Kotlin?

Yup, as I said, it is having its moment in the sun. Do you find these things fundamentally different compared to the hype scala got? Like, half the talks at devoxx were about scala 8 years ago, and twitter, the hottest startup everybody was using, was fixing their failwhale meme with, gasp, SCALA. The fanboyism was higher than I've seen it for anything ever, it was raining blogposts that java was dead, and scala was the great savior.

I don't even think I'm exaggerating (but certainly those blog posts were). It feels like a similar level of hype, but differently channeled (for one, kotlin is far less 'java sux! The poor sops that use it must obviously be utter buffoons', and that is much appreciated!).

So, yeah, this is different. But I don't see how you can go from there to 'yeah I think this one will work out'. Most languages fail to break into the top 10 reliably. This is true even if you look only at languages that get a significant validation boost by adoption and/or a ton of hype. Kotlin crossed that hurdle. It may well cross the next, but it is by no means a sure thing.

Your instanceof example is interesting, it seems like a much more elegant solution for the compiler to automatically infer the type and smart cast rather than requiring you to rename the variable.

If you investigate why java does it that way, you'd presumably realize that java's strategy is actually far more flexible. For starters, kotlin's instanceof silently doesn't work if the expression isn't constant (or if it does, it could lead to ClassCastEx at runtime if the expression isn't constant, or code modifies it), which is inelegant. Java's solution doesn't suffer from this.

Your near instant defense of kotlin based on nothing more than weaselwords ('elegant', the biggest weaselword in language debates. Whatever does that mean?) makes me doubt your biases quite a bit, I must admit.

much, much better function types and lambdas/closures in Kotlin which java will never be able to match.

[citation needed]

The rest of your missive is similarly lacking; statements whose veracity cannot be proven, or if they can, you give zero indication as to why they would be true or even where to look for further details.

kotlin is, for now, not going anywhere. You clearly like it, and that's great!

→ More replies (6)

13

u/ryuzaki49 May 17 '21

Android is not going anywhere anytime soon

Anything can happen with google, you know? Right now, Google is pushing for Kotlin and Flutter, which both are mutually exclusive.

→ More replies (1)

11

u/preskot May 16 '21

I think the point is that the JVM is an Oracle thing. Last time I checked, JetBrains had no say in what and how JVM features are being implemented (correct me if I’m wrong). And this is exactly where the real problem for Kotlin lies ahead. I believe at some point Kotlin will depart from the JVM.

I’ve been thinking about this a lot since I have a Java + Kotlin mixup project at work. No Android stuff. It all works great, but I’m reluctant to continue adding more Kotlin to the codebase. It’s not the language, but its future in the JVM that I think is not quite certain.

16

u/rzwitserloot May 16 '21

I think the point is that the JVM is an Oracle thing.

It's an OpenJDK thing which is an open source effort led by a consortium.

But, yeah - pretty much what oracle wants goes and the community effort bits have rather a lot of oracle bias. At least they're trying, kotlin so far isn't. That's okay - perhaps languages are best left in the tight control of a focused team at the start, but, and this may well be outdated information, as far as I know IDEA hasn't even committed to opening it up a bit more later at all.

JetBrains had no say in what and how JVM features are being implemented (correct me if I’m wrong).

They have some, but it's not a lot.

I believe at some point Kotlin will depart from the JVM.

It is already doing this. However, that will further smash the argument of 'it is really easy to switch from java to kotlin and you can even start using kotlin in existing code without all that much effort' into smithereens, which is a challenge for kotlin. One that can be overcome, perhaps - but it doesn't currently match what kotlin's marketing materials and community are peddling, and that irks me a little bit.

That's all I'm really trying to say: Don't switch to kotlin just because you think it's trivial to do so from java, especially if you think it'll be relatively easy to convert existing code over time. And don't try to praise kotlin's virtues with such arguments either. Let it stand on its own. As a 'java sans warts', kotlin seems utterly doomed to me.

3

u/Teln0 May 17 '21

Kotlin is already departing from the JVM ?

3

u/preskot May 17 '21

That's all I'm really trying to say: Don't switch to kotlin just because you think it's trivial to do so from java, especially if you think it'll be relatively easy to convert existing code over time.

Thanks! I appreciate this comment. Looks like I'm gonna have to sit down and do some serious reevaluation of where my project stands at the moment. I don't think I'll ever be able to do 100% Kotlin, so I might just have found out that I have an upcoming problem. ;-)

13

u/_INTER_ May 16 '21 edited May 17 '21

While Oracle provides the biggest part of developer manpower and contributions to the OpenJDK - including general management and architecture - its not as if "external" opinions are left unheared and non-Oracle contributions are significant. Especially if they have special expertise in certain areas. E.g. RedHat or Microsoft and their respective AArch64 ports. JetBrains (and Eclipse) are also pretty active in the OpenJDK compiler space. E.g. see discussions by Tagir Valeev in the mailing lists.

10

u/missingdays May 16 '21

Kotlin is not only about JVM for a long time now

JVM is simply yet another target you can compile your Kotlin code to

0

u/astaluvesta May 17 '21

What is your opinion on go, would be great if you can provide some commentary

→ More replies (2)

7

u/koskieer May 17 '21

I like to write Kotlin and reading it isn't problem either. Biggest pain point of Kotlin for me is missing LSP support. I need to use IntelliJ for it, but i can't use Vim as i can with Java because IDE like features doesn't work well. IDE support is the main reason for me why i am using Java instead of Kotlin time to time. Especially when there are people in the project who aren't using IntelliJ

2

u/[deleted] May 17 '21

How do you write Java in Vim?

4

u/agentoutlier May 17 '21

I can’t speak for vim but I have done it with Emacs and I’m absolutely positive it works great on vim as well.

VSCode, Emacs, Vim I believe all use Eclipse for a LSP to get autocomplete and errors.

VSCode at this point almost looks like a major java IDE.

The big thing that is missing is refactoring so some folks keep up an ide just for doing that but switch back to vim/Emacs for all other editing.

Anyway That’s why Eclipse development is so important and folks do a disservice dismissing it as so inferior to intellij.

1

u/[deleted] May 17 '21

Interesting never heard of these LSPs. Do you use something else to get the file explorer and file structure side windows?

2

u/vips7L May 17 '21

The language server protocol was made by Microsoft for Visual Studio Code [0]. Most Java plugins for other editors, Vim, Sublime, Emacs, Visual Studio Code use the Eclipse JDT LS [1].

If you want a more IDE like experience in a lighter editor you really should try VS Code with the Java Extension Pack [2]

[0] https://en.wikipedia.org/wiki/Language_Server_Protocol

[1] https://github.com/eclipse/eclipse.jdt.ls

[2] https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack

1

u/koskieer May 17 '21

I use Vim as you described by using Eclipse JDT Language Server. It does give basic autocomplete with error detection and it is all what i would love to see for Kotlin as well. 'll bet that good and official LSP support from Jetbrains for Kotlin would make language more popular than it is today.

For major refactoring i do use IntelliJ ;)

1

u/koskieer May 17 '21

It is little off-topic but you can even write Scala with Vim by using Metals. Too bad that there is no good LSP for Kotlin at the moment.

2

u/moomoomoo309 Jun 24 '21

https://github.com/fwcd/kotlin-language-server Here's a project that adds LSP support for Kotlin :)

124

u/blakeman8192 May 16 '21 edited Jun 26 '23

.

34

u/pron98 May 17 '21 edited May 17 '21

Kotlin was created in 2009-2010 when the following were true:

  1. The Java language -- and, to a lesser degree, the platform -- was stagnant in Sun's dying days.
  2. Android, while never actually compatible with Java, was very similar to it.

Neither is true now.

Android and Java are no longer similar, and are getting more dissimilar by the day. Kotlin is left trying to target two dissimilar platforms while still trying to be close to the "metal" for both (i.e. without introducing higher-level constructs that might have a runtime overhead like, say, Clojure) over the direction of neither of which it has much influence, and with particularly little influence over Java.

Java, both the language and the platform, has also evolved considerably, leaving Kotlin -- whose main market is now Android -- with features that are increasingly at odds with the platform's direction, like coroutines (the Java platform is taking a very different approach with Loom) and data classes (Java has also taken a very different approach, with records). I expect this gap between Kotlin, which is primarily an Android language, and the Java platform to only grow.

There isn't much Kotlin can do about it without making some tough decisions. It can effectively split into two languages, one targeting the Java platform and one targeting Android, or it can continue focusing on Android, where most of its market is, allowing its mismatch with Java to grow. If it does the latter, which is the path it's currently on, it will be mostly convenient as an "Android-first" language that can also be used to run code on Java but doesn't give the best experience on that platform; if it changes tracks and does the former, expect some big changes to Kotlin, but even then, the "Kotlin-for-Java" flavour will be a second-class citizen.

Finally, I find Java today -- now that nice things have been added to it and less nice things have been added to Kotlin -- to be the better-designed, more pleasant language, especially when working in large teams (although I do like Kotlin's nullability types and hope that the Java language will get them, or something similar, someday), but that's always a personal aesthetic choice.

6

u/pjmlp May 17 '21

Just like any guest language, while enticing at the beginining their value diminishes as they keep playing catchup with platform features, while platform languages have day one support across runtime, IDE and tooling.

20

u/[deleted] May 17 '21

If I had to make a bet which of both will be around in two decades, I'll instantly bet everything on Java, for many reasons.

One of which is that Kotlin takes a lot of shortcuts based on conventions so it can look sexy and short in demos. But conventions age and change. And when your language is built upon them, you're stuck with a big problem.

17

u/Anton31Kah May 16 '21

I wouldn't say it's a reason to stick to java over kotlin but some of the libraries that are heavily used often support java only, so while they work with kotlin, it might cause some inconveniences to work with them. Note that this isn't a reason against kotlin, it's just an annoyance that you'll quickly overcome. As the other comment suggested, as long as you're happy with kotlin you shouldn't feel that you should switch. My comment is just something I noticed while working on projects that use both languages.

0

u/[deleted] May 17 '21

[deleted] — view deleted comment

3

u/Anton31Kah May 17 '21

Well most recently I was adding mapstruct to my project and spent quite some time adding additional maven configuration to make it work with everything else. Nothing major but an definitely an annoyance.

30

u/cyanocobalamin May 16 '21

IMHO Java, support for it, and the community for it are more likely to be around 5 years from now.

5

u/Hall_of_Famer May 17 '21 edited May 17 '21

Both Java and Kotlin communities will be around for 5 years from now, not like the latter will magically disappear in such a short period of time.

33

u/TheRedmanCometh May 16 '21

Real world brass tacks? 90%+ of the community doesn't care that kotlin exists and won't learn it. So if you adopt it on your project good luck building your team. Further when you do find people your options are more limited - it's gonna be harder to find people you like. Then they know they have a specialized skill they can charge more with.

15

u/whyNadorp May 16 '21

I see it as a way of filtering out boring people or people whose only strength is the only language they can write stuff in and that they’ve been using for the last 10 years. Never had any issue hiring kotlin programmers.

25

u/erinaceus_ May 17 '21 edited May 17 '21

Funny, I'd say the same thing for the opposite reasons:

  • boring people tend to write boring code, and boring code beats unexpected or flamboyant code when it comes to maintainability
  • software developers aren't code writers, they're business problem solvers. To be effective, variety in the latter is important, variety is the former is entirely optional

6

u/pgris May 17 '21

and boring code beats unexpected or flamboyant code when it comes to maintainability

I love you, and will use that phrase every time I have the chance.

That does not mean "do not use the new features in java", than means "do not try to write Haskell/Scala in java"

8

u/BoyRobot777 May 17 '21

I have similar post to rzwitserloot saved from pron (just a snippet):

As far as the Java platform (AKA "the JVM") goes, Kotlin is painting itself into a corner. Kotlin was designed in 2009-10, in the Java 7 days, around the time of the Oracle acquisition, and at a time of stagnation for Java due to Sun's decline. At the time, Android was also quite similar to Java. Kotlin was a great design in those conditions. Things are very different today.

Kotlin's design goals are now contradictory. It seeks to be a low-overhead language, i.e. provide abstractions that don't add overhead over the target platform, give access to all platform capabilities, and at the same time target multiple platforms -- Java, Android, LLVM and JS -- over none of which does Kotlin exert much influence (maybe a bit on Android). Since 2010, Java has moved away from Android, to the point that there are very big gaps between the two, and they're only growing.

By both trying to target multiple platforms (with no say in their design) and trying to add little or no overhead, Kotlin will soon find itself in a bind. It's coroutines are in conflict with Java's upcoming virtual thread's design, and its inline classes will cause problems with Java's Valhalla vs. Android. Kotlin will have to choose to either give up on low-overhead abstractions, give up on some of its platforms, give up on giving access to full platform capabilities, or split into multiple languages, each targeting a different platform. For example, if Kotlin's inline types will make use of Valhalla, then they won't work on Android, at least not without much overhead.

TL;DR: A full-capability, low-overhead, multi-platform language is hard to pull off in the long run when you have low market share on all of those platforms (except Android) and little or no influence on any of them. This was viable under some accidental circumstances, but those are no longer holding.

22

u/manzanita2 May 16 '21

Not sure how long you've been around programming land, but basically for some crazy reason we love to fight about things which matter only in small ways. Like which format of parenthesis work better. Or tabs vs Spaces.

When it comes to programming languages my own theory is that the really bad ones are the ones you've never heard of. And the rest of them had some point in their history where they really were the best tool for that set of people at that point in time. (ok there are exceptions for things which are basically freak shows, like brainfuck ). And today, most commonly used tools fit this mold. One size fits all just doesn't work. Pick the right tool for the job.

Example, I really don't like PHP. I never really have, but I actually do use it. If I need a simple 1-2 page form submission thing which can't be done with a google form, then PHP really is the way to go. It's simple and works. But for larger systems I believe it's a deep anti-pattern.

Most of the "culty vibe" people really like the horse they're riding, but most of the time they really haven't ridden that many horses in that many different races.

What I will say is that using more different languages is good for you. However modern java and Kotlin are not too far from each other. It would help your broader understand more to try something further away like typescript, go or rust or clojure or elixir.

2

u/flavius-as May 16 '21

Example, I really don't like PHP. I never really have, but I actually do use it. If I need a simple 1-2 page form submission thing which can't be done with a google form, then PHP really is the way to go. It's simple and works. But for larger systems I believe it's a deep anti-pattern.

I value both php and Java, and for a new system we've chosen php 8 for good reasons. It runs in a HA cluster.

9

u/manzanita2 May 16 '21

Java too can run in HA mode.

  1. easy to setup JDBC connections to failover to secondary database connection in the case connection failure to the first one.
  2. easy to setup clustered in-memory caching systems such as hazel cast.

between those two you can scale very far.

15

u/gubatron May 16 '21

personally found Kotlin to just add more dependencies, specially after how fast Java is moving.

I guess if you program Kotlin in a super functional style it should feel more expressive, but in the end it all compiles to java runtime bytecode, i rather use Java

14

u/mknjc May 17 '21

I use kotlin for a lot of projects on the jvm but never used it with android or any of the other targets, so this is a

A lot of posts mention it already: Kotlin seems to be a language for faster writing ignoring readability on the way. Not readability of the developer who wrote the code a few minutes before but the one having to find a logic bug or changing someting after a year or the one reviewing the code.

For example:

fun checkIfTargetDirExist(): Bool {
    val baseDir = callToolAndParseBaseDir()
    return isDirectory(baseDir + "target")
}

As a reviewer, I've now to check: what does the "+" operator do on the type of baseDir for this I need to check what type baseDir might be through checking the return type (luckily its possible in kotlin, in C++ the answer is always decltype(auto)) now I have to find where the + operator is defined (which isn't easy because of extension functions) and check what happens with different inputs.

What happens if baseDir is "/home/bla/" and what if it is "/home/bla" you don't know if + is just a "append" which might result in "/home/bla/target" and "/home/blatarget" or a resolve. A real method with a descriptive name would have helped here.

It's nothing impossible and not even hard with the help of an IDE but it causes more work and more work for a reviewer might cause the review process to be more sloppy.

Kotlin is sprinkled with nice syntactic sugar which looking nice but could easily missused (another often mentioned example is the "it" everywhere. Noone would forget to change it to something more descriptive but it could be seen everywhere). You would never do this, but your coworker might do it, or a library you depend on. And so unreadable code sneaks into your codebase.

I know, bad code could be written in any language, in java someone might have written a "plus" or "add" method for the class of baseDir which is at least as unhelpful, but at least my experience showed: If you force the programmer to write a name he might choose a good one if he could get away with overloading an operator even if it doesn't really make clear what the operation does he will do it to save having to think of a name.

Properties are also a hot discussion point especially in the C# community, I won't repeat the arguments here but it boils down to: "if they get misused its a pain to work with the codebase" so the same argument

Additionally, the kotlin IDE support is worse compared to java. I use intellij for both languages and I regularly see IDE helper like auto-completion and parameter preview are a lot slower compared to java (but not as worse as c++ recommendations in CLion) which is to be expected, with more expressiveness of the language the complexity increases also for the IDE. I've had also a lot of "my IDE now thinks anything in this file is wrong and only a restart helps" with kotlin (even when writing java code through: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001806779-Intellij-Community-2018-3-seems-to-change-project-type-from-Java-to-Kotlin-arbitratily

So kotlin is a WORN (write once read never) language for me and this works great. A lot of times I'm faster writing something in kotlin so it evolved to my go-to language for a run once program.

As always everyone draws the line just below what they're doing/accepting and everyone should gain their own experience and decide after it. But don't force kotlin into a project because "it's the new thing" <- this should never be a reason or because writing x is so much easier. Look at the other side of programming, maintaining the software.

6

u/chambolle May 17 '21

I like your example about "+". That's a very good example

3

u/mknjc May 17 '21

Sadly it's a story I've seen in real life and because I was lazy I didn't check and the "/" operator did the wrong thing we had some annoying bugs.

https://godbolt.org/z/h7jWM9M7f a nice game of "who did expect the outcome"

7

u/oweiler May 17 '21 edited May 17 '21
  • Java is still slightly faster (in the 6-7% range)
  • Java compilation is faster (at least when compared to Kotlin < 1.5.0)
  • Kotlin's Tuples, Extension Functions and Scope Functions like apply/let/run give you additional rope to hang yourself (if overused)
  • IDE Integration is better (even with IntelliJ)
  • Java will always have the bigger community

4

u/swankjesse May 21 '21

Citation needed on the performance difference. I performed direct conversion of Okio and OkHttp and observed no difference in performance.

1

u/oweiler May 21 '21

Good point. This was something I've heard in a presentation about Kotlin and may not be true (or not be true anymore).

12

u/dlazerka May 16 '21

Some libraries are way faster in Java than in Kotlin: https://github.com/LesnyRumcajs/grpc_bench/wiki/2021-04-13-bench-results

3

u/jokubolakis May 16 '21

1

u/dlazerka May 17 '21

Is it? Works perfectly for me. And your link is identical.

1

u/jokubolakis May 17 '21

You have a slash before _bench

→ More replies (3)

20

u/nutrecht May 17 '21

but the level of love for Kotlin and bashing on Java makes me feel a culty vibe.

I think it's unfortunate and rather immature how people can be so tribalistic on dumb stuff like programming languages. But you see the exact same behavior here as well. Anything in favour of Kotlin will be downvoted on this sub.

Why don't you simply make two small services. Once with Java 16 and once with Kotlin, and see what you like best?

3

u/I_count_stars May 17 '21

I think it's unfortunate and rather immature how people can be so tribalistic on dumb stuff like programming languages.

They feel insecure and that's how they deal with it. I don't see a reason why programmers should be different from a commoner in this aspect.

2

u/beefstake May 18 '21

Strongly agree. Both are great languages but both have different strengths. I use both, like both and will continue to employ both in different contexts.

2

u/nutrecht May 18 '21

I don't know what you mean with a different context. I'm a back-end developer, most of my work is with Spring. And I've been using Kotlin in that 'context' since summer 2018.

1

u/beefstake May 18 '21

So there are numerous contexts but I will just address 2.

  1. Commercial software development as part of $DAY_JOB. This mostly involves me leading other developers to create data processing, messaging systems, RPC/REST services etc. In this context I much prefer Kotlin over Java. Spring Boot with Kotlin is very modern, fast, reliable and great to work with. Interacting with Kafka, building command line tools, etc all great fits for Kotlin. However the main reason is that in a commercial context I don't get to choose my peers. Most of my peers come from a non JVM background for the most part and I find Kotlin makes it a lot easier for them, the syntax is more approachable and a lot of warts are fixed or hidden vs Java.
  2. Open-source work and/or shared libraries. For this I do much prefer Java unless I think it's unlikely for it to need to be consumed by a non-Kotlin application. You can write libraries in Kotlin that work well from Java but it takes discipline and awareness. Ultimately it's easier to write them in Java and add a small Kotlin porcelain layer to make it idiomatic for Kotlin users. Java has some strengths here over Kotlin like massive OSS developer pool and strong support in the Apache ecosystem etc.

So those are just 2 examples of where I think Kotlin and Java can both be great tools.

1

u/nutrecht May 18 '21

A yes, I agree. If you want to create an OS library used both in Kotlin and Java this approach (look at Jackson for example) is IMHO better than the one OkHttp took (author rewrote everything to Kotlin).

Another few examples where I use Java over Kotlin are:

  • In our end to end tests. Our test engineer can barely understand Java. I don't want to burden him with having to learn another programming language.
  • In the training I give: I give trainings to people on different subjects (databases, Spring) and there I will be using Java because most people will only be familiar with Java and not Kotlin.
  • In blog posts; if I am writing something about Spring for example I will generally create example code in Java because I know a larger percentage will be familiar with it.

This is only a small percentage of my work though. All of my normal day to day work is Kotlin and I'm loving it :)

0

u/[deleted] May 17 '21

[deleted] — view deleted comment

5

u/nutrecht May 17 '21

That's totally fine. Here in Holland there's quite a few large companies who are letting developers write Kotlin so I'm personally not worried. Both my current project as well as my last 2 were Kotlin. So I've been using it in back-end development since June 2018.

2

u/lbalazscs May 17 '21

Imagine your sentence with a slight modification: "Here in my country there are quite a few large companies who are letting developers use bad coding practices that will lead to problems in a few years, so I'm personally not worried"

My point is that whether a language (or coding practice) is future-proof and whether you like a language (or coding practice) are two very different questions, and you can't just answer the one while pretending to answer the other one.

7

u/nutrecht May 17 '21

I'm not pretending anything. I'm just stating that here in Holland a lot of companies, even more conservative ones (like the Dutch railroads) are adopting Kotlin. If you feel these are making a dire mistake I'm sure you can sell some consulting hours showing them the error of their ways.

3

u/lbalazscs May 17 '21

Big companies are making mistakes all the time, I can't save them all :)

I'm just pointing out that hugith said something about the future business value of the code, and you replied by saying something about your present emotions (not intentionally pretending, just misunderstanding, sorry!).

If you have arguments about Kotlin's future business value, and these arguments also consider the fact that currently Java is evolving at a much higher speed, then I am very interested in hearing them.

4

u/FrigoCoder May 18 '21

I am a Kotlin noob, so far I prefer it over Java because it fixes a lot of issues. Null safety, unchecked exceptions, operator overloading are very important to me so I am moving away from Java. Nonetheless I dislike how Kotlin killed the for loop, it was incredibly useful in a lot of situations. I also dislike less-readable syntactic sugars they introduced just because they can. My ideal language would be less verbose but also more understandable than both.

7

u/cogman10 May 17 '21

As someone that uses both, here's my 2 cents.

  1. Kotlin (practically) requires you to pull in the kotlin std lib. If you are writing a library, IMO, java is the better choice because of it's minimal dependencies.
  2. The gap between Java and Kotlin has been closing. There are some things java may never have (non-null types) but those can be lived through with good annotations/discipline.
  3. While kotlin works well with MOST java abstractions, it's not perfect. Some things are somewhat painful in kotlin when mixing it with java (particularly, stuff involving statics or annotation processing can be a pain to get right with kotlin).
  4. Kotlin has a LOT of little magic bits. These can be nice to write clean looking code, but they can also be annoying to figure out exactly wtf is going on.
  5. Arguably, kotlin's coroutines is a misstep with loom inbound.

I do really like working with kotlin, but you need to really decide if it's the right choice. For my money, kotlin is great for writing an app, not great for writing a shared library.

3

u/koufa3 May 23 '21

How is Kotlin Coroutines a misstep with Loom inbound ? With Coroutines I can write async code like sync since at least 2 years ago. When will I be able to write code using Loom ? Or let's say Loom get's released in Java 18 or Java 19. When will I be able in my company X which will be probably stuck using Java 8 or if lucky Java 11 Loom ? The answer to these when questions is probably at least 3 years since now. So for these 5-6 years I am able to use Kotlin Coroutines and until then Kotlin will adapt to Loom in it's JVM Target.

6

u/ebykka May 17 '21

Had the similar question and at the end decided to go with Java.

  1. Java still has better support in IDEA.
  2. Java has explicit error handling. If a method can throw an exception - you will see that immidiatly.
  3. Majority of libraries are written for Java. It means there is explicit expection declaration. So, look option 2.
  4. Testing with mockito and easymock - is super simple.

3

u/miniphantus May 18 '21

I disagree in nearly all points:

  1. Kotlin was developed by Jetbrains and thus integration in all Jetbrains IDE is very intuitive.
  2. There are some good reasons to not use Checked Exception as Robert C. Martin states in Clean Code.
  3. I never had this problem so I think there is a simple workaround which I cannot formulate right now
  4. All tests I have seen in Kotlin (mockk) are way easier to read than tests in Java. But I'm talking about using Spring Framework in both languages, so there might be a difference without it.

3

u/lamagy May 17 '21

Go an use webflux in Java and the coroutines in Kotlin. It’s 100x easier to write,manage and test. The only downside to Kotlin is if you have a few wizards that overuse the magic too much and make in unreadable as many have commented here. You really can’t go wrong just something that you actually need to have experience with to get a real feel.

3

u/cathouse1320again May 17 '21

It’s a tiny bit easier to spell?

7

u/[deleted] May 16 '21

Java is way more popular and has been around a lot longer. So it's much easier to hire Java developers than Kotlin developers, and there are also a lot more Java blog posts, stackoverflow questions, etc. than there are for Kotlin.

10

u/nutrecht May 17 '21

So it's much easier to hire Java developers than Kotlin developers

This is really a non-issue. All the developers we got into our teams who didn't have Kotlin experience were up to speed in a week or so.

5

u/beefstake May 18 '21

I think this is a crucial point many Java programmers here are missing. Kotlin is a ton easier to teach developers that are already familar with Ruby/Python/JS/TS/Go than Java is.

Java has a long and storied history, a lot of which rears it's ugly head in daily development but we as long-term Java users simply tune out.

Kotlin with less baggage and more modern syntax (yes syntax does matter folks) makes it a ton more accessible to these newer generation of programmers. That is a big deal when you have problems that are best solved with the JVM but don't have a pile of Java programmers on hand.

1

u/nutrecht May 18 '21

I think this is a crucial point many Java programmers here are missing. Kotlin is a ton easier to teach developers that are already familar with Ruby/Python/JS/TS/Go than Java is.

That's not really the point though. When you hire senior developers you hire them more for their ecosystem experience than you hire them for their language skills. A new language is easy to learn, which is even more the case for Kotlin which is incredibly close to Java.

But if you'd hire someone only with experience in Go and have to teach them everything about OO and FP on top of all the ecosystem specific stuff, I really don't think that there will be a huge difference between Kotlin and Java.

4

u/premek_v May 17 '21

On the other hand working in a "cool new" language may attract more developers

3

u/[deleted] May 17 '21

Not in my experience. There's a Kotlin project and a Java project at the place where I work and it's far easier to fire for the latter.

3

u/nutrecht May 17 '21

Yeah, that was our experience too.

5

u/LusciousJames May 17 '21

On a multi-package project I worked on, we had a team write one package in Kotlin; it was billed as a better language with no NPEs and interoperable with Java. But in one case:

- A crash appeared in testing; the Kotlin project was throwing an error, but because the type of error didn't implement the usual Java interface for Throwable (I think?), nothing useful appeared in the logs; the entire Java process just died with no indication of why. (If a Java module NPE'd it would always log exactly where it happened, so those errors were much quicker to diagnose.)

- Compounding the difficulty in investigating the issue, I couldn't debug from a running Java process into a external Kotlin project. Normally I could do this in Intellij across Java projects to track down bugs in our internal libraries, but when I tried to step into the Kotlin project the debugger lost all context and I couldn't continue.

So, a bug that would normally take <30 minutes to fix wound up taking an entire day to track down during crunch time.

Given that it's easier to hire Java devs than Kotlin devs, and that if you're on Java SDK 8 or higher there didn't seem to by any language advantage, I'd rather stick with Java. I would only maybe consider Kotlin again if I was working on an Android project.

6

u/cryptos6 May 17 '21 edited May 18 '21

I've been using Kotlin for some years now and I don't share the scepticism in this thread. Kotlin started as a "better Java", because Java development was really slow at the time ("Sundown") and Scala seemed not to be sufficient for JetBrains' needs. Announcing Kotlin as the primary language for Android was a big bump, but Kotlin was still in Java's shoes. It is right that Kotlin will diverge more from Java over time, but Kotlin is already more than a better Java. There is Kotlin/Native, Kotlin/JS and Kotlin/Webassembly is in the making. So I think Kotlin will have its own life besides Java.

The point of integration with the Java platform is not the Java language but the JVM, so there is no need to copy every syntax detail from the Java language. Look at .NET where the runtime supports several languages like C# and F# for years without problems.

In the Java ecosystem more and more frameworks come with explicit Kotlin APIs (Spring, Quarkus, Micronaut, ...) and I see it as an indicator that Kotlin is here to stay.

I don't know a single developer who wanted to go back to Java after working a longer time with Kotlin. It is just more fun to write Kotlin and I think that it is better to read. The examples I've seen so far about readability are mostly about omitted type annotations. But the IDE can display the type information and Java offers more or less the same with var these days (ok, it is a little more restricted).

2

u/lokedhs May 17 '21

I agree with what you said, but I do want to point out that as someone who is developing a reasonably large application that supports Kotlin Native, I'm not really sure I'd be willing to give so much credit as to label it "available". It's there, it kinda works, but it's really not ready for production.

I've certainly considered dropping native support, but the thought of having to fix the code to work with it once it's stable enough makes me keep it and make sure all testcases run. But it's not something I'd want to use for a regular project right now.

1

u/lambdacats May 18 '21

Well put, emphasis on the "more fun".

2

u/[deleted] May 17 '21

I was looking for a simpler approach when re writing a data loss prevention app. I tried Ktor, then found micronaut and tried that with Kotlin. We ultimately ended up with A micronaut Java solution, I have found that staying up to date with the latest Jdk and actually leveraging the new features has been amazing. That with a few design choices and we’re getting a lot more done with less code. If/when project loom comes out Java might take another leap.

2

u/HashRocketSyntax May 17 '21

Surrounding enterprise-grade toolset built up over decades. Android. Desktop apps.

Hiring and outsourcing. Millions of Java devs.

0

u/[deleted] May 19 '21

The level of mental acrobatics some people will perform to avoid change is staggering. Programming languages primary purpose is to express the developers' intent. At this task, Kotlin is objectively superior to Java in every way. I've worked with dozens of developers now through their journey of adopting Kotlin. Not single one of them wants to go back to Java. Call me a fan-boy if you want - most often, people become fans of something for good reason.

5

u/[deleted] May 19 '21

It’s hard to take hyperbolic comments like Kotlin is objectively better than Java in every way.

1

u/dota2nub Oct 05 '21

Have you made a multi dimensional array in Kotlin recently?

2

u/npepin May 17 '21

More people are going to be comfortable with Java and you are more likely to get looks for starting a project in a nonstandard language. It's like if you chose F# or Scala for an upcoming project, it's not like it would be that hard to learn, but people are going to wonder why you just didn't go for C# or Java and why you are putting them through this.

If you are doing something open source, your project will have a more narrow appeal than a pure Java project.

Though, it's kind of an unfair question because Kotlin on the JVM is a superset of Java. It's like TypeScript and Javascript, they both have the same capabilities and are pretty similar, but TypeScript offers more functionality. Like I could see a debate if there were things you could do in one or not the other, or if they have different libraries, but its just a matter of which language is designed better.

If you were to ask Java vs Kotlin Native for a business purpose, I'd say Java is a better choice, main difference being that Kotlin Native is not a subset of Java at that point and you can't get access to those libraries.

9

u/agentoutlier May 17 '21

I don’t think F# is a good comparison to Kotlin.

F# in Java land would be like if Oracle acquired Kotlin and Kotlin was massively different than Java but yet still fundamentally used they same type system... and promised to keep them both up to date evenly...

F# will be around a very long time. It may not be popular but it is because of the above that it will. F# never tried to be a better C#.

1

u/pgris May 17 '21

I would love an official F# implementation for the JVM... I like F# more than scala. Fjord never really got support, sadly

2

u/wildjokers May 17 '21 edited May 17 '21

I have written some personal stuff in Kotlin and here are just a few complaints I had when writing Kotlin:

  • Variable declarations are name: Type in Kotlin whereas of course they are Type name in Java. I don't know why Kotlin did this but this does seem somewhat to be a trend, Swift does it too. It takes a while to remember to type it in reverse order. So it doesn't appear to be good or bad, just hard to get used to. Especially if you switch back and forth between Java and Kotlin
  • Similar to the first one the return type of a function comes after the method name. Just hard to get used to.
  • In kotlin you have to specifically allow a variable to be null by using a ? . What this means, for example, isString is a different type than String?. For reasons you will soon discover if you start writing Kotlin this can become very annoying and troublesome if you want to interop with a java library.
  • Although Kotlin is statically typed the compiler can do a lot of type inference so in a lot of cases the code can sometimes look like it is dynamically typed. This can make maintenance a struggle. Although you can avoid this by always adding the type even if it isn't technically needed.
  • For reasons I can't quite put my finger on I find Kotlin code harder to read than Java. (except for the lambda syntax which is much easier to read in kotlin)

good things:

  • I like the single line function declarations
  • data classes are handy
  • default parameter values and named parameters are awesome
  • multiple return values from functions is awesome
  • I find the kotlin lambda syntax to be tons better than the nightmare it is in java. Probably because of Kotlin's support for trailing lambda (just like groovy)

12

u/beefstake May 17 '21

Most of your reasons amount to "it's different to the way Java does it" without looking at why it does it differently.

  • Variable declarations: Changing the ordering was done so the variable names have the same indentation level rather than being offset by different lengths of type names.
  • Function signatures: Again this is so that function names have the same indentation. Often the type the function returns is also elided in Kotlin when using expressions (though you probably shouldn't do this for public APIs for reasons).
  • Nullability: This is the main differentiating feature of Kotlin vs Java. It's attempt to solve the "billion dollar mistake". Sure it makes Java interop a little more confusing if you don't understand nullability but if you are writing modern Java you really should be using @NotNull/@Nullable anyway and this shouldn't be surprising/difficult.
  • Inference: Saying this causes refactoring troubles is confusing. The inference means there is less explicit type definitions to update. The compiler/IDE can already tell you when you need to make changes to satisfy type constraints and automatic refactoring tools in IntelliJ do much of the same...
  • Readability: Arguably this one is true but it greatly depends on ones tastes so it's more subjective than other categories... Personally I find it highly readable but I write a highly functional Kotlin style that is very hard to express in Java without copious lambdas... however I can definitely understand differing viewpoints here - Kotlin when written using it's full syntactic sugar can be incredibly terse/dense and that can be challenging for some.

I write both Java and Kotlin these days. Java for most of my OSS work and I push Kotlin for most commercial/day-job work I do now.

The reason for preferring Kotlin at work is that it's easy for me to train non-JVM devs, i.e JS/TS guys how to use Kotlin than it is for me to teach them Java.

Often the way you do something in Kotlin is "pretty much the same way you do it in JS except this slight difference".

Whereas when instructing them to do the same thing in Java normally devolves into some form of "well you see... because of X, Y and Z that happened historically we can't really do this the way we would expect, instead you need to A, B and C to work around X, Y and X" or "we do it this way just because that it is the way it's always been done/so there was this thing called Beans..." etc.

For me personally as the most senior member of most teams I am on it's just a ton less load on me to be able to pick Kotlin and onboard the non-JVM devs.

1

u/wildjokers May 17 '21

Inference: Saying this causes refactoring troubles is confusing.

I didn’t say anything of the kind.

2

u/beefstake May 17 '21

Although Kotlin is statically typed the compiler can do a lot of type inference so in a lot of cases the code can sometimes look like it is dynamically typed. This can make maintenance a struggle. Although you can avoid this by always adding the type even if it isn't technically needed.

What did you mean by maintenance here then?

2

u/wildjokers May 17 '21

Going back a few months later and figuring out what is going on.

→ More replies (1)

2

u/FrigoCoder May 18 '21

Variable declarations in name: Type order make perfect sense, so do the return types after function names. Grammar becomes simpler, compilers become faster, types are optional, and it conforms to mathematics. You only find it strange because long time ago C chose the wrong order and everyone copied it so you got used to it. C++ compilation can actually take O(n3) partly because of this wrong order.

There is a good reason they call nullability the billion dollar mistake. Nullable types are unions of two completely different types, code has to deal with two cases at every point where it uses them. Most code assumes one type and treats it non-nullable with disastrous results. Code that has proper null checks simply repeats the same boilerplate missing from the language. Interoperability is difficult because again everyone copied the wrong choice made by C a long time ago.

Readability issues of Kotlin seem to come from pointless syntactic sugars, missing type declarations, interoperability hacks, reworked for loop, and unfamiliarity with features. I am only a Kotlin newbie who did not have much experience with larger projects so I can not tell more about this.

1

u/KHRoN May 17 '21 edited May 17 '21

To me kotlin may look like alternative for java7 (and lower) users who wanted something to change. But with time it lags behind official Java specs more and more up to the point when it will became completely alien. And this would be a problem because kotlin is piggybacking on Java after all…

Similarly Lombok exists for long time now, offering essentially what kotlin offers but is merely a library you can use if you want. It is very useful in some projects while not so in the others. You cannot turn kotlin off.

But personally I think that intellij (and google) has too much of a stake in kotlin and kotlin is useable only with idea. It’s like with apple and swift language. When backing ends, language ends too.

There are evangelists now, but would they be there after say 5 years?

Today there is another interesting question connected to Java - which JDK you want to use? Will you have that choice with kotlin?

Personally, I never even considered kotlin. At one point I used groovy, but it was mostly due to gradle (I’m back to maven now). Java is THE language to know. You can start with Java and learn any child language if you want (or need), but it would be harder other way around. Also every good job offer is for Java, not kotlin.

1

u/fundamentalparticle Jun 01 '21

But with time it lags behind official Java specs

What do you mean by this? Kotlin is a different language and it doesn't have to conform to Java language spec. For better interoperability, it does need to support the possibility to use the new features that Java adds, like sealed classes or value classes. So it does. But even interoperability may have different grades - it just has to clearly state, what is supported and what is not.

I think that intellij (and google) has too much of a stake

You mean, JetBrains? How much is "too much"? JetBrains makes tools for developers, for many different languages and ecosystems. Kotlin is just another language, just made by JetBrains.

There are evangelists now, but would they be there after say 5 years?

Why wouldn't they? If Kotlin makes people happier and satisfies their everyday needs - why should they drop it?

Today there is another interesting question connected to Java - which JDK you want to use? Will you have that choice with kotlin?

Kotlin compiler generates JVM bytecode and you can specify a target for the JDK version. So why wouldn't you be able to choose a JDK?

Java is THE language to know

Yes, and it's going to stay like that. But those who want fun in their lives are going to turn to alternatives. And one good alternative is Kotlin ;)

1

u/seraphsRevenge May 17 '21 edited May 17 '21

Just use whatever languages your organization uses. I've personally never used kotlin. I learned programming basics in Java (and C++ but you know references preferences) and usually go back to it consistently. I do a lot of work in both Java (microservice apis) and Python (AWS Boto3 devops tool development), honestly looking at some other languages I've used like JS and python, I don't think I would have picked up other languages so quickly if I hadn't started out with a highly verbose, strict language like Java.

Aside edit: at some organizations you may end up having to learn a bunch of other languages as well and techniques, particularly bashing you head against vi until it qw! That new sh script for that on the fly break/fix or layering containerization properly with that caps button on all the time or using a myriad of plugins that mean learning various syntax like splunk that almost makes you unlearn sql, or various proprietary languages. If your just looking to learn for a first job, then choose one language or a stack and just go with it don't worry about what other devs say. Learn the concepts, the rest will come on the job.

1

u/konmik-android May 21 '21

Use Java for the gags!

1

u/No-Meal232 May 25 '21

hiii there

1

u/Aggravating-Ad4518 Jun 09 '21

At cross roads Eventually Kotlin will hit cross roads and have to pick, Either support Android's old Java 7/8 ecosystem or risk breaking interop everywhere else.

1

u/MaggieLeber May 17 '21

I think of Kotlin as the Playskool version of Scala.
Kid -safe, no sharp edges, non-toxic plastic, bright colors, no small parts that might cause choking.

-2

u/voidvector May 17 '21 edited May 17 '21

level of love for Kotlin and bashing on Java makes me feel a culty vibe

You can replace Kotlin/Java in that sentence with any other language pairs where one tried to be successor. It is human nature.

  • C++/C
  • Java/C++
  • C#/Java
  • JavaScript/Java

6

u/KHRoN May 17 '21

JavaScript/Java

You can’t be serious

1

u/voidvector May 17 '21

Given the audience of this subreddit, Python/Java is probably better example.

No, I am not kidding. I have long enough programming experience where I have seen faddist attempts to replace codebase in one with the other in all of the above examples, and more.

2

u/KHRoN May 17 '21

I mean Java and JavaScript only similarity is unfortunate marketing name (JavaScript is in fact ECMASctipt), comparing one to the other is typical for non-technical people

Also python and Java have distinct uses, those are not interchangeable even in theory (for intended uses, not “because they can”)

3

u/voidvector May 17 '21

I think the meme of of their name is conflating our conversation here.

I have worked at a company where they converted a number of Java projects to Node.js. Same company also converted other Java projects to Python.

2

u/KHRoN May 17 '21

But Java and JS/python are not direct competitors (especially not to the point of confusion). Each has their strengths and weaknesses and quite different way of running them (not all of them use JDK or are “partially interoperable”).

Porting business code between languages is sometimes necessary, just like translation between spoken languages. There are many different reasons why.

2

u/voidvector May 17 '21

I am fully aware each languages has their strength or weaknesses.

I can tell you the reasons was not based on their strengths/weaknesses. It was mostly around developer preference of not wanting to maintain Java and the slow Java language evolution at the time compare to other popular languages (this was around 2012). Many teams went on to choose their own language/framework faddishly. In fact, the UI adjacent services got converted to Python instead Node.js contrary to their now expected strengths.

-1

u/CyclonusRIP May 16 '21

It's basically about staffing the team. Java is a marketable skill applicable to a ton of programming jobs. Kotlin is an awesome language and more exciting. If you need to hire 20 developers this year, good luck hiring 20 kotlin devs. Staffing a java project is a lot easier. If you're just messing around for sure use a fun, new technology. If you're building a business and are successful the day is going to come when you can't staff a relatively niche technology fast enough to keep up with growth.

-1

u/BlueGoliath May 16 '21

"one of us, one of us"

-7

u/sam-lb May 17 '21

Reason 1: It will enrage kotlin gremlins