News for hackers. Stuff that matters.
Re:Practical Go: Real-world advice for writing maintainable ... by zbobet2012 on Thursday February 21, 2019 @05:21PM (#19221086)
I generally find if you need multi letter variable names it means your function or scope is to long, or manipulating to many things. It's a nice little red flag for me.

Up to four or five single letter variables is pretty trivial to remember. Especially when three of those are i, j, and k. More than 6 or 7 rapidly becomes painful. But if you are manipulating 6 or 7 variables _in the same scope_ you are doing to much.

I also agree with Pikes comments about typography here: http://doc.cat-v.org/bell_labs/pikestyle

Re:Practical Go: Real-world advice for writing maintainable ... by pcwalton on Thursday February 21, 2019 @05:57PM (#19221411)
I could not disagree more. When I'm skimming code, I want to immediately know what a variable means. I don't want to go cross-reference elsewhere.
Re:Practical Go: Real-world advice for writing maintainable ... by zbobet2012 on Thursday February 21, 2019 @06:49PM (#19221788)
If you have to go "cross-reference" elsewhere you are modifying something "to far away" from you. That's a giant sign of spaghetti code.

Also names vary with there contextual scope. Larger scopes mean longer names generally. Russ Cox gives a succinct description here: https://research.swtch.com/names

  A name's length should not exceed its information content.
  For a local variable, the name i conveys as much information as 
  index or idx and is quicker to read. Similarly, i and j are a 
  better pair of names for index variables than i1 and i2 
  (or, worse, index1 and index2), because they are easier to
  tell apart when skimming the program. Global names must convey
  relatively more information, because they appear in a larger
  variety of contexts. Even so, a short, precise name can say more
  than a long-winded one: compare acquire and take_ownership. 
  
  Make every name tell.
Variables should generally have short scope (we don't want a lot of global, or even package level variables). So _variable names_ in particular should be short.
Re:Practical Go: Real-world advice for writing maintainable ... by bpicolo on Thursday February 21, 2019 @09:13PM (#19222544)
> For a local variable, the name i conveys as much information as index or idx and is quicker to read

This is only true because i is a specific, common abbreviation for index. When writing arbitrary glue code, a single letter variable would be a meaningless abbreviation without shared context. If you encounter "i" and it doesn't mean "index of a for loop", you're going to be taking additional time parsing meaning.

Re:Practical Go: Real-world advice for writing maintainable ... by 12298765 on Friday February 22, 2019 @02:03AM (#19223662)
An example where I disagree, and use 1-letter names daily: arrow functions in both Java and JS.

`usersList.stream().forEach(u -> someSet.add(u))`

It's immediately obvious that u is a user in usersList. I realize that it's debatable if u is really more readable than spelling out user, but I prefer it, and I don't think anyone is going to be confused by it. If the chain does get really long, also, I will spell it out explicitly.

Re:Practical Go: Real-world advice for writing maintainable ... by irishsultan on Friday February 22, 2019 @05:16AM (#19224273)
Shouldn't you be able to write that as `usersList.stream().forEach(someSet.add)`

For Javascript at least that would work.

Re:Practical Go: Real-world advice for writing maintainable ... by leshow on Friday February 22, 2019 @09:04AM (#19225347)
I haven't written Java since like java 5, but I believe java 8 has syntax for this as well:

`usersList.stream().forEach(someSet::add)`

Re:Practical Go: Real-world advice for writing maintainable ... by bpicolo on Friday February 22, 2019 @09:49AM (#19225746)
Sure, for a lambda I think it’s arbitrary. For larger functions / classes it matters
Re:Practical Go: Real-world advice for writing maintainable ... by arvinsim on Thursday February 21, 2019 @09:43PM (#19222680)
I disagree. I am pretty sure that there's some code that is short and simple but you want to have descriptive names anyway like financial related computations.
Re:Practical Go: Real-world advice for writing maintainable ... by coldtea on Friday February 22, 2019 @12:40AM (#19223392)
>I generally find if you need multi letter variable names it means your function or scope is to long, or manipulating to many things. It's a nice little red flag for me.

Many times your function should be longer, rather than shorter.

Short methods and functions used just for the sake of being short just move the complexity of understanding in the interaction between them, making logic harder to follow an algorithm when it could have been all in the same place (for related functionality of course, I don't advocate having a function do 2 different irrelevant things).