nn
represents. Ready, Go!"Egon,
"Your task is to look at the first line after the function signature in order to discover what the variable namednn
represents. Ready, Go!"
// WriteString writes a string.
// It returns the number of bytes written.
func (b *Writer) WriteString(s string) (int, error) {
nn := 0
// . . .
return nn, nil
}
nn is the number of bytes written.
That was easy!
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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.
n := copy(w.buf[w.pos:], s)w.pos += ntotal += n
chunkLength := copy(writer.buffer[writer.unflushedBytes:], input)writer.unflushedBytes += chunkLengthtotalBytesWritten += chunkLength
Wow. Reading the comments here is a little depressing. The post in question isn't really about bufio. The example he picked is just that—an example, but it's a good candidate to pick on.
The author isn't advocating a massive rewrite of the entire Go codebase. He's not going to submit a pull request or anything like that. What he's advocating is better naming.
He's making the point that compilers don't care about names and the length of the names. The resulting compilation doesn't care if your names are nn or total, so why not use total to begin with? To save a few bytes or a few keystrokes? So instead of naming a function fbn why not name it fibonacci? Doesn't that more clearly communicate the meaning? Sure, if you're not familiar with fibonacci then there's some additional overhead. But fibonacci is infinitely more Googleable than fbn.
30 years ago, fixed-width screens were the norm and so were rotary phones. Going over 80 characters on a line was a very big deal (this is a carry over from the punch card days from even before that). Just because you've done something for 30 years doesn't justify it's continued use. My 75-year-old parents still want to use rotary phones and are completely inept at cell phones. Is there any doubt today that using rotary phones is a thing of the past? These conventions are from a bygone era and the limitations that caused them have fallen away.
Everyone is talking about familiarity. If you want to get familiar, why not use the English language? Using English words imposes far less mental mapping than cryptic variable names such as fg or pp or what have you like minifiers and obfuscators do. Granted, programers who have limited English skills may have trouble, but that's another topic. Then again, if the variable name is a contrived acronym for something, it may be easier to read a full English word which can be punched into an online translator. A few years back I worked with a small outsourcing team in South America who delivered the source code to us in Spanish. I could easily read Spanish but others on my team couldn't. Were others on my team irresponsible or amateur because they had trouble understanding the code? No. They had trouble reading the names and the names conveyed a meaning they couldn't decipher. Don't even get me started on Japanese source code. Good luck reading that unless you read Japanese. If you really want to be concise and brief, method names and variable names could be single-character Japanese runes. That would make the source code files much more compact, but you would spend all day deciphering code rather than making improvements to it.
Of course you want to have correct code and good algorithms, but you always want to have those. They're a baseline for deliverable code. The post already mentions this.
The entire point of the post is this: When choosing between brevity and clarity, choose clarity—clarity of thought and expression that conveys meaning and understanding to those who maintain the codebase. Saving a few keystrokes is often at odds with this ideal.
He's making the point that compilers don't care about names and the length of the names. The resulting compilation doesn't care if your names are nn or total, so why not use total to begin with? To save a few bytes or a few keystrokes? So instead of naming a function fbn why not name it fibonacci? Doesn't that more clearly communicate the meaning? Sure, if you're not familiar with fibonacci then there's some additional overhead. But fibonacci is infinitely more Googleable than fbn.
The entire point of the post is this: When choosing between brevity and clarity, choose clarity—clarity of thought and expression that conveys meaning and understanding to those who maintain the codebase. Saving a few keystrokes is often at odds with this ideal.
I'm not the author of package bufio but I have made changes to it.I personally didn't find the short names to be a problem, but they are short. I can see why some people might have an issue with them.As a matter of course we don't refactor standard library code without good reason.The bufio code has been in use for years now.Let's leave it alone.