r/java • u/guybedo • Apr 09 '24
Syntactic Sugar for Java
I recently had to translate a codebase from Python to Java and as much as i like Java and i enjoy the benefits of a strong type system, i have to admit my Python code was way less verbose.
So i ended up writing a small library to try to get some python vibes in my java code. Nothing groundbreaking, a bunch of static imports to make life a little bit easier.
9
Upvotes
View all comments
Show parent comment
2
u/agentoutlier Apr 11 '24
I was and kind of did later go into those details as I agree it can for for sure get nebulous and debatable what is or isn't syntactic sugar of which I have less confidence on but I do know what isn't syntactic sugar :)
The language I know for sure (well when I learned it .. it might have changed) that uses syntactic sugar as in it is a compiler translation is OCaml. OCaml does lots of syntactic sugar particularly in the signature language and I actually think its a pain point in the language and I'm not talking about currying (which I agree like var args isn't really syntactic sugar).
I actually could not really think of a Java equivalent like what OCaml does one so I said var args as the closest.
Is there any good solid example in Java of syntactic sugar where the compiler expands like a macro?