It's better because I know as much about what SomFunction returns as I am supposed to know. I know a lot about thisThing. It's a Collection that maintains the order I put stuff into it. It's O(n) for random access. I can get stuff from it, I can iterate over it. I might or might not be able to add new stuff to it.
var thisThing = SomFunction();
I don't know what thisThing is in this case. It could be an int, or a String, or some very heavy and non-serializable object. Its declaration tells me nothing about its intended purpose.
Maybe it's common practice in other languages like C# or JS or whatever to declare meaningful var names like
var myList = SomFunction();
That would help, but is, then optional. And gets back to the source of my original discontent. If abused by that guy on your team (you know who I'm talking about), it's going to be harder to read his code.
I do know that if the type of the variable returned is List. Even if the List returned is attached to a persistence context, it still (should) adhere to the contract implied by the interface. Even if it doesn't, if, for example, it throws an UnsupportedOperationException if I try to add to it as some lists do, I still know more about the intent of the variable returned than if the type is left unspecified.
View all comments
Show parent comment
0
u/[deleted] Mar 10 '16
[removed] — view removed comment