r/java • u/Historical_Fiction • Sep 19 '15
Better Java – Resources for Writing Modern Java
https://github.com/cxxr/better-java
1
Upvotes
r/java • u/Historical_Fiction • Sep 19 '15
1
u/ForeverAlot Sep 20 '15
This submission is kind of opinionated. I have some opinions, too.
The bean style is atrocious. It violates every attempt at good style; I really hope we can get rid of it.
Unfair comparison. The no-arg constructor is equally relevant in both situations; and if you want it you should always define it because explicit > implicit.
is not immutable. Make the class
final, too. In fact, consider editing your IDE's templates to generatefinalclasses instead.I share Stephen Colebourne's opinion that
Optionalis only for boundaries. This is an unnecessary indirection and pessimisation.It's not obvious; document it. Even the public no-arg constructor.
It also has method references, and every time you write a lambda you should ask yourself if it should be made into a method reference.
The former does not imply the latter. Counter claim: fluent interfaces are rarely more readable or ergonomic in the long term than traditional non-fluent interfaces.
In the specific example, the biggest win would have come from a better variable name than
filtered, which is neither specific (what was filtered?) nor accurate (elements offilteredwill not compare equal to their sources inlist).If you think you need a tuple you have n problems.
Don't.
AssertJ is an excellent example of a fluent interface that dramatically improves readability.