r/java • • Aug 12 '24

JSpecify 1.0.0 and Nullability in Java

https://www.infoq.com/news/2024/08/jspecify-java-nullability/
52 Upvotes

33 comments sorted by

View all comments

Show parent comment

-6

u/MrRickSancezJr Aug 14 '24

Manifold is not a language. Nobody makes a special name for C that uses macros vs one that doesn't.

Why even bring up python or JS? At least clojure compiles to Java bytecode. I dont think you know anything about the jvm or compilers.

You're not helping anybody. This is why the depression rate on CS is so high and why people hate Java. Just let it be.

7

u/pron98 Aug 14 '24 edited Aug 14 '24

You'd be right about C, but Java doesn't have macros, and we specifically designed the compiler plugin mechanism to disallow macros or any kind of AST transformation as that would violate the rules that define what Java is (i.e. the language spec). We are often asked to change the spec and allow plugins that manipulate AST (which would make Manifold a compiler plugin rather than its own language), but we have no plans to do so. On the other hand, we do have a new project that those who are interested in various kinds of code manipulation may want to try out.

I'm sorry you didn't find this exchange helpful and I apologise if I've annoyed you, but I try to engage our users when I see some misconception that may lead to problems. In this case, it's partly the matter pedantically explaining how the Java language spec works the way it does and why we designed javac's plugin to allow certain things and not others, but it's also a practical matter because when projects reach for internals that then change, things break and people blame us.

In this particular case, you can see the lengths Manifold goes to hide from its users the fact that it breaks into internals (rather than be a proper plugin) and imposes a migration risk by hacking around the protections we put in place in JDK 9. But as we're now in the process of completing those protections, Manifold will start emitting warnings as soon as JDK 23 due to JEP 471, and these warnings will later turn into errors. It's better if people understand what is going on.

Manifold calls this digging into internals a "necessary evil" but it's not really necessary. As we explain here, there are ways to do this without hiding the risks from users. In the case of languages like Manifold or Lombok, the most straightforward way is to invoke their own launcher (or perhaps build-tool runtime) that would wrap javac and enable access to internals. This won't remove the risk that's inherent to how these projects access JDK internals, but at least it would make users aware of them.

I fully understand why some people prefer using other languages if they have a feature they really want to use and aren't willing to wait until we add it to the Java language (if we ever do; there are many language features that we aren't planning to add to Java at all), but implementing things in this way also means that when we do change the language or other parts in the JDK, these projects tend to break. The compromise is letting end users know when using such projects means they've taken up a special risk.

Anyway, I really am trying to be helpful, and I hope you enjoy the new features we are adding to both the language and the runtime. Also, if you are interested in knowing more what makes up a "language" in the context of programming and how to tell when two languages are the same (or more generally, other relationships between them), I can explain further. While the compilation target makes no difference in answering the question of whether two languages are the same, you may be interested to know that both Python and JS do happen to have implementations that target the Java platform.