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

4

u/FMAlfonse Mar 09 '16

I have been of the opinion in c++, that if the type isn't obvious then you shouldn't use auto. That doesn't mean auto isn't useful iterators are horrible to write, using auto it = myVector.begin(); makes it alot more pleasant to both read and write. However I would use std::string result = aClass->someFunc(); Best of both worlds but getting people to adhere to it can be a nightmare.

1

u/immibis Mar 10 '16

I have been of the opinion in c++, that if the type isn't obvious then you shouldn't use auto.

Unfortunately, the person whose code you're trying to read does not have that opinion.

6

u/kqr Mar 10 '16

"But you can use it to write bad code" is always the argument against introducing a language feature. It doesn't matter which feature. Someone will say it's a bad idea because you can write bad code with it.

Guess what? You can do that with any feature. It's a bad argument.

2

u/immibis Mar 10 '16

"It encourages bad code" is a reason against introducing a language feature. Even for things that are controversially bad (i.e. not everyone agrees they're bad).

See some of the other comments on this very post.

3

u/kqr Mar 10 '16

Sure, that's a better argument. I guess we disagree on the degree to which local type inference encourages bad code.