News for hackers. Stuff that matters.
Re:Var and val in Java? by revelation on Saturday March 26, 2016 @02:45PM (#11366846)
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.

Re:Var and val in Java? by mabbo on Saturday March 26, 2016 @03:18PM (#11367011)
Just 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.

Re:Var and val in Java? by domergue on Saturday March 26, 2016 @04:10PM (#11367237)
Nope. 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.
Re:Var and val in Java? by mabbo on Sunday March 27, 2016 @11:40AM (#11370314)
When 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).

Re:Var and val in Java? by x0x0 on Saturday March 26, 2016 @03:17PM (#11367007)
His 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...

Re:Var and val in Java? by charleslmunger on Sunday March 27, 2016 @12:56AM (#11368957)
I 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.
Re:Var and val in Java? by dcminter on Saturday March 26, 2016 @03:34PM (#11367069)
I 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 :)

Re:Var and val in Java? by skocznymroczny on Saturday March 26, 2016 @04:30PM (#11367318)
this line of code isn't bad actually, because IDEs have autocomplete anyway.
Re:Var and val in Java? by takno on Saturday March 26, 2016 @04:36PM (#11367339)
It's easy to create. It's verbose and tedious to read
Re:Var and val in Java? by ChemicalWarfare on Saturday March 26, 2016 @05:33PM (#11367556)
Maybe 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.