hnlmorg 11 hours ago

I’ve worked with people who raised comments like these in PRs and they were a nightmare: always arguing, never listening to anyone but themselves, and generally full of ego. Good developers but often slow to deliver too.

If you’re focused on what character of “GitHub” or “oauth” should capitalised in a variable name, then you really are focusing on the wrong problems of software development.

  • theshrike79 16 minutes ago

    A project should have an .editorconfig setup that automatically hints or enforces the correct code style in the IDE.

  • B-Con 10 hours ago

    There is value in having local consistency, which is usually achieved through having rules.

    The more uniform a code base, the easier it is to breeze around and get stuff done. Naming things is already hard, so having rules around the annoying bits is nice.

    • theshrike79 17 minutes ago

      Rules are best handled by automated tools with as few configuration options as possible - like gofmt or black.

      This way people won't start bikeshedding about the placement of curly braces, they either accept the style or move on.

      It also prevents things from getting political or personified. It's the tool that's making the decisions, not a specific person.

    • hnlmorg 2 hours ago

      These rules aren’t really about naming things, which I agree is hard. It’s pedantry around terms that really don’t matter which way you choose and thus are categorically not “best practices” let alone “idioms” one must abide by.

      If the author really cares this much then they should be linter rules instead of a blog post.

  • donatj 5 hours ago

    I don't know, code that isn't at least internally consistent with itself in capitalization is a pet peeve. There should be one way to do a thing.

    • hnlmorg 2 hours ago

      When is agree when talking about all caps terms like HTTP or even just camel case verses snake case. But it’s really scraping the barrel of usefulness when you’re debating whether the H in Github or A in OAuth is capitalised.

      Just write a linter rule and be done already.

rs186 11 hours ago

I'm afraid this is a waste of everybody's time.

> Avoid unused method receiver names

That's just "don't create a non-static method if you don't use 'this'" in other languages with classes. Which is not a bad idea, but hardly matters. If someone realizes that it's difficult to add a unit test for the function, they'll fix it themselves. Maybe the real question is: did the code author create a unit test for the function?

(P.S. I never understood why Go uses words like "receiver" and "marshaling" that are rarely used elsewhere)

> Empty string check

Sure, but that's just ordinary code smell, likely due to someone not thinking carefully over the code, which could be easily identified in a code review. If it's never found, it barely matters anyway. Is it really worth bringing this up?

Everything else seems unnecessarily boring, like the number of spaces between sentences. Most people I know write comments like how they write regular English sentences, like in emails. Other than a professor who is near retirement age, I don't know anyone who uses double spaces. It's so rare I don't see any point in mentioning it. And if someone did do this in the code, whether it's their style or by accident, I wouldn't even flag it in the code review. For what? Does anyone benefit from it? It's important to have consistency over fundamental things like tab vs space, but that quickly becomes meaningless bikeshedding.

My advice would be: write code using your common sense. Don't be obsessed with trivial things that don't matter. Use your time elsewhere -- push a new feature, fix a bug, add a unit test, or just relax.

  • tczMUFlmoNk 11 hours ago

    > > Avoid unused method receiver names

    > That's just "don't create a non-static method if you don't use 'this'" in other languages with classes.

    I don't think that's what's meant. It means to write `func (Receiver) Method()` rather than `func (r Receiver) Method()` when you don't use `r`. Sometimes you need this to implement an interface like `error` or `Stringer` and you just don't need instance data.

    (I'm no Go apologist but I think "receiver" is a great term. It's clear, it's applies to other languages and paradigms, and it doesn't really have an alternative that I'm aware of.)

  • adastra22 11 hours ago

    > P.S. I never understood why Go uses words like "receiver" and "marshaling" that are rarely used elsewhere

    What else are you familiar with? Those are extremely common terms in the object oriented community.

    • MooseBurger 10 hours ago

      Method? Serialize?

      • atombender 9 hours ago

        A receiver isn't a method. It's the "self" instance the method is invoked on. It's standard OOP terminology.

        I'm with you regarding marshaling, but not because it's not an industry-standard term, it's just that Go misapplies it. Marshaling historically has referred to describing a remote procedure call and its return value; for example, you call "CreateFoo()" with a "CreateRequest", the latter must be marshaled into a payload that the remote call can read. For a network call this requires serializing the data to bytes using some kind of format, but for a local call it could just be a pointer to a data structure. However, historically people have often mixed the two terms. Python's standard library also misuses "marshal" to refer to serialization.

        • adastra22 8 hours ago

          The history on marshaling goes back further than that. Smalltalk used the word more or less how it’s used in Go. There is definitely an RPC connotation these days though, probably because small talk was based on message passing.

  • mkl95 11 hours ago

    > (P.S. I never understood why Go uses words like "receiver" and "marshaling" that are rarely used elsewhere)

    Not sure about receiver, but marshaling has been part of Python's lingo for ages.

    • layer8 11 hours ago

      “Marshaling” became pretty ubiquitous as a term in the 1990s with CORBA and Microsoft OLE/COM.

    • cratermoon 11 hours ago

      The term 'receiver' has a long and distinguished history. Alan Kay used it, Smalltalk used the word almost exclusively. If Zoomers don't know their computer science history that's on them.

  • 38 11 hours ago

    > That's just "don't create a non-static method if you don't use 'this'" in other languages with classes

    Go doesn't have static methods. Regardless if you name the receiver, you have to provide an instance of the type to all methods. Maybe you should check your own knowledge before criticizing others

mjburgess 11 hours ago

> When reviewing Go code

This article reads as a parody of the worst sort of code review. This seems to be a person who sees themselves as little more than a regex engine.

Were I writing a go codebase in the UK, all spellings would be UK -- because of how absurd it would be to retrain the staff to split their brain on a trivial issue of this kind.

Likewise plurals do not matter, -- double spacing in comment sentences? I cannot imagine comment whitespacing being on the radar of any person one would wish to have as a team mate.

  • jrockway 11 hours ago

    Being consistent is the key. When you open up a codebase worked on by 50 people, it's nice when you can't tell who wrote it because of the spelling or whatever. Everyone on the team can see it, think "this looks like I wrote it", and work on it accordingly. That's a good thing.

  • Joker_vD 9 hours ago

    > Were I writing a go codebase in the UK, all spellings would be UK.

    What about if you were in Australia? Germany? Poland? Bulgaria? China?

    > how absurd it would be to retrain the staff to split their brain on a trivial issue of this kind.

    I've seen this argument used to argue that all the spellings in source code should be US English, always and everywhere. In my opinion, this (being able to use the same argument to argue both for and against the same issue) invalidates the argument entirely.

Mogzol 10 hours ago

The link in the "Error variable naming" section seems to directly contradict what the section says.

The link (https://go.dev/talks/2014/names.slide#14) says:

  Error values should be of the form ErrFoo:
  
  var ErrFormat = errors.New("image: unknown format")
But the page says:

  // But if you want to give it a longer name, use "somethingError".
  var specificError error
  result, specificError = doSpecificThing()
And also says:

  Don't do this:
  [...]
  var errSpecific error
  result, errSpecific = doSpecificThing()
So should error variables written like `errSpecific` or `specificError`? The go wiki says they should be written starting with `err`: https://go.dev/wiki/Errors#naming
  • DHowett 4 hours ago

    The advice in the 2014 talk applies to exporting specific types of errors as part of a package’s public API surface.

    The article, on the other hand, advocates for local variables storing errors not to have distinct names.

    • Mogzol 4 hours ago

      So a public variable error should follow different naming conventions then a local variable? That doesn't seem right, the go wiki says you should use the 'err' prefix for both (capitalized for public variables though, obviously)

      And I'm only asking about when you are giving an error a distinct name, not just naming it 'err'.

danw1979 11 hours ago

Pedantic Go more like…

“oAuth is not pretty” but “oauth” is ?

We’ve all had PRs reviewed by people like this and we know where it leads.

  • dlahoda 7 hours ago

    where it leads?

stevebmark 12 hours ago

Idiomatic Go is using shortened variable names, not what's in this article. I thought that was common knowledge and part of the Go ethos? I also wouldn't consider grammar in comments part of the language idioms? This is an unusual and very light take on Golang language idioms.

  • prisenco 12 hours ago

    My understanding is that shortened variable names are recommended for small, tight contexts (loops, short functions) but not generally.

    • cube2222 11 hours ago

      That and conventionally standard names, like r for request/reader, w for writer, etc.

      Agreed. Functions shouldn’t be full of short non-descriptly named variables.

      The longer the lifetime/scope of a variable, and the more variables there are, the more descriptive the names should be.

  • GauntletWizard 11 hours ago

    These are dang short compared to Java's FooBarBazBeanFactoryFuncClassImpl. The point you may be responding to is that "Short variable names" are themselves contextual. If you're doing a simple loop:

      for i := range personlist {
        person := personlist[i]
        ...
      }
    
    Is more readable than

      for personNum := range personlist {
        person := personlist[personNum]
        ...
      }
    
    because it makes clear that the i is basically irrelevant. The latter isn't bad style if you're three loops deep, because i, j, k is a bit harder to keep track of which is which.
callc 11 hours ago

I used Golang in a medium and large project. To anyone learning or thinking about learning Go, try it and ignore the online opinions.

I say this as someone who is simultaneously impressed by some parts of it, and gobsmacked at other parts.

Just ignore the dogmatic Gopher priests.

  • dlahoda 7 hours ago

    why ignorance is good?

    • euroderf 42 minutes ago

      Go is straightforward enough that fairly quickly you'll figure out how your own working style and coding style meld with it.

gnabgib 11 hours ago

(2016) Based on the comment/voting entries, first submitted here in 2018.. I wonder if the author feels the same 9 years later.

crackrook 8 hours ago

I'm not angry about it but the fact that Go uses capitalization for access control is just so silly to me. Like something a child might design when figuring out how to hide secrets in a note.

  • euroderf 40 minutes ago

    Strong disagree. Using capitalization for access control is ridiculously obvious and simple and clear. Sure, things like "Printf" look odd for a little while.

liampulles 10 hours ago

Here's the idiomatic Go style guide: accept whatever go format outputs. The fact that go formats code by default is one of the best things about the language. The whole point is that spending time either correcting whitespace (or even worse, arguing about how much whitespace to put) is an absolute waste of time and a comradery killer.

nickvec 10 hours ago

> Use singular form for collection repo/folder name

I’m confused by the examples in this section. Are they not identical?

  • pansa2 10 hours ago

    `player` vs `players` etc.

koakuma-chan 11 hours ago

It's the same language that "marshals" and "unmarshals" JSON and "dials" sockets.

  • tptacek 10 hours ago

    Dial is a Plan9-ism and it's hard to argue that it isn't a lot better than the BSD sockets interface.

porridgeraisin 12 hours ago

I love go and everything but this reads more like pedantic go, not idiomatic go.

  • mjr00 11 hours ago

    Yeah. And if you do care about this stuff, you shouldn't be reviewing it anyway; you should be setting up linter rules to enforce it automatically.

    • rs186 11 hours ago

      Exactly. Unless these are rules that are enforced during build, they are just "someone's opinions", regardless of how "correct" they are.

PhasmaFelis 11 hours ago

I am obsessively pedantic about grammar and spelling, in code and in English. I have a firm personal preference about how to spell "cancelled"--I like two Ls.

The only reason I'd ever consider telling someone that "canceled" is wrong is if the other spelling was firmly established in the actual codebase. Not in comments. And absolutely not with the ridiculous claim that the language you're coding in has opinions about how to spell your comments.

_jab 11 hours ago

[flagged]

  • tptacek 11 hours ago

    This article isn't about whether you like or don't like Go, which has been around for 15 years and whose merits have been debated, like those of literally every programming language, forever. We need to be careful about threads like these, because language war arguments spread like kudzu. Let's just try to talk about what this article is actually talking about.

    If you want to see an article about the shortcomings of some language discussed, write one.

    • LudwigNagasena 11 hours ago

      But those are far better topics for a discussion about idiomatic Go. I would rather see how to deal with lack of custom default values or error handling rather than how many spaces one should place after a punctuation mark.

      • tptacek 10 hours ago

        We can't be talking about code that is or isn't idiomatic Go if we're arguing about features people are unhappy Go doesn't have.

        • LudwigNagasena 9 hours ago

          That seems to be the exact context where we should be talking about idiomatic Go. You expect feature X and you are unhappy that Go doesn't have it because it's now harder to do Y. So here is an idiomatic Go way to do Y. Or that's why you should do Z in Go instead.

  • silisili 11 hours ago

    > I hate that forgetting to initialize all fields of a struct does not lead to an error, but will just fill in "zero-values" for those fields. This has bitten me many times, and zero-values are almost never the behavior I want.

    There's a linter for this you can easily integrate into your build or CI. Personally, having worked at a place with that as a CI rule, I'm the opposite. I felt annoyed having to explicitly set things I purposely didn't set. So I think it living as an optional linter is probably the right place.

    > I've found Golang's generics to be confusing and unexpressive.

    Same. Also with iterators.

  • B-Con 11 hours ago

    > I hate that forgetting to initialize all fields of a struct does not lead to an error, but will just fill in "zero-values" for those fields. This has bitten me many times, and zero-values are almost never the behavior I want.

    If empty values are biting you, you need constructors.

    There's definitely multiple ways to go about struct initialization, and Go had firmly chosen one approach. Best practice is to make the zero value of a field "useful", and to write a constructor function if you need it populated with any sort of conditional values.

  • catlifeonmars 10 hours ago

    Contrary to (probably) popular opinion, I find the concurrency model to be relatively poor. You get some cute primitives, but they come with a bunch of footguns. It’s really easy to spawn a green thread with `go <expr>`, which means it is easy to introduce deadlocks or race conditions.

    On the other hand, I find the syntax to be relatively simple and non-concurrent code to be straightforward and unsurprising.

levkk 11 hours ago

For a programming language that makes unused variables a compiler error, I'm surprised there is no clippy/rubocop/black/cargo fmt/clang fmt built-in.

  • Mawr 4 hours ago

    As far as I can tell every single one of those tools was inspired by Go's `gofmt` & `go vet` in the first place.

  • medhir 11 hours ago

    there is, gofmt :)