5 ms·
You fail to see that type inference is optional. So yes for readability's sake, in your first example I wouldn't omit the "int", but in simpler cases you CAN om
by haffla 11y ago
You fail to see that type inference is optional. So yes for readability's sake, in your first example I wouldn't omit the "int", but in simpler cases you CAN omit if you want. And that's just nice, end of story.
- nikolay 11y agoOptional, alright, but promoting bad practices. If people like dumb-down languages, there are plenty of them already!
- oldmanjay 11y agoWhat are the bad practices being promoted by this? How does it qualify as dumbed down? Simply ranting about things that, charitably, you don't seem to understand, does not make the rants valid.
- nikolay 11y agoThe best practice is that the type of the variable is of the interface, not the implementation except in some special cases.
- wtetzner 11y agoSo stop using constructors and start using static factory methods. The return type of a static factory method can be the interface type.
- nikolay 11y agoYeah, let's UML the hell out of everything to be enterprisey and be Martin Fowler-approved! This is what turned off a lot of people before!
- msbarnett 11y agoThis is complete nonsense if you're using a static constructor and not a factory. There's zero point to doing this for a local, statically constructed type. It's not a best practice. If you were using a factory, var would infer the factory signature's type, which would normally be the interface.
- nikolay 11y agoNo, it's not a complete nonsense, no. People abusing Java with overengineering and using factories and other enterprisey design patterns for everything made a lot of people leave the Java land!
- wtetzner 11y agoA "static factory" is just a static method. You know, a function. Nothing over-engineered or enterprisey about using functions to allocate objects.
- nikolay 11y agoWhy state the obvious?
- wtetzner 11y ago> Why state the obvious? So you think using functions is enterprisey and over-engineering things?
- nikolay 11y agoRead my other reply to you on the subject! The API might be a small syntactic change, but the concepts and the implementation behind those for noobs are not. They learn OOP and constructors and then you tell them - they suck, use factories via static methods.
- 11y ago
- oldmanjay 11y agoAs the sibling comment indicates, and I wish to amplify with precision, if you are using the static constructor reference to initialize the local, declaring the local reference to be of a super type is cargo cult nonsense, not a best practice. The concrete type is already locally known, nothing is gained via the abstraction.