News for hackers. Stuff that matters.
Re:Ask HN: What are some of the most elegant codebases in yo... by stickfigure on Saturday June 17, 2023 @06:35PM (#36375401)
While I think there's a lot to love about Java, I think the standard library itself is not an especially great role model. Most of it was written a long time ago and has a fairly antiquated style - lots of mutable state, nullability, and checked exceptions. Not that the library isn't an incredible asset - it's luxuriously rich compared to working in Node.js - but if it were written from scratch today, I suspect it would look fairly different. Eg, the collection classes would use Optional and have separate read/write interfaces.

For an example of "modern Java" I would point at something like this (which I wrote, sorry about the hubris):

https://github.com/stickfigure/hattery

Re:Ask HN: What are some of the most elegant codebases in yo... by NBJack on Saturday June 17, 2023 @08:37PM (#36376196)
As much of a fan as I am of Java, I have to agree. There are some real bombshells in the library that can either make your coding life or debugging a prod service miserable (sometimes both). Other additions are great, but have hurt readability a bit (i.e. Java lambdas).

Checked exceptions get a bad rep, but I've frequently found taking advantage of their hierarchical nature can be beneficial to at least making them less bad to catch. When I work with languages that have no exception support at all, I sometimes even miss them.

Re:Ask HN: What are some of the most elegant codebases in yo... by flashgordon on Monday June 19, 2023 @04:29AM (#36388643)
As much as "not" a big fan of java, I need to give credit where it is due.. as my (almost) first language almost 25 years ago I learnt heaps by going through the source code. Sure there were bad and (what are now) outdated conventions etc. But as a junior eng learning how layouts worked, how data structures were implemented, how network code was written and tons more, the Java src folder was a huge treasure mine. Did I mention swing?
Re:Ask HN: What are some of the most elegant codebases in yo... by kaba0 on Sunday June 18, 2023 @04:55AM (#36378464)
From your repo: Respectfully, I disagree that checked exceptions are a misfeature. Java’s implementation definitely leaves a lot to be desired (inheritance doesn’t make sense for them), but otherwise checked exceptions are a better form of Result types.
Re:Ask HN: What are some of the most elegant codebases in yo... by The_Colonel on Sunday June 18, 2023 @05:09AM (#36378536)
Unchecked exceptions are the better version of Result type.

The problem with checked exceptions is that methods throwing them force its callers to react to the even if they are irrelevant to them. In 99% of cases I don't have any JSON specific error handling, yet Jackson forces me to do a try-catch-rethrow ceremony in thpse 99% to declare I don't want to do anything specific.

Re:Ask HN: What are some of the most elegant codebases in yo... by kaba0 on Sunday June 18, 2023 @05:35AM (#36378657)
That’s the not too comfortable part. But with a tiny bit of syntax sugar (say, a ! or ? that expands to a mini-try-catch block) it would be more than fine.
Re:Ask HN: What are some of the most elegant codebases in yo... by The_Colonel on Monday June 19, 2023 @03:04AM (#36388138)
Yes, I would be fine with a shorthand syntax like that. But it's not available which makes checked exceptions more trouble than worth.
Re:Ask HN: What are some of the most elegant codebases in yo... by pragmatick on Sunday June 18, 2023 @06:32AM (#36378946)
I only looked over your code for a minute but found some stuff I would comment on in a code review.

Comment for a method says "null safe" - why not use an annotation?

A package called "util" is a code smell for me.

UrlUtils only provides two methods for URL encoding so why not name it appropriately?

Re:Ask HN: What are some of the most elegant codebases in yo... by Tokumei-no-hito on Sunday June 18, 2023 @10:55AM (#36380841)
I’ve always heard about the “util” package code smell but usually in complex contexts that are hard to discuss.

How would you refactor this to avoid a util package or a UrlUtils class?