In documentation, they use camel case and pascal case both. Is this convention different for functions and methods? Does it decide scope of a function ?
Yes. In Go a field/method is exported if it begins with an upper cased letter while it is unexported if the first letter of the identifier is lower cased. This is similar to the public/private features in most OO languages. Here's an example or two;
package "a"
func ThisFunctionIsExported() {}
func thisOneIsNot() {}
...
package "b"
import "a"
a.ThisFunctionIsExported() // works
a.thisOneIsNot() // compiler error
So, yes the developer is consciously deciding what the scope of those methods are with their casing choice. Lower cased functions are always helper methods inside the package scope, they aren't exposed in importing scopes.
I'm not sure an documentation on Go ever mentions "Pascal case". Supposedly you're using this term to denote camel cased name which begins with either a capital or small letter, right?
Okay, Go uses the term "camel case" for both variations. The distinction between the first letter of an identifier being capital or not does indeed govern the visibility of that symbol. Please read any entry-level guide on Go for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With