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).
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
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).
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
close() seems to be a reserved keyword for channels. Seems a bit strong to make it a built-in, when it could just be a method on a channel, no? Like when creating and closing a file?
I guess the same could be asked for len()?
close is a function that takes a channel as a parameter. Just like new and make, they are functions, and you can name local variables or functions like them.
Keywords are language constructs like struct, type, if, else ...
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 4 years ago.
Improve this question
I'm curios as to what this specific method is called:
public Word(String word) {
this._word = word;
}
Thanks in advance!
This is called a constructor. In this case, it would be for a Word object. It takes parameters to assign values to instance variables (in this case, the String word.)
Here is a link to the Oracle documentation on providing constructors in Java for further reference.
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.