Hacker News new | ask | show | jobs
by mattmanser 3504 days ago
If you change the return type of a method without using var you would still have the exact same problems. That's not an actual problem.

I've used var since it came out years ago and never had this autocompletion problem you talk about.

You sometimes had to explicitly declare a type in foreach loops, but that had more to do with shitty legacy APIs that used abstract classes as return types. Wasn't really var's fault though.

1 comments

Consider the following scenario:

You have a Toilet object with a method flush.

  var toilet = house.getToilet();
  toilet.flush();
Now you find out that updating Toilet objects is somehow expensive and decide to wrap it into a Cache<Toilet>. Unfortunately, Cache also has a flush method, so there will be no compile time error, but functionality is broken now.

I agree this problem would also occur when using chained calls (house.getToiled().flush()), but explicit types could cover at least some of the cases.

> Now you find out that updating Toilet objects is somehow expensive and decide to wrap it into a Cache<Toilet>. Unfortunately, Cache also has a flush method, so there will be no compile time error, but functionality is broken now.

This has happened to me exactly 0 times since type inference was introduced in 2007/2008.