Hey all,
I used to be excited about golang naming syntax, as everyone knows that higher or decrease case initials change the visibility of capabilities and variables.
As there isn’t a strict commonplace for golang, I usually use snake case. It’s a private choice. I used to love camel/pascal case after I programmed in Java, however again there higher or decrease case initials have been strictly outlined. If I might select to make use of camel case in Go I’d usually write a “get” operate as GetStuff()
in order that it’s public, versus the getStuff()
that will have been applied in Java. Personally, GetStuff()
kinda damage my eyes.
In Python we may effortlessly implement a public operate get_stuff() or a personal _get_stuff()
, which isn’t fairly, however it’s okay.
Attending to the purpose: in Golang, if I select to make use of snake case, then a personal operate would appear to be get_stuff()
. Consequently, a public one can be named Get_stuff()
, which appears like a snake with a big head. It’s bought me pondering: shouldn’t we name this one a “cobra case”?
Idk how helpful this subject can be, however “cobra case” bought me in a very good temper .
Finest needs to all of you!
There isn’t any official commonplace afaik, however idiomatic code makes use of CamelCase (have a look at the usual library as an illustration).
You are able to do no matter you need in your code (nobody will cease you), however I are likely to keep away from packages that deviate, for no different cause than the creator possible doesn’t know the usual library effectively and subsequently most likely not golang effectively both.
Naming issues is difficult
However personllay I’ve no extra situation with Golangs method of doing it.
I usually do named imports that can be on this case:
package deal.GetStuff()
And what I do for myself is structs with a T on the finish.
so as an alternative of sort Stuff struct {} I do StuffT struct and I comply with the identical in typescript frontend. Thus I all the time know what’s the sort definition and what an precise struct.