Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How worse? How would you even begin to understand this line without an IDE?

    auto something = someObject->someFunction();
    // and then 10 lines of various operations on "something"
    // also imagine that someObject is also auto and returned from somewhere
I've had to deal with code like this. It wasn't pleasant, even with an IDE. There are very few cases where type inference is good and doesn't make your code an unreadable mess.


Step number one is not naming your things "something". I for one am glad I can use "auto" instead of "std::vector<int>::size_type" in my code–in this case the actual type this couldn't matter less; all you need to know is that it's some kind of unsigned integer. The same is true for Swift, where it's generally a lot more useful to know you have some type of sequence rather than "I have a LazyMapSequence<LazySequence<[Int]>.Elements, String>". Plus, C++ is one of those languages where certain things have types that you cannot write down, so auto is required to use certain parts of the language!


Type inference is the usual tradeoff for being able to write statically-typed code efficiently. I think it's better than

  MyType something = new MyType(...); 
like in old-school Java, is it not? IDEs and LSP-enabled editors are pretty much the standard nowadays, although I agree that it's nice to be able to read code without one.

Also, that code you mentioned seems like bad style with the auto keyword; the type should be obvious.

Do you have a better solution in mind?


> IDEs and LSP-enabled editors are pretty much the standard nowadays

There are many places where you see code without IDE-like features. One that comes to mind is everything related to git. Web-based git tools like github, git GUIs, command-line git, you name it.

Besides, it's nice to be able to read and understand the code without needing to download the entire project and importing it into an IDE just for that.

My idea is that you almost always write in an IDE, but not necessarily read in one. Thus, for verbose languages, the IDE would generate most of that example for you (I know for sure IDEA does this exact completion) but it will be perfectly understandable in a git diff.


> There are many places where you see code without IDE-like features. One that comes to mind is everything related to git. Web-based git tools like github, git GUIs, command-line git, you name it.

Both git and web-based git+ services like Github are frequently used through deep editor/IDE integrations, so, no, I disagree that “everything related to git” is a good example here.


I use all such tools mostly from the comfort of my IDE.


You just need to use auto properly.

auto/var/val etc are best used when you can tell the type from the rvalue.

    var m = new HashMap<String, List<Pair<X, Y>>>();

    var m: Map<String, List<Pair<X, Y>>> = obj->someFunc();

All of the examples you have should be caught in linting or code review.


> You just don't know how to use auto properly.

I do. The problem is, others don't necessarily do. A good-in-my-world language makes it take more effort to write unreadable code than readable.

Everyone seems to only be judging languages by the code you write yourself, totally oblivious to the fact that reading and understanding someone else's code, including in projects you don't influence, is also an important part of being a software developer.


Believe me, we've read a lot of code written by other people. There's a point where you read

  HashMap<Integer, ArrayList<String>> mapping = new HashMap<Integer, ArrayList<String>>();
enough times that you start to get tired of reading stuttering code, too.


By your logic we shouldn't program because someone else MIGHT mess it up.

Should we remove every feature that someone might misuse?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: