News for hackers. Stuff that matters.
Re:Google’s Go Style Guide by bpicolo on Friday November 18, 2022 @10:01AM (#33655674)
I just use reader//req. Code is instantly easier to read for me personally and no time has been wasted.

It's all preference, of course.

Re:Google’s Go Style Guide by kevmo314 on Friday November 18, 2022 @01:32PM (#33659507)
Sometimes you run into packages called reader which makes for a less fun time using variable names that are also words.
Re:Google’s Go Style Guide by rlabrecque on Friday November 18, 2022 @01:56PM (#33660062)
This is much nicer for other people coming into this. It's the same problem with spoken language and slang, slang is better if you know it, worse if you don't.
Re:Google’s Go Style Guide by dimitrios1 on Friday November 18, 2022 @02:16PM (#33660460)
Sorry to be pedantic (well, not really it's M.O. for a hacker news commentor after all, isn't it?) , but as someone who knows a few languages, slang is not an issue with spoken languages at all. You learn a language by full immersion with other speakers, who impart that knowledge unto you. Unless all you are doing is conversing with grammaticians and newscasters, you will pick up on regional and local differences, euphemisms, and slang.
Re:Google’s Go Style Guide by shepherdjerred on Friday November 18, 2022 @02:47PM (#33660981)
I don't believe so.

Imagine you're new to Go and you haven't mentally mapped all of these abbreviations. What would you rather read, `r` or `reader`?

Re:Google’s Go Style Guide by jrockway on Friday November 18, 2022 @03:02PM (#33661219)
Designing an API that "stutters" is a very common mistake that many programmers make. reader.Read() is pretty jarring.

There is also nothing wrong with naming variables after what they're for instead of what they are. Consider io.Copy(dst, src). That's nicer than io.Copy(reader1, reader2).

Re:Google’s Go Style Guide by pindab0ter on Friday November 18, 2022 @04:32PM (#33662584)
But not necessarily nicer than io.Copy(destination, source).
Re:Google’s Go Style Guide by shepherdjerred on Friday November 18, 2022 @07:17PM (#33664999)
Sure, so call your reader `file` or `network` or `stream`. Don't call it `r`. Nobody is charging you by the character.

It isn't a huge deal when the code is simple, e.g. you create a reader named `r` and in the next line you use it. That's easy to understand. The problem is that the pattern propagates. A few more lines of code are added, the reader is still named `r`. It's name `r` here, so we start putting it in a struct as `r`. Soon enough the codebase is littered with instances of `r`. Not great.