Live data from Hacker News

Rating 26 years of Java changes

neilmadden.blog

311–320 of 327 posts

Re: Rating 26 years of Java changes

#311

Earlier quoted context omitted.

OpenJDK redesigns massive swaths of the compiler every other month. The true explanation, at least the way OpenJDK says it, is that designing language features is more complex than a casual glancer can fathom, and there's 30 years of "Java is in the top 5 most used languages on the planet, probably #1 especially if focussing on stuff that was meant to be supported for a long time" to think about. From personal experi…

But ... LocalDate predated records by 6 years? Eventually, I guess there'll be backwards compatible "pattern extractors" functionality retrofittable to existing "record-like" classes. This has been hinted at on several occasions.

> But ... LocalDate predated records by 6 years?

Yes, exactly - now you're getting it. Or rather I get the feeling I failed to explain it well.

ArrayList predates generics.

However, ArrayList does have generics.

That's because generics were added to the language in a 'culturally backwards compatible' way: Existing libraries (i.e. libraries that predate the introduction of generics, such as ArrayList) could modify themselves to add support for generics in a way that is backwards compatible for the library: Code written before they added it continues to work and compile fine even against the new release that added generics.

The same principle applied to records would mean that LocalDate could have been updated to turn into a record in a way that is backwards compatible.

And it really works that way.. almost. You really can take an existing class (defined with `class`) and change it into a record (defined with `record`) and all existing code continues to work just fine. However, this means all your properties now neccessarily get an accessor function that is named after the property. And that is a problem for LocalDate specifically: It already has accessors and they are named e.g. `getYear()`. Not `year()`. That means if LocalDate were to be rewritten as a record, one of two very nasty options must be chosen:

* Break backwards compatibility: As part of upgrading code you must change all calls to `.getYear()` into calls to `.year()`. It's a total ecosystem split: Every dependency you use comes in 2 flavours, one with calls to getYear and one with year, and you must use the right ones. This is truly catastrophic.

* Have both methods. There's year() and also getYear() and they do the same thing. Which is the lesser evil by far, but it makes very clear that LocalDate predates `record`. Contrast to ArrayList: It is not all that obvious that ArrayList predates generics. It does, but if you were to design ArrayList from scratch after generics are introduced you'd probably make the same code. Maybe the signature of `remove` would have been `remove(T)` instead of the current `remove(Object)`.

Instead, obviously then, the best choice is to not make it a record. And that's my point: The best possible (possibly here perfection is the enemy of good, but, I'd have done it differently) way to deploy records would have included some way for localdate to turn into a record without the above dilemma.

Perhaps simply a way to explicitly write your accessors with some marker to indicate 'dont generate the default `year()` - THIS is the accessor for it'.

Had that feature been part of record, then LocalDate could have turned into one in a way that you can't really tell.

Re: Rating 26 years of Java changes

#312

Earlier quoted context omitted.

Spring Boot’s support for async jobs and scheduled jobs is lacking. Can you elaborate? What exactly is lacking and what version of Spring are you using?!

Compare with the functionality offered by async job systems of other full stack frameworks - eg django with celery and rails with solid-queue. It’s not even close. I am on the latest version of Spring Boot.

I am not saying there aren't more robust scheduling libraries, people still use Quartz a lot in the Java ecosystem - was just wondering what specifically are you up against that you cannot solve with Spring's scheduling?

Re: Rating 26 years of Java changes

#313

Earlier quoted context omitted.

Yes, but at what cost? Many libraries can solve visibility problem with package level visibility. And modules cost a lot: dependency management was a non-goal for them, so anyone who wants to use module path instead of classpath, has to declare dependencies twice. It was a big mistake not to integrate modules with a de facto standard of Maven.

> Many libraries can solve visibility problem with package level visibility The only way of doing this would be to put all classes in the same package. Any nontrivial library would have hundreds of classes. How is that a practical solution?

Well designed non-trivial libraries should be open for extension and thus should not hide most of the implementation details, leaving the risk of too tight coupling to users. E.g. if I‘m not 100% satisfied with some feature of a library, I should be able to create a slightly modified copy of implementation of some class, reusing all internal utilities, without forking it. So no, modules as means to reduce visibility are not as cool as you think. And given the specific example of the list, it’s possible to filter out irrelevant suggestions for auto-complete or auto-import in IDE settings.

Re: Rating 26 years of Java changes

#314

Earlier quoted context omitted.

> Many libraries can solve visibility problem with package level visibility The only way of doing this would be to put all classes in the same package. Any nontrivial library would have hundreds of classes. How is that a practical solution?

Well designed non-trivial libraries should be open for extension and thus should not hide most of the implementation details, leaving the risk of too tight coupling to users. E.g. if I‘m not 100% satisfied with some feature of a library, I should be able to create a slightly modified copy of implementation of some class, reusing all internal utilities, without forking it. So no, modules as means to reduce visibility…

So goalpost moved from “libraries can solve visibility problem with package level visibility” to “libraries should not try to solve the visibility problem because it is not even a problem at all”?

Re: Rating 26 years of Java changes

#315
I use Java time a lot and yes it has to be that complex. One of my favourite examples is Duration vs Period. They are just not the same once you factor in timezones. And I like that they make it difficult for you to mess that up, although I'm sure there is a way.

Re: Rating 26 years of Java changes

#316

Earlier quoted context omitted.

Well designed non-trivial libraries should be open for extension and thus should not hide most of the implementation details, leaving the risk of too tight coupling to users. E.g. if I‘m not 100% satisfied with some feature of a library, I should be able to create a slightly modified copy of implementation of some class, reusing all internal utilities, without forking it. So no, modules as means to reduce visibility…

So goalpost moved from “libraries can solve visibility problem with package level visibility” to “libraries should not try to solve the visibility problem because it is not even a problem at all”?

No, it has not. If you are software engineer you should understand the difference between what I actually said and what you quote from logical perspective. I said "many libraries", not "all". For majority of use cases package level visibility is sufficient and is more granular. Yes, many libraries have already migrated and include module-info, but they still are fully compatible with classpath and actively use more classic mechanisms for visibility control. How many projects do use modules? I haven't seen a single one yet.

Re: Rating 26 years of Java changes

#317
post #9

Earlier quoted context omitted.

I used to joke that the direction spring was heading was that you’d have an application be a boilerplate main method with a dozen lines of annotations. Then I actually encountered this in the wild: we had an app that sent updates from db2 to rabbitmq, and the application literally was just configuration via annotations and no actual Java code other than the usual spring main method.

this is exactly why spring succeeded. I need to run a scheduled job, @EnableScheduling then @Scheduled(cron = “xxxxxx”) - done. I need XYZ, @EnableXYZ the @XYZ… sh*t just works…

why does this sound like systemd?

Re: Rating 26 years of Java changes

#318
post #147

Fully agree with most votings but 3/10 text blocks?! That has got to be one of the most useful recent features. :-) The pleasure of just copying and paste text in plain ASCII that looks as intended rather than a huge encoded mess of "\r\n"+ concatenations. But ok, I'm just an ASCII art fan. ^_^

String sql = “Not having “ + “to break up “ + “SQL statements” + “like this for readability “ + “thus making them hard to edit “ + “was incredibly useful at my job.”; (Note: I put a subtle bug in there because it always happened) SQL injection is horrible, but people were managing to do that all these years after prepared statements anyway without text blocks. I really don’t think they made things worse. Same thing w…

> Note: I put a subtle bug in there because it always happened

No space between "statements" and "like"?

Re: Rating 26 years of Java changes

#319

> if you wanted to store an integer in a collection, you had to manually convert to and from the primitive int type and the Integer “boxed” class I have never worked with Java. What is this? Why would one want to have a class for an Integer?

Primitive variables in Java, such as `int`, `boolean`, and `double`, store their actual values directly in memory. When they are local variables inside a method, this memory is typically allocated on the thread's stack. These primitives do not have the structure or overhead of an object, including the object header used by the Garbage Collector (GC) to manage heap-allocated objects. If a primitive value must be treat…

Can you have a collection of primitives?

Re: Rating 26 years of Java changes

#320

Earlier quoted context omitted.

Primitive variables in Java, such as `int`, `boolean`, and `double`, store their actual values directly in memory. When they are local variables inside a method, this memory is typically allocated on the thread's stack. These primitives do not have the structure or overhead of an object, including the object header used by the Garbage Collector (GC) to manage heap-allocated objects. If a primitive value must be treat…

Can you have a collection of primitives?

No, but yes. There is nothing in the standard library, that implements the Collection-interface and works with primitives. However you can write your own and there are several implementations of collections for primitives. The problem is that you have to implement them seperately for each type of primitive (e.g. an IntList, DoubleList, BooleanList...).
Post reply on HN