4 ms·
You're naming a variable, not the title of your Magnum Opus. You're naming a variable, and that name is probably the most important documentation about that sp
by onion2k 7y ago
You're naming a variable, not the title of your Magnum Opus.
You're naming a variable, and that name is probably the most important documentation about that specific point in the code. A lot of the time a useful name will be quite obvious, so you should use one. If you see code that has variable names like a, i, myVar, value, etc then it's usually a sign the developer didn't think very hard about the code that they were writing. Using a name that gives some context to the data the variable should hold is massively useful to the next developer to work on the code (which is usually you, so you'll be thankful you did).
- raverbashing 7y ago'a' and 'i' are perfect for indexes or range traversals. Yes, myVar is bad. You can always read the context and see 'for value in list_of_values' or understand what's it that you're working with right now. Yes, be more explicit on the tricky parts, but sometimes i = i+1 is just fine.
- onion2k 7y ago'a' and 'i' are perfect for indexes Except they're not as good as 'index', which is obvious and provides some meaning, so why accept single character name? I have an eslint rule that blocks single character var names on my projects. It makes my team develop good habits, and no one has ever complained about it. Our code is very readable.
- raverbashing 7y ago> so why accept single character name? Because readability suffers with repeated long variable names There's a reason why math uses i,j,k and x,y,z and it's not to be petty.
- onion2k 7y agoThere's also a reason why a lot of people find equations incredibly hard to parse.
- Nevermark 7y agoThis is a nice semi-random deeply nested spot to observe how the topic of naming is so cognitively attractive. Even in the meta-sense it is being discussed here. There is something about naming that we like thinking about, and fine tune our thoughts on, more than a simple need for legibility. There is a sense of ownership in picking a name.
- de_watcher 7y agoAre you awful or just trolling? I've said that naming is very important, but I didnt't suggest that people should choose a longer word when two are equivalent. A real way to give 'more meaning' to the index is to indicate to which collection it belongs.