Most active commenters
  • breadwinner(10)

←back to thread

253 points chhum | 24 comments | | HN request time: 0.001s | source | bottom
Show context
nelup20 ◴[] No.44009800[source]
I personally appreciate Java (and the JVM) much more after having tried other languages/ecosystems that people kept saying were so much better than Java. Instead, I just felt like it was a "the grass is greener" every time. The only other language that I felt was an actual massive improvement is Rust (which so far has been a joy to work with).

It's a shame imo that it's not seen as a "cool" option for startups, because at this point, the productivity gap compared to other languages is small, if nonexistent.

replies(6): >>44009912 #>>44009928 #>>44009952 #>>44010109 #>>44010282 #>>44010468 #
kllrnohj ◴[] No.44010282[source]
Personally I think C# is miles ahead of Java and in meaningful ways (like a drastically better implementation of generics, not to mention value types have existed for eons at this point and an FFI system that doesn't hate you for using it)

But nobody seems to talk about or care about C# except for Unity. Microsoft really missed the boat on getting mindshare for it back in the day.

replies(12): >>44010302 #>>44010329 #>>44010450 #>>44010481 #>>44010493 #>>44010636 #>>44010692 #>>44010825 #>>44010902 #>>44011079 #>>44011124 #>>44012556 #
1. breadwinner ◴[] No.44010692{3}[source]
One area where C# really messed up is exception handling.

See https://mckoder.medium.com/the-achilles-heel-of-c-why-its-ex...

replies(4): >>44010987 #>>44011072 #>>44011368 #>>44011745 #
2. easton ◴[] No.44010987[source]
They intentionally chose to not have checked exceptions though, and people have different opinions on it. They believed that people would just catch Exception most of the time anyway instead of selecting on a very specific type (which is often how it works, in web apps anyway.)

https://www.artima.com/articles/the-trouble-with-checked-exc...

replies(1): >>44011111 #
3. neonsunset ◴[] No.44011072[source]
IIRC all previous conversations about checked exceptions here ended up with the swift conclusion that they are heavily discouraged throughout Java code.
replies(1): >>44011113 #
4. breadwinner ◴[] No.44011111[source]
> They believed that people would just catch Exception most of the time anyway

Their belief was wrong. Microsoft now recommends against catching Exception.

The article you linked to is addressed at the bottom of this article: https://mckoder.medium.com/the-achilles-heel-of-c-why-its-ex...

5. breadwinner ◴[] No.44011113[source]
> they are heavily discouraged throughout Java code

That's so ignorant. Read the article please.

replies(1): >>44011181 #
6. neonsunset ◴[] No.44011181{3}[source]
Let's revisit past conversations:

- https://news.ycombinator.com/item?id=43226624

- https://news.ycombinator.com/item?id=43584056

- https://news.ycombinator.com/item?id=36736326

And more. I'm not sure what you found in (checked) exceptions. If you'd like explicit error handling, we have holy grail in the form of Rust which beautifully solves it with implicit returns, error type conversions and disambiguation between error and panic model. I'd prefer to use that one as it actually reduces boilerplate and improves correctness, the opposite to the outcome of using checked exceptions.

replies(2): >>44011309 #>>44011760 #
7. breadwinner ◴[] No.44011309{4}[source]
> I'm not sure what you found in (checked) exceptions.

I could copy/paste the entire article here... but it would be easier if you could take a gander: https://mckoder.medium.com/the-achilles-heel-of-c-why-its-ex...

Summary:

Crashy code: You have no compiler-enforced way to know what exceptions might be thrown from a method or library.

More crashy code: If a method starts throwing a new exception, you might not realize you need to update your error handling.

Dead code: If a method stops throwing an exception, old catch blocks may linger, becoming dead code.

replies(2): >>44012858 #>>44013364 #
8. jayd16 ◴[] No.44011368[source]
Java streams and a lot of other APIs are extremely ugly because of checked exceptions. Conversely, LINQ and delegates and a lot of other syntax is far cleaner in C#.

Your linked blog is pretty wild. Only throw RuntimeExceptions to crash? Why not just Exit if that's the proper thing to do?

If you treat all C# exceptions as RuntimeExceptions, then it satisfies the blog anyhow.

replies(3): >>44011399 #>>44011441 #>>44015573 #
9. breadwinner ◴[] No.44011399[source]
> Why not just Exit if that's the proper thing to do?

Because you won't get a stack trace.

10. vips7L ◴[] No.44011441[source]
Checked exceptions could still work across lambdas. Scala is doing research there: https://docs.scala-lang.org/scala3/reference/experimental/ca...
replies(1): >>44020234 #
11. bigstrat2003 ◴[] No.44011745[source]
I don't know that I'd say "messed up", but I do wish C# had checked exceptions. I strongly believe that they are superior to non-checked exceptions, basically static type signatures but for error handling. It's a real pity that everything after Java seems to have abandoned the idea.
replies(1): >>44014344 #
12. bigstrat2003 ◴[] No.44011760{4}[source]
> I'd prefer to use that one as it actually reduces boilerplate and improves correctness, the opposite to the outcome of using checked exceptions.

Reducing boilerplate is not a valuable goal in and of itself. The question is, does the boilerplate buy you something? I think that with checked exceptions it does. Having an explicit type signature for what errors a function can raise improves correctness a great deal because the compiler can enforce the contracts of those functions.

I agree that the Rust approach is good too, though I don't agree it has any strong advantages over the way Java does things. Both approaches are equally respectable in my view.

13. Kwpolska ◴[] No.44012858{5}[source]
None of those arguments are convincing. In many cases, you can't handle errors more reasonably than just crashing or telling the user something went wrong. Java has RuntimeExceptions, which do not have to be declared in the function signature. Division by zero, or trying to index an array out of bounds, and the dreaded NullPointerException, are some examples of RuntimeExceptions.
replies(1): >>44014105 #
14. mrkeen ◴[] No.44013364{5}[source]
> You have no compiler-enforced way to know what exceptions might be thrown from a method or library.

Always assume exceptions will be thrown from a method or library.

replies(1): >>44014097 #
15. breadwinner ◴[] No.44014097{6}[source]
Which ones? That's the issue.
16. breadwinner ◴[] No.44014105{6}[source]
What about the ones you can recover from? You don't want to crash the entire application every time there's an exception!
replies(1): >>44015271 #
17. kllrnohj ◴[] No.44014344[source]
Java itself has basically abandoned the idea, or at least the ecosystem at large has. Checked exceptions are a decent idea but Java's implementation sucks. It needs to be a lot more automatic or something
replies(1): >>44015507 #
18. Kwpolska ◴[] No.44015271{7}[source]
You usually wouldn’t crash the entire application, the request that causes the issue will return a 500 error. (Or equivalents for non-web environments.)
replies(1): >>44016587 #
19. breadwinner ◴[] No.44015507{3}[source]
> Java itself has basically abandoned the idea

Some Java developers may have, due mostly to misinformation from the .NET camp.

20. breadwinner ◴[] No.44015573[source]
Side effects are not allowed in functional style programming. Exceptions are side effects, it doesn't matter whether they are checked or unchecked exceptions.

https://jessewarden.com/2021/07/why-functional-programmers-a...

While composing methods in stream style is convenient, methods that can throw exceptions warrant more careful coding, so convenience should not always be the priority.

replies(1): >>44020229 #
21. breadwinner ◴[] No.44016587{8}[source]
Some exceptions are not recoverable and may cause 500 error. Others such as FileNotFound are recoverable, for example by reading the file from an alternate location.
22. int_19h ◴[] No.44020229{3}[source]
Exceptions are not side effects since no state mutation occurs.

If you really want to see everything through the FP lens, exceptions are exactly like Result<T, E> with implicit do-notation.

23. int_19h ◴[] No.44020234{3}[source]
One of the original lambda proposals for Java - the one from Neal Gafter - also had checked exceptions.

The problem is that you then need a way to capture exception specifications as generic type parameters to properly propagate contracts, which complicates the type system quite a bit. Which is why Java ultimately went with the much simpler proposal that didn't even try to tackle this.

replies(1): >>44043517 #
24. vips7L ◴[] No.44043517{4}[source]
Yes I'm well aware, but that is uniquely a Java problem. With a sufficiently strong type system, like the one in Scala, you can easily make checked exceptions work across higher order functions.