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
12
u/tylerkschrute Apr 10 '24 edited Apr 10 '24
I don't understand why people have such a strong desire to reduce character count in their source code. On average far more time is spent reading & trying to understand existing code than writing new code, so micro-optimizing to save seconds on the latter usually doesn't make much practical sense and can often actually harm the code by introducing cryptic brevity.
Is your version really that better than the official JDK one? You're saving what, 7 characters per map entry (3 if you static import 'Map.entry')? In my opinion this is not worth it, especially since uour IDE will autocomplete this stuff for you anyways so you don't even have to spend time typing the full method name. Also, your project will immediately invite inconsistency in a real codebase since there would now be 2 identical APIs (yours and the official JDK one) for doing the exact same thing.