Re:Better Java – Resources for Writing Modern Java
by Cthulhu_ on Saturday September 19, 2015 @07:13PM
(#10245874)
Re the first bit about 'struct' style, even better (IMO) is to use Lombok; throw an @Data annotation on your class and all you need to do is put your properties in there (private final if need be). Nobody should be writing those boilerplate constructors, getters and setters. If it's generated by your IDE, use Lombok. The best code is no code.
[ Parent
| on HN ]
Re:Better Java – Resources for Writing Modern Java
by Babylonian on Sunday September 20, 2015 @04:25AM
(#10246931)
Lombok is a crime. Have you seen what happens when someone does a minor reformatting of your code and moves one field declaration above another? You get a nasty little surprise because the two fields of the same type have now reordered in your Lombok generated constructor. When the app runs nobody can figure out why foo is set to bar and bar is set to foo. There's also the issue of Lombok vals which don't conform to the language spec leading to other fun. And it's almost always incompatible with new jdks without code changes to the lombok libs due to the whacky way it relies on implementation specific compiler details.
Re:Better Java – Resources for Writing Modern Java
by dguaraglia on Monday September 21, 2015 @05:30PM
(#10255267)
Wow, I didn't know this could happen. I've only recently started using Lombok for some side-project related stuff and this heads up comes at a really good time. Thanks!
Re:Better Java – Resources for Writing Modern Java
by monksy on Sunday September 20, 2015 @02:09AM
(#10246713)
Thats one of the things that'll happen to you if you start writting groovy code. The whole setter/getter boilerplate thing gets really annoying.
Another groovy-ism.. the whole deal with having to copy properties. (In a groovy class they're threated like a map)
Re:Better Java – Resources for Writing Modern Java
by vorg on Monday September 21, 2015 @06:10PM
(#10255456)
> properties. (In a groovy class they're threated like a map
Except in hard to remember special cases like .class which gives the class "LinkedHapMap" of the map object instead of the value at key "class". After working with Groovy for a short while you'll realize you're really working around it.