6 ms·
I'm of the mind that it is un-Java like. Whether or not there is a "Java" as a philosophy is not the hill I'm trying to die on. Consider these contrived lines
by mieseratte 7y ago
I'm of the mind that it is un-Java like. Whether or not there is a "Java" as a philosophy is not the hill I'm trying to die on.
Consider these contrived lines of code:
```
String first = someMethodCall();
var second = someMethodCall();
```
The first provides more useful information at a glance. I don't see any value in the "nice shorthand." Typing out "SomeStupidClassName" has never once been a material bottleneck in my 15+ years of programming, but now we have this new option that caters to the lazy, and in doing so makes life harder. Now I have to either ban it, embrace it, or come up with some ruleset around when you can and can't use it. Why? Someone can't be bothered to type a few extra characters.
It reminds of my grandfather, a former professional ball player, but one who played back in the days where there weren't these multi-million dollar celebrity ballplayers pissing and moaning in the press about just how hard their life is. He used to call those types "high-priced cry-babies," and I really feel a tinge of that in dealing with folks who just wholly embrace `var` and give folks like me shit for having criticisms of it. Perhaps that's just my old blue-collar showing but your convenience in writing a handful of characters simple will never enter into my considerations.
I love using Java, I love the addition of things like streams, the Optional type, etc. My sibling comment is a little right, and very wrong. Lots of Java developers have a certain conservatism about them, I'm mostly certainly one. But there are large reasons to hate it.
- anchpop 7y agoTo quote another comment from this thread: > [D]rop the strawman argument and borderline ad hominem. It'll do you better.
- bunderbunder 7y ago> I don't see any value in the "nice shorthand." Typing out "SomeStupidClassName" has never once been a material bottleneck in my 15+ years of programming There are a few rather glaring spots that I've noticed. First, when you're refactoring, you've now got to edit every spot where a variable of that type is created. At the very least, when you're just renaming a class, your IDE can help you, but you still create a lot of diff noise. At worst, when you're splitting up a class or otherwise shifting responsibilities, you may end up with a whole lot of yak to shave. This is not just an annoyance; it's a latent code quality problem, because it creates a disincentive to clean things up. Second, I've seen it become an impediment to writing clean code in the first place. I have encountered situations where it's clear that the author wrote someMethodCall( withOutputOfSomeOtherMethod( thatTransformsTheOutputOfYetAnotherThing( basedOnThisInput))); because creating intermediate variables would have meant having to type out (and burn precious screen real estate on) some ridiculous set of 60-character generic type names. I've even seen it result in situations where data gets copied or otherwise processed excessively, because the explicit type annotation resulted in an upcast that shed some useful feature that a subsequent developer shimmed back in because they trusted the explicit type annotation and not a function's actual return type. So yeah, I decry your assertion that this feature is about being lazy. This feature is, at least for me, about code quality.
- Retra 7y agoIt would appear that all of your code quality arguments are "people are too lazy to actually write good code." So it's not clear why you would decry that assertion. I don't have a horse in the race one way or another, but you're not refuting mieseratte's objection.
- joshuamorton 7y agoA tool that encourages you to shoot yourself in the foot is a bad tool. If a language encourages bad patterns by making good patterns overly verbose, the language should address that.
- scott_s 7y agoIf explicitly naming the type is better, then do that. I find it useful for cases such as: OurConfabulatorWithADashOfSpice confab = new OurConfabulatorWithADashOfSpice(); Versus: var confab = new OurConfabulatorWithADashOfSpice();
- EpicEng 7y agoSure, in a contrived example where the return type is not obvious, you perhaps shouldn't use var. What about real world examples where the type is more often than not obvious?