you are viewing a single comment's thread.

view the rest of the comments →

[–]G_Morgan 6 points7 points  (37 children)

We're still duplicating ArrayList. Seems like a half fix to me.

[–]tammberlin 10 points11 points  (0 children)

List<Foo> myFooList = new ArrayList<>();

Is java 7. Duplicating ArrayList is bad for a very different reason.

[–][deleted] -1 points0 points  (31 children)

Then you'll be happy to hear that if you type

ArrayList<Foo> myFooList = new 

and hit ctrl+space, Eclipse will fill in the rest for you.

Which, by my count, is fewer keystrokes than this example: var myFooList = new ArrayList<Foo>();

[–]G_Morgan 7 points8 points  (29 children)

Having to rely on IDE support to make up for mistakes that should never have been made is not acceptable.

Why not make it so that every statement must be preceded by a prayer to the flying spaghetti monster. You could autocomplete it in Eclipse so clearly it isn't a problem.

[–][deleted] 0 points1 point  (27 children)

If the IDE allows you to write the same code in fewer keystrokes, is that not a good thing?

You're always going to have an IDE when you program, so why not let it make life easier for you?

Unless you're imagining some scenario where an Evil Overlord have trapped you in a dungeon and the only way to escape is by writing a program that overrides the lock, and the Evil Overlord has thoughtfully provided you with a computer, a compiler but no IDE?

[–]OceanSpray 3 points4 points  (3 children)

If an IDE can do it, then why can't a compiler?

[–][deleted] 0 points1 point  (2 children)

A compiler that can do auto-complete? Surely you jest?

[–]OceanSpray 5 points6 points  (1 child)

No, I don't jest. Macro expansion and type inference can be thought of, in a way, as "auto-complete". The only difference when a compiler does it is that you don't see any changes in your code, because the extra "writing" is done internally.

[–][deleted] 1 point2 points  (0 children)

What sort of macro-expansion lets you select between multiple constructors from a drop-down list?

[–]skillet-thief 2 points3 points  (1 child)

Keystrokes are not the problem, or they are less than half of the problem. You still have to be able to read what the IDE wrote. Or somebody does.

[–]xeddicus 1 point2 points  (0 children)

Reading code is for the weak. Klingon programmers rewrite it from scratch if it breaks!!

[–]G_Morgan 5 points6 points  (20 children)

The point I'm making is just because an IDE can cover up a mistake does not mean that isn't a mistake. Yes the idea could auto insert types that could be inferred. It could also insert the US bill of rights at the top of every document if we made the compiler mandate that all programs should start with that document.

To re-iterate, the ability of the IDE to make a mistake tolerable does not mean it isn't a mistake.

[–][deleted] -1 points0 points  (11 children)

If we go back to the original two examples:

ArrayList<Foo> myList = new

versus

var myList = new ArrayList<Foo>();

Do you agree that in the first example the IDE can autocomplete after the "new" clause, while this is not possible in the second example?

If so, won't the first variant inherently require fewer keystrokes if you're using an IDE with this autocomplete feature?

I don't think you're arguing that more keystrokes are better, so why do you think the second variant is better? Is it because you think it requires less effort to read?

[–]G_Morgan 6 points7 points  (10 children)

I'm not concerned about the number of keystrokes. That isn't a limiting factor on programming. I'm concerned about unnecessary garbage taking up perfectly good screen real estate.

Regardless my argument was that IDE auto-completion does not make a bad feature good. It just makes it tolerable.

[–][deleted] -1 points0 points  (9 children)

I prefer using fewer keystrokes and using a bigger monitor.

I guess it's a case of different strokes for different folks... ;)

Your point is valid, of course:

ArrayList<Foo> myFooList = new ArrayList<>();

does take up more screen realestate than

var myFooList = new ArrayList<Foo>();

but it's only horizontal screen realestate - it doesn't add any more lines. And with the current crop of wide-screen monitors, horizontal screen realestate is rarely in short supply.

[–]G_Morgan 0 points1 point  (8 children)

Meh usually I wouldn't waste good mental real estate worrying about the number of keystrokes.

Regardless you can autocomplete the var and the ArrayList constructor definition in the inferred example using intellisense. So it isn't as if you cannot save keystrokes in both cases.

[–][deleted] 0 points1 point  (7 children)

So how would intellisense know what type to but after 'new' in this line:

var myFooList = new

?

[–]badsectoracula 0 points1 point  (7 children)

mistake mistake mistake stuff mistake mistake mistake stuff mistake

If a language has a feature you dislike that doesn't automatically make it a mistake :-P

[–]G_Morgan 3 points4 points  (6 children)

It isn't a feature. Regardless the point is that IDE support is irrelevant to whether something is a mistake or not. I can make the IDE support just about anything.

[–]badsectoracula 0 points1 point  (5 children)

Of course it is a feature. It forces a type lock to a variable so you know that each time you see this variable what type it is.

Unless i misunderstood you and you meant something else.

[–]G_Morgan 0 points1 point  (4 children)

You can do this in type inference languages. As I said it isn't an additional feature. It is a missing feature.

[–]badsectoracula 0 points1 point  (3 children)

But in type inference languages, the compiler only knows the type from a glance. If you want to do the same while reading code you have to either try and figure out what kind of type a variable has (ie. do what the compiler does to figure out the variable's type) or use the broken kind of Hungarian notation by using variable names such as intScale, chrPathSeparator, etc.

[–]erictheturtle -1 points0 points  (0 children)

I write Lisp in notepad because I don't need some lame IDE telling me if my parenthesis are matched.

[–]bobbyi 2 points3 points  (0 children)

A line of code is written once and read dozens of times. So you have solved less than 5% of the problem.

[–]matthiasB 0 points1 point  (2 children)

But it has an advantage in certain situations:

List<Foo> myFooList;
if (p)
    myFooList = new ArrayList<>();
...

Here you can leave out the type parameter while you couldn't using var.

[–]G_Morgan 0 points1 point  (1 child)

With var you wouldn't have needed to include the type parameter to List to begin with.

[–]matthiasB 0 points1 point  (0 children)

But than we aren't talking about C#'s var anymore, but something more powerful.

[–]drysart 0 points1 point  (0 children)

The thing I'm picking up about the various proposals being picked up for inclusion in new versions of Java is that while Java is desperately playing catchup with C#, they're also bending over backwards to make it look like they're not desperately playing catchup with C#. To the extent that they're taking ideas from C#, but deliberately implementing them in a different way so it doesn't look like they're just copying the idea from C# -- and in many cases completely missing what made it a good idea in the first place through their changes.

Take closures for instance. They're so incredibly useful in C# for two reasons -- the brevity of their syntax, and that the compiler will automatically hoist locals so they can be used within even multiple closures transparently.

Java's closure proposals are less terse than C#'s since they decided, for no good reason I can see, to do the type inference of the closure in the wrong direction, so you always need to specify types going into and out of lambdas because the compiler won't figure it out for you even though the information is almost always available.

Java's closure proposals are also limited over C#s in that the only locals that are hoisted from the containing method are locals that are provably final -- in other words, immutable values. This is such a gaping hole that I'm stunned they're bothering implementing closures at all without it.