Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



> > 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.)


The term “receiver” comes from Smalltalk: http://www.bitsavers.org/pdf/xerox/parc/techReports/SSL-76-6...


That makes sense. I just about figured it would. :-)


> 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.


Method? Serialize?


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.


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.


> (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.


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.


> Alan Kay used it, Smalltalk used

So Alan and the language he helped create. That’s double counting the sample of 1


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


> 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


They said “in other languages with classes”. They are comparing to a common code review but/gripe in other languages besides Go.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: