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
27
u/ingvij Apr 09 '24
I honestly won't complain about the DSL, I think you can create the abstractions you want to make your code look better for your taste and use them in your project if you or your team is happy with that..
A couple of things though:
This is the kind of library that I would most likely not want to use in any performance-aware application. Remember that there's always a trade-off. When you add layers on top of your code, it will pay a cost. From a quick glimpse over the KeyValue class and the `map()` static function, I would assume there's some GC overhead on using this over a regular `new Hashmap<>(Map.of(...))`.
Intense usage of this library can yield a codebase that is java in theory but not really in practice, increasing the entry barrier for contributors, so that would also be a factor against using this library on a project.
But then, as I said, if it works for you, then I guess this is fine.