5 ms·
Well, I just looked through the authors recent activity on GitHub, and stuff like this: > SecurityPositionCalculationFunction function = new SecurityPositionCa
by revelation 11y ago
Well, I just looked through the authors recent activity on GitHub, and stuff like this:
> SecurityPositionCalculationFunction function = new SecurityPositionCalculationFunction();
is exactly why Java needs var/val/whatever decide already (PICK ONE! DON'T RUIN THIS JAVA!).
So I'm not sure why he would pick some piece of code that violates the simple rules the C# team suggests and then burn that strawman with a flash of gasoline.
- x0x0 11y agoHis argument hinges on certain language syntax being awkward when mixed with declaring local variables final, something I've never seen. He asserts it's "a reasonably common coding standard", but again, I've written a lot of java code and never seen this in a coding standard. I skimmed projects I use on apache and don't see it there either. Maybe it's a finance industry thing? That said, I'm grateful for joda, and Stephen has written a hell of a lot of (good) java...
- dcminter 11y agoI do this pretty consistently - it avoids a small category of errors: assignment to the wrong variable is less common when there are fewer variables! But I have to agree that it's unusual. I'm always willing to forego this if the team objects to it because I think the advantage is slight. I'm therefore slightly in favour of the val/var option over "final var" as the former might encourage the immutable by default approach since it requires less typing. I would guess the view would split pretty much exactly like that between those who do and don't currently use final locals by default. Rich bike-shedding lies ahead :)
- charleslmunger 11y agoI like adding final to most of my local variables. I can declare a variable final, and no matter how complicated the control flow is that assigns its value, I know the compiler is enforcing that it's only set once. It also avoids accidental = rather than == bugs.
- mabbo 11y agoJust for context, another piece of Java code the author wrote is a little library called 'joda time'. And then also the standard java.time library. Does this make him the best Java coder in the world? No, of course not. But it does make me more inclined to listen when he has opinions on what makes good Java. Do give him some credit as a good Java developer, is my point.
- domergue 11y agoNope. Just becuase he made a library that eventually got popular and rewritten for JDK 8 doesn't mean he's some kind of authority. Quite opposite actually. This guys is as backwards is it gets. Just read about his ramblings about Scala.
- mabbo 11y agoWhen someone who is accomplished and respected says things I disagree with, the response I try to have is not to respect him less, but to reconsider my own viewpoint. Perhaps their opinion is from experience I don't have yet, or from a perspective I don't share. In this particular case, I actually disagree with him about var/val- I think they're a great step forward. But that said, I value his differing opinion on the matter, and try hard to really see his point as to why he disagrees. Perhaps in time I'll realize he was right, or perhaps in time he'll realize he was wrong. Or maybe it will be like putting final on every variable declaration- my teammate and I will never see eye to eye on it (so much extra noise for so little gain, imho).
- skocznymroczny 11y agothis line of code isn't bad actually, because IDEs have autocomplete anyway.
- takno 11y agoIt's easy to create. It's verbose and tedious to read
- ChemicalWarfare 11y agoMaybe it's me but after working with Java for a while I don't mind the verbosity of variable declarations especially when looking at someone else's code. There's obviously plenty of boilerplate in Java that can be rather painful to deal with at times but again I don't mind it when declaring variables.