r/programming • • Mar 09 '16

var keyword proposed for Java

http://openjdk.java.net/jeps/286
250 Upvotes

395 comments sorted by

View all comments

Show parent comments

5

u/kmaibba Mar 09 '16

That's a cultural problem though. Somewhere, someone along the way decided that you MUST have an ISomething for every Something, and while we're at it, have an ASomething too! And then use an ASomethingFactory and an SomethingFactoryImpl to instantiate the SomethingImpl. To top it all off, offload all the EVIL MUST NOT USE "new" to a DI Framework and configure it in XML-files. That should do the trick. Your code is now "maintainable", because when you change something, you just have to implement the interface and the edit some XML file, as opposed to just changing one line of the fucking implementation. Fuck actually being able to debug and read stuff, right?

Got a new guy at work who writes code like this and it's a nightmare to read. I mean the actual implementation is 20 lines of trivial CRUD code, why do you need 4 support classes/interfaces spread over 3 packages? Why can't you you just write a simple class, write some tests and the do your silly abstractions the moment you actually need them (hint: you won't need them 99% of the time, and the other 1% you will need to change all the other stuff anyway because of unforseen new requirements).

OT though, I hope and am pretty sure that they won't implement the var keyword. All it does is reduce readability and save some keystrokes. Verbosity is not a bad thing. It might look clumsy when you compare it to some hipster language tutorial, and it might suck a little bit while writing the code, but when reading and understanding the code later, it's a godsend.

5

u/[deleted] Mar 09 '16

Do you really write Java without an IDE though? Pretty much all of them support hovering over the variable to see its type.

1

u/kmaibba Mar 09 '16

No, I use an IDE, but as you say, you have to hover over it. I just think that the small benefit of not having to type as much (and usually you type only a few letters and then auto complete) does not outweigh the disadvantages. Again, I don't think that verbosity is a bad thing at all (within reason). Only a very small part of your time spent programming is actual typing.

2

u/[deleted] Mar 09 '16 edited Mar 09 '16

It hinders readability for me when the types are some convoluted generic thing to have it in the code. As long as I can see the type when I'm unsure, it's much easier to focus on the rest of the code.

I generally can't autocomplete much of Func<string, Func<SomeObject, List<SomeOtherObject>>> and I can tell from the code that that's what must be returned anyway.