Live data from Hacker News

JEP draft: Prepare to make final mean final

openjdk.org

111–120 of 143 posts

Re: JEP draft: Prepare to make final mean final

#111
post #93

Earlier quoted context omitted.

Why the Lombok hate? It's just an innocent preprocessor allowing a bit of syntactic sugar right?

It’s not an innocent preprocessor. It’s a hack which breaks on almost every JDK upgrade.

Now, given that a looot of projects use Lombok, it might be worth a try to actually standardize (or at least upstream) the feature given there seems to be an obvious demand of people to not having to pollute their codebase with tons of pointless getter and setter boilerplate.

Re: JEP draft: Prepare to make final mean final

#112
post #93

Earlier quoted context omitted.

It’s not an innocent preprocessor. It’s a hack which breaks on almost every JDK upgrade.

Now, given that a looot of projects use Lombok, it might be worth a try to actually standardize (or at least upstream) the feature given there seems to be an obvious demand of people to not having to pollute their codebase with tons of pointless getter and setter boilerplate.

AutoValue, Immutables, MapStruct. All libraries that do what Lombok does without using JVM internals.

Records also literally do a huge portion of what Lombok does.

There are a lot of fairly popular alternatives to Lombok out there that don't need a constant eye on maintenance. Lombok is probably the most popular but that's really mostly because it's got the first mover advantage.

Re: JEP draft: Prepare to make final mean final

#113
post #107

Earlier quoted context omitted.

>add them to hashCode and equals (or worse, hashCode OR equals) That's a fundamental misunderstanding of hashCode, and lombok makes no exception. Not all fields need to be used to calculate hashCode, it makes the overall performance worse in most cases. Equals is of course different, however if you have an identity (i.e. database primary key), only the identity should be used.

Hurray! I thought I was the only one that understood this. There are two of us! I've seen so many performance issues with hashcode because devs will put all fields into it. Even though there's an id column or even fields that imply other fields. Hashing 1000 char strings when there's a UUID or int field that guarantees identity is silly. I think it's because devs have an preference for symmetry. I see the same thing…

>There are two of us!

Realistically, I have trained quite a few folks on my own.

>I think it's because devs have an preference for symmetry.

Another option is that's the default for all IDEs auto gen, so few clicks/taps and it's done.

Re: JEP draft: Prepare to make final mean final

#114
post #90

Earlier quoted context omitted.

I don't even agree with their demo video. It shows the "hard" way of autogenerating settings/getters, toString, hash, etc. The end result was like an additional ~80 boilerplate lines. I have no problem keeping those lines around.. opposed to adding the lombak.jar and changing my build config. I do understand the user perspective of it "just working" and of course the getters/setters will grow as you add fields... it…

It's not 80 lines. It's many thousands of lines in any real project. Lines that you should keep synchronised with "source of truth". People love Lombok for a reason. And most developers don't really care about implementation details, they believe that Lombok is "big enough" to work in the foreseeable future. It worked for them for years, it's supported well in Idea. I, personally, avoid Lombok, specifically because I…

>It's many thousands of lines in any real project.

I dont use lombok and the latter has been actively removed. If you have access to records, lombok is just bad. Even if you dont have - public final fields are sufficient in most case + c-tor and validation there. Just dont use getters & setters.

Re: JEP draft: Prepare to make final mean final

#115
post #113

Earlier quoted context omitted.

Hurray! I thought I was the only one that understood this. There are two of us! I've seen so many performance issues with hashcode because devs will put all fields into it. Even though there's an id column or even fields that imply other fields. Hashing 1000 char strings when there's a UUID or int field that guarantees identity is silly. I think it's because devs have an preference for symmetry. I see the same thing…

>There are two of us! Realistically, I have trained quite a few folks on my own. >I think it's because devs have an preference for symmetry. Another option is that's the default for all IDEs auto gen, so few clicks/taps and it's done.

In Idea you have to explicitly select the fields which should be included. So it’s always choice of a developer to misuse it.

My favorite question on interviews is explaining all methods of class Object, including the contract and best practices for equals/hashCode. Failure to answer this question automatically disqualifies applicants to mid-level and senior positions.

Re: JEP draft: Prepare to make final mean final

#116
post #113

Earlier quoted context omitted.

>There are two of us! Realistically, I have trained quite a few folks on my own. >I think it's because devs have an preference for symmetry. Another option is that's the default for all IDEs auto gen, so few clicks/taps and it's done.

In Idea you have to explicitly select the fields which should be included. So it’s always choice of a developer to misuse it. My favorite question on interviews is explaining all methods of class Object, including the contract and best practices for equals/hashCode. Failure to answer this question automatically disqualifies applicants to mid-level and senior positions.

>all methods of class Object

  finalize() is actually is a very hard mode; I'd not expect any extra senior to be able to explain it properly (incl. the semantics of JMM, the fact half created objects can be finalized; the resurrection ability). Deprecated now, so perhaps no need?
  wait/notify/notifyAll - easier, still require some practice, also not that useful any longer; but still I'd expect to know not to use a naked notify and how to properly use a loop around wait
  clone() - it'd be a hard nut for many, and I have seen more than enough implementations that straight out use new XXX(); not very difficult but not intuitive
  hashCode/equals -> hashCode being by default a random number generator is sort of cool; yes they are the backbone of all collection framework; also the value of the not overridden hashCode() is available through System.identifyHashCode()
  getClass() - if included anonymous classes, it might puzzle some
  toString() - finally something easy


---

flip note: the standard templates for intellij could use some work when it comes to the quality of hashCode;

Re: JEP draft: Prepare to make final mean final

#117
post #116

Earlier quoted context omitted.

In Idea you have to explicitly select the fields which should be included. So it’s always choice of a developer to misuse it. My favorite question on interviews is explaining all methods of class Object, including the contract and best practices for equals/hashCode. Failure to answer this question automatically disqualifies applicants to mid-level and senior positions.

>all methods of class Object finalize() is actually is a very hard mode; I'd not expect any extra senior to be able to explain it properly (incl. the semantics of JMM, the fact half created objects can be finalized; the resurrection ability). Deprecated now, so perhaps no need? wait/notify/notifyAll - easier, still require some practice, also not that useful any longer; but still I'd expect to know not to use a naked…

> finalize() is actually is a very hard mode;

> Deprecated now, so perhaps no need?

Yes. Worth mentioning existence and “do not touch it”, but no need to go deep. Same with clone. The point of this exercise is to demonstrate that you can use the core library without shooting yourself in the foot. As for wait/notify/notifyAll, I’d expect the correct usage patterns from mid-level.

Re: JEP draft: Prepare to make final mean final

#118
post #79

Earlier quoted context omitted.

Brian Goetz, chief architect of Java, once posted a "what they think I do" vs. "what I actually" do tweet. If I remember correctly, 25% - 50% of the "what I actually do" category was something like "get angry at serialization." So I think it's safe to say "what about serialization?" is always going to be asked.

In this 2014 talk, Brian shows a slide in which he characterizes a visible fraction of his job as “regretting serialization” (somewhat tongue-in-cheek). https://www.youtube.com/watch?v=2y5Pv4yN0b0&t=930s Link is to the start of a sequence of three slides, the third of which is the slide in question. For a more recent update on serialization, watch this talk “Serialization: A New Hope”: https://www.youtube.com/watch?v…

It's not just Java, either. The original .NET serialization system is very obviously inspired by Java, and has many of the same issues - to the point where it's effectively deprecated these days.

Re: JEP draft: Prepare to make final mean final

#119
post #4

From my perspective as a C++ developer, every attempt to use `const` for compiler optimization appears to be stymied by the existence of `const_cast`, because modifying a `const` value is only undefined behaviour if the underlying object is `const`. Glad to see that Java is willing to break the language to improve it.

The implementation of "const" in C/C++ is really annoying, in the end all you get is a bit of semantic documentation and a bunch of compiler errors or casts whenever some library doesn't use it. You can often trick the compiler into stronger optimizations by making a local variable marked as "const" (in which case it is a "true const") and copying the value to/from it.

The real problem is that "const" in C/C++ is a misnomer - the literal meaning of the word means "unchanging", and yet if you have a pointer or reference to a const T, it can, in fact, change. A "const pointer" in C is really a read-only pointer to some data that may or may not be actually constant.

In C, at least, you can usually distinguish a true pointer to immutable data by using `restrict`.

Re: JEP draft: Prepare to make final mean final

#120
post #71

Earlier quoted context omitted.

The issue is that many essential libraries and tools rely on setting internal final fields. I assume that's why the options around this have remained open-ended. The problem with these various "integrity by default" options is that, in most cases, granting access to one effectively grants access to all. For instance, JNI, agent libraries, and JPMS options can each be used to bypass restrictions, making the separation…

First, it's not a "crusade" but the steps necessary to deliver the features Java's users demand. Second, the prevalence of the use of JDK internals has dropped drastically, and demonstrably so. For example, many programs broke before internals were encapsulated during the upgrade from 8 to 9; 99% of the causes were libraries relying on internals, which had changed. Access to internals was closed off in JDK 16, althou…

> First, it's not a "crusade" but the steps necessary to deliver the features Java's users demand

Semantics. Nobody demanded anything, if we want to play word games.

The java philosophy of final, makes software less extensible. This is the point; to have less overriding. Regardless of what the voting body decides (the meaning of users being subtly repurposed), the feature is anti-developer-agency past the point of healthy balance. I dont understand the enthusiasm.

Post reply on HN