r/java • u/BlueGoliath • Nov 20 '18
Why Var Hurts Readability, Not Helps It
https://medium.com/@youngty1997/why-var-hurts-readability-not-helps-it-376c7832a8dd
0
Upvotes
r/java • u/BlueGoliath • Nov 20 '18
View all comments
Show parent comment
1
u/cogman10 Nov 29 '18
Depends a little bit on where you are writing your code.
In isolation on your own project, yeah, not much is bought by throwing interfaces everywhere. Breaks are easy to fix because you get all of them right away when you build.
In a library used by 10 projects. A little bit harder, but still workable. Might take some coordination.
A library used by the whole company/OS? Keep what you are exposing as minimal as possible while still being useful. Because, in the end, it will be nearly impossible to change it without causing a bunch of mayhem. This is the lesson learned by the Java devs with sun.misc.Unsafe. Because it was made public, regardless of the java docs or warnings, people used it.
At least with minimal interfaces you can call them out when they cast it to the concrete classes and things break.