News for hackers. Stuff that matters.
Re:Java is not a safe language by Traubenfuchs on Monday June 13, 2022 @06:45AM (#31723563)
Nothing but dirty FUD by someone whose Java skills are at best Junior level.

Why is this on the front page?

> Java does not trap overflows

Fair enough but only relevant for specific problems/domains. Never encountered this in 10 years.

> Java allows data races

It does not, if you use its dead simple std lib concurrency collections. Also it brings all the concurrency primitives you'd ever ask for (mutex, semaphore, synchronized and god knows what) and guaranteed latest-read "volatile" keyword if you really want to go there. Which you shouldn't. Use AtomicReference, AtomicInteger, ConcurrentHashmap, etc. If you struggle with data races in Java, you are at best a Java junior programmer and should study it instead of writing FUD.

> Java lacks null safety

I like null. Matter of personal opinion. If you are an anti null fetishist, go with Optional. If you want to go even further, use validated @NonNull annotations.

> Java lacks named arguments

Personal opinion. Syntactic sugar I never missed. IntelliJ and VS Code offer inlay hints to overcame this if it really helps. May I also offer you some rainbow colored braces for dessert?

Re:Java is not a safe language by kasperni on Monday June 13, 2022 @07:01AM (#31723688)
> Nothing but dirty FUD by someone whose Java skills are at best Junior level.

Lamire (the author of the blog post) is well know as the author of https://github.com/RoaringBitmap/RoaringBitmap which is in widespread use.

Re:Java is not a safe language by kjeetgill on Monday June 13, 2022 @07:14AM (#31723796)
I love Lamire's blog posts and think he's brilliant, but I'd have to agree with the GP (though more gently) that this really does read like a list of "Things to Watch out for: My First 6 month of Java".

I suspect that weirdness has less to do with Lamire, but the weird expectations that it tries to "debunk".

Like no ones out here arguing that Java is some especially safe, super high validation language. Sure it's memory safety was a huge breath of fresh air compared to C/C++, but it's not in the same vein of reputation as an Eiffel or Ada or even Rust.

Re:Java is not a safe language by anuraaga on Monday June 13, 2022 @09:34AM (#31725340)
Perhaps the intent was seeing what crazy HN thread would be started :) My reading of the last paragraph was that there is no safe language since in the end it's always up to the programmer.
Re:Java is not a safe language by kaba0 on Monday June 13, 2022 @05:40PM (#31732135)
Well, I did have to debug a Rust program with valgrind/miri so it is not like safety is a singular axis (not shitting on Rust, I really like the language, but it is a low level language exposing low-level constructs thus low-level bugs can rear their ugly heads)
Re:Java is not a safe language by eternityforest on Monday June 13, 2022 @07:19AM (#31723846)
A safe language isn't a language that lets you do things safely, it's a language that will not let you do them unsafely, or will at least make it hard to do so.

The moment you allow things that don't work well with the prover, people will use them, and the whole ecosystem becomes unsafe. And by extension, your code becomes unsafe, if the compiler can't reason about what happens when your code calls theirs.

Plus, unless you have just the right linter set up, you can still accidentally mess up and do something unsafe if the compiler lets you.

Re:Java is not a safe language by lenkite on Monday June 13, 2022 @08:25AM (#31724496)
When we call a language “safe”, that formally means that there’s a proof that no well-formed program in the language can do something undefined.

Java is completely safe by that definition. Now, you can have the seat-belt even tighter than that for various types of <domain> safe, but we are moving the goal-posts of the definition.

Re:Java is not a safe language by Akronymus on Monday June 13, 2022 @10:25AM (#31726079)
>...or will at least make it hard to do so.

Also known as the pits of success.

Re:Java is not a safe language by ImprobableTruth on Monday June 13, 2022 @07:51AM (#31724121)
Null pointer exceptions by far the most frequent exception I encounter. Not only on the development side, but also as a user.

Optional is convention based and @NonNull just throws the runtime exception at a better location, so in my experience neither come remotely close to providing null safety.

Re:Java is not a safe language by kaba0 on Monday June 13, 2022 @05:46PM (#31732207)
@NonNull and similar annotations can and are used by static analyzer programs to completely eliminate null exceptions. For example Checker Framework can do that and much more.

This is the exact same thing that languages with null-safety have “in-built”. Sure, language support is nice, but it is here and is working

Re:Java is not a safe language by timeon on Monday June 13, 2022 @08:03AM (#31724243)
>> Java allows data races

> It does not, ... If you struggle with data races in Java

How can one struggle with data races if it does not allow it.

Re:Java is not a safe language by BeefWellington on Monday June 13, 2022 @10:41AM (#31726307)
A lot of "I know better than standard library authors" custom code to do things that already exist elsewhere, basically.

I've seen what GP was referring to in practice.