5 ms·
I disagree. It is a great, clear, readable, succinct name, the same way that 'i' is a great name for an index in a loop, or i,j,k can be great names for nested
by jng 10y ago
I disagree. It is a great, clear, readable, succinct name, the same way that 'i' is a great name for an index in a loop, or i,j,k can be great names for nested indices. Einstein's multi-index notation was based in the same principles and works great in the contexts where it is used, the same that 'u' works great above.
- choward 10y agoWhy "u"? Why not "a"? Because "u" stands for "user"? Then make the variable "user" and don't add extra mental overhead for me when I read it.
- pklausler 10y agoAnd then you have the similar names "user" and "users" present in the same scope. There's absolutely nothing wrong with single-letter variable names with miniscule scopes. (Well, never use lower-case 'l' for anything, but the rest are fine.)
- choward 10y ago> And then you have the similar names "user" and "users" present in the same scope. So? They are different names and have different types. Maybe this is a ruby specific thing. Are you suggesting since "u" looks more different from "users" than "user", it's easier to tell it's a different type? Usually in non statically typed languages, I thought you make the variable more descriptive to make up for lack of types not less descriptive. For example: user_collection.each { |user| puts user.name }
- khedoros 10y agoSingle letters for iteration values are a common convention in a number of languages. In the case of user/users, I'm likely to miss the distinction when scanning the code. If I've got a bunch of little lambdas, short loops (under 10 lines, perhaps), or list comprehensions, I'm not going to use longer names in them, because the context is clear and limited in scope. If the variable's got to stick around longer (like throughout a function/method), it'll get a more descriptive name. As the scope grows, the variable loses the context that it came from, and it's more likely to need a longer name to make its meaning clear.
- nailer 10y agoIterating user for users is also a common idiom. Additionally making others having to look at the context to know what a u is, multiplied by the amount of loops, is somewhat inconsiderate.
- stouset 10y agoFFS, it's on the same line of code. The variable is live for a single expression. This is style wankery at its absolute worst.
- nailer 10y agoSure but most functions are longer, small functions can grow, and consistency is better. On a separate matter: you should read the HN guidelines.
- stouset 10y ago> most functions are longer Irrelevant. This function is painfully short. > small functions can grow It's a microlambda passed to a map function. 99% of these will never grow past a single expression. Hell, 95% of these will never even be modified. > consistency is better What, exactly, is this inconsistent with? > you should read the HN guidelines There's a difference between being uncivil and expressing frustration frankly.
- nailer 10y ago> This function is painfully short. Irrelevant. Other functions are longer. And needless human minification will undoubtedly creep in there too. > What, exactly, is this inconsistent with? Other functions. > expressing frustration frankly. Calling someone a wanker isn't exactly a pinnacle of expression.
- pklausler 10y ago> Calling someone a wanker isn't exactly a pinnacle of expression. No, it's not. But you shouldn't confuse your own identity with your coding style preferences, which were what the comment used "wankery" to describe.
- SiVal 10y agoI recommend skipping both cases of the letter O as well. I'm surprised so many people use it, especially to mean "object". Really, code that uses `my_dict[O]` where the object is a hashmap key or `O1 + O2` demonstrating the wonders of operator overloading even show up in textbooks. No scope is small enough to justify O as a variable name.
- pklausler 10y agoUse 'j' and 'k', avoid 'i', especially for loop controls. It's so much easier to find their uses in the loop body with an editor, since they're high-valued Scrabble letters and they don't show up in C++ reserved words apart from "break".
- nikanj 10y agoUse an IDE instead of an editor and finding/hilighting usages is just one keypress away. I'm often surprised how many people assume IDE=editor, but with higher system requirements.
- kazinator 10y agoIn Vim (editor, not IDE), if your cursor is on the i, then * will jump to the the next occurrence, # the previous one. In addition, they all get highlighted if ":set hls" (highlight search) is on, which is the default. "Don't use 'i' because it occurs often in keywords, making it hard to search for" is the most outlandish thing I've head in a good several weeks, even without the Scrabble reference.
- sullyj3 10y agoAlternatively, you could search for "int i" or "\<i\>", or "for (i".
- kazinator 10y agoMore importantly, don't use Notepad or Pico for writing code.