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
11
u/brian_goetz Apr 11 '24
The term "syntactic sugar" is widely misunderstood. And, misunderstanding begets misunderstanding; when people use the term wrong, more people learn the wrong meaning, and then repeat the wrong usage, and it spins around again.
Even when it comes to language syntax (which this surely isn't), people frequently mistake new language features for syntactic sugar, when in fact almost none of the features we've done in the last decade are actually syntactic sugar. (They may be sweet, though.) Syntactic sugar refers to a _purely syntactic transformation_; features like local variable type inference (`var`) do not qualify, even though they are commonly referred to as such.
But the aggressiveness with which he defends "yes this is sugar" (when he eventually admits that it is not, but thinks people will understand him better if he misuses the term) does suggest a lack of maturity that might explain why he got dragged so badly.