News for hackers. Stuff that matters.
Re:Long Names are Long by choward on Friday June 17, 2016 @12:01PM (#11923419)
Why "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.
Re:Long Names are Long by pklausler on Friday June 17, 2016 @12:10PM (#11923469)
And 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.)

Re:Long Names are Long by SiVal on Friday June 17, 2016 @05:16PM (#11925610)
I 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.
Re:Long Names are Long by choward on Friday June 17, 2016 @12:19PM (#11923549)
> 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 }

Re:Long Names are Long by khedoros on Friday June 17, 2016 @01:23PM (#11924017)
Single 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.

Re:Long Names are Long by nailer on Friday June 17, 2016 @04:43PM (#11925428)
Iterating 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.
Re:Long Names are Long by stouset on Friday June 17, 2016 @11:05PM (#11926842)
FFS, it's on the same line of code. The variable is live for a single expression. This is style wankery at its absolute worst.
Re:Long Names are Long by nailer on Saturday June 18, 2016 @07:38PM (#11931128)
Sure but most functions are longer, small functions can grow, and consistency is better.

On a separate matter: you should read the HN guidelines.

Re:Long Names are Long by stouset on Sunday June 19, 2016 @05:19AM (#11932357)
> 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.

Re:Long Names are Long by nailer on Sunday June 19, 2016 @09:09AM (#11932836)
> 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.

Re:Long Names are Long by pklausler on Monday June 20, 2016 @12:43PM (#11939192)
> 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.

Re:Long Names are Long by khedoros on Saturday June 18, 2016 @02:27AM (#11927344)
I know that it's common. I use it in cases where there are more than a few lines of code, where the reader would have to maintain context. Wider context equates to a more specific variable name.

> multiplied by the amount of loops, is somewhat inconsiderate.

And using the more detailed variable name is misleading. It implies a longer scope, to me.