Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
There is only one convention I'm aware of in Golang for interface name - suffix single func interfaces with their method name plus "er". I've also noted another - Interface. As a package can only have one type with a name, I infer that it must be intended as the primary interface to the package - you could call this the "package interface".
My is there another reason?
Naming an interface type Interface isn't a convention–it's only used once in the standard library: sort.Interface.
Maybe the name Interface isn't the best or most intuitive one–Sortable would be more intuitive–but I guess the Go authors chose that name because together with the package name it is still better: sort.Interface vs sort.Sortable (the latter repeats sort).
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am using GoLand IDE for Golang development. Just wondering if there is a way to find the list of functions implemented for a given struct or a type?
Just found out, it is CTRL+Q (cursor on the type) to get the list of functions for a given type or struct.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
Which name is better, repository.UserRepository or repository.User?
I'm thinking about naming recently.
I have referenced several sources and they are talking.
Think about the context and name it.
Here is the link.
https://talks.golang.org/2014/names.slide#2
https://github.com/golang/go/wiki/CodeReviewComments
Additionally, Can you also recommend a project that can be referred to when creating an http server?
according to the golang official ducument
The importer of a package will use the name to refer to its contents, so exported names in the package can use that fact to avoid stutter. (Don't use the import . notation, which can simplify tests that must run outside the package they are testing, but should otherwise be avoided.) For instance, the buffered reader type in the bufio package is called Reader, not BufReader, because users see it as bufio.Reader, which is a clear, concise name. Moreover, because imported entities are always addressed with their package name, bufio.Reader does not conflict with io.Reader.
repository.User may be good then repository.UserRepository
the package in src/encoding/base64 is imported as "encoding/base64" not "encoding/base64Encoding"
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have a Go package that declares and uses some constants in file1.go. Now I add a new file to the package, file2.go, which refers to constants in file1.go.
Would you move the shared constants into a new file, like consts.go, since they don't "belong" to one file or the other? Or do you leave them in file1.go and assume that someone looking at file2.go can use their IDE or editor or grep to locate the shared constants?
Using const.go file is an idiomatic way, see Go standard library.
For example see: math/const.go
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Why people use only one character to represent the current instance in method of struct? Example:
type Something struct {}
func (s *Something) doSomething() {}
I find more readable to use:
func (something *Something) doSomething() {}
It's just good practice to follow rule that name should be short and concise (more info).
Also the point here is to avoid a way long names and generic names such as "me", "this" or "self" (more info).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Is it best practice to access module methods with a dot (.) or the scope resolution operator (::)?
I know both work and I understand the purpose of ::, I would just like to know which to favour when accessing module methods and why.
Note: There is a related question here which goes into this topic, but not into which is better form.
Both work but the Calling Methods docs suggest that you should use :: for namespaces:
You may also use :: to designate a receiver, but this is
rarely used due to the potential for confusion with ::
for namespaces.