r/java • • Jun 10 '24

[deleted by user]

[removed]

613 Upvotes

594 comments sorted by

View all comments

Show parent comment

32

u/HaMMeReD Jun 10 '24

Well, that's a bit of a gross oversimplification don't you think.

Like what if you want Null Safety? What if you don't like semicolons? Robust type inference?

31

u/drinkcoffeeandcode Jun 10 '24

Everything except the semicolons, and to that I say “grow up”

18

u/pwnasaurus11 Jun 11 '24 edited Apr 30 '25

ring quicksand tap desert paint pie handle head normal workable

This post was mass deleted and anonymized with Redact

6

u/thecodeboost Jun 11 '24

I was on board of that train as an early Kotlin adopter but although I'm still a Kotlin fan I actually think that particular argument doesn't hold much water. Writing Java code in Kotlin's style is exactly as null safe as native Kotlin code is. The only nuance is a compiler error versus a static analysis error. And because Kotlin insists on being null safe you have to start working around it every time you work with null-first libraries (which is pretty much most of time in the real world). Your mileage may vary of course but I find myself writing idiomatic J21 code way more and Kotlin way less as the two converge.

1

u/pwnasaurus11 Jun 11 '24 edited Apr 30 '25

gaze familiar chop support fade chubby noxious memory six psychotic

This post was mass deleted and anonymized with Redact

2

u/714daniel Jun 11 '24

@NonNull

→ More replies (1)
→ More replies (2)
→ More replies (11)

4

u/leemic Jun 10 '24

Lambda with Receiver. I miss this in Java. I can quickly write my custom DSL.

1

u/thecodeboost Jun 11 '24

Interesting, I find receiver lambdas incredibly anti-idiomatic. The whole point of a lambda is to be functional in nature and a receiver allows it to operate on the this instance. And all you're getting for it is slightly more concise code that's harder to parse visually. What are you getting out of it exactly?

2

u/leemic Jun 11 '24

I do not think Kotlin is a pure functional language. We overlay the object-oriented with streaming + functions. In the OO paradigm, this is an implicit input parameter with additional permission, etc. Lamda with the receiver is a dynamic runtime extension function. They could have used a better name that was not confused with the functional paradigm.

As for the use case, I created a cucumber-like testing framework with a single abstract class. I handed it off to a test engineer as an automated test tool. The specific use case is an electronic trading engine where it receives an order and sends out multiple orders to exchanges. I orchestrated various clients and numerous exchanges, which only took a few days. The engineer can easily extend it because it is code/Kotlin.

1

u/thecodeboost Jun 21 '24

I don't either. I just think receiver lambdas hurt code quality (you can make a close to objective argument for it since it's literally a semi-documented side effect). To each their own of course.

1

u/HaMMeReD Jun 10 '24

NVM I do Android, and we are always behind on Java features, and officially the recommendation is Kotlin.

1

u/SenorSeniorDevSr Jun 12 '24

Didn't Google and Oracle have a massive year-long lawsuit about how Android isn't using Java, but something that just so happened to look like it? :p

1

u/[deleted] Nov 15 '24 edited Nov 15 '24
  1. Semicolons? Grow the fuck up
  2. Robust type inference? Syntax sugar. Not needed.

The only real one is null safety, but is not enough to bring the world to move to Kotlin.

Everyone is abandoning Kotlin and Scala and returning to Java 17 - 21. As they should. Java will kill them on the long run.

Java killing the Java killers is such a sweet irony.

0

u/SkryxBob Jun 11 '24

The wrapper type Optional from java8 solves null problems if used correctly

5

u/marvk Jun 11 '24 edited Jun 11 '24

No, it's not at all a good replacement for non-nullable types.

1

u/SkryxBob Jun 12 '24

Its a replacement of setting missing values to null no? Why is it not a good replacement of handling null values? I use it as a contract to indicate a return type may be missing

3

u/marvk Jun 12 '24
Optional<Foo> myFoo = null; // ¯_(ツ)_/¯

Yes, it's a contract for return types. That's about it. If used liberally, for example for parameters, it pollutes the api, and it still doesn't stop you from passing null to functions. It's simply insufficient. I'd encourage you to take a look at Kotlin null safety. You will quickly see how Optional is inferior.

-1

u/pragmasoft Jun 10 '24

What if you don't want kotlin runtime in every dependency you use? 

What if you use in your work programming editor, which cannot use kotlin language server, because there isn't one?

10

u/HaMMeReD Jun 10 '24

I'm not trying to start a Kotlin vs Java war, I'm just stating that "Java 17+ has everything you need" is a gross oversimplification.

Both languages have their own advantages/disadvantages.

-3

u/JDeagle5 Jun 10 '24

Null safety is provided by annotations + intellij. Kotlin null safety actually eats up a considerable portion of cpu in runtime.

6

u/vytah Jun 10 '24

That's a trade-off both ways.

Annotations are really, really annoying to use.

0

u/JDeagle5 Jun 11 '24

I wouldn't say it is more annoying than question marks.

5

u/marvk Jun 11 '24

Kotlin null safety actually eats up a considerable portion of cpu in runtime.

No. Just no.

[...] At runtime, objects of nullable types and objects of non-nullable types are treated the same: A nullable type isn't a wrapper for a non-nullable type. All checks are performed at compile time. That means there's almost no runtime overhead for working with nullable types in Kotlin.

Note: We say "almost" because, even though intrinsic checks are generated, their overhead is minimal.

- https://kotlinlang.org/docs/java-to-kotlin-nullability-guide.html#support-for-nullable-types

→ More replies (1)