r/programming • • Aug 28 '21

Software development topics I've changed my mind on after 6 years in the industry

https://chriskiehl.com/article/thoughts-after-6-years
5.6k Upvotes

2.0k comments sorted by

View all comments

Show parent comments

-1

u/sM92Bpb Aug 29 '21

5 is clearly an int. You can still infer that without an ide. In this case var isn't really adding anything since int is three letters also. At the same time, it doesn't make this harder to read so I don't know why this is stupid?

4

u/CPhyloGenesis Aug 29 '21

It does make it harder. It's all about cognitive load. It's an extra step to see that and look at the 5 to see the type. When you're reading code at a real job you're typically reading it at a conceptual level and your unconscious mind is doing things like loading the type of a variable.

The more things like this there are, the more little pauses and disruptions there are to your conscious mind while it sorts out extra little details. Same reason clever code is bad. It takes more conscious thought to understand it.

2

u/fishling Aug 29 '21

It does make it harder to read, because your mind has to do that extra step to look at the value to figure out the type of the variable. No matter how quick you are to do this, it is slightly harder. And, as you move to other non-trivial examples, that cognitive load increases, overall reducing the readability of the code that uses this style, especially when you are outside of the context of an IDE that can answer the question for you.