When writing a single package intended to be used as a command that is idiomatic: call all identifiers private or call all identifiers public?

In Go, public names begin with an uppercase letter, and private names begin with a lowercase letter.

I am writing a program that is not a library and is a single package. Are there any Go Idioms that determine if my identifiers should be public or private? I do not plan to use this package as a library or as something that should be imported from another Go program.

I can’t think of any reason why I need a mixture. He "feels" as if everyone is private - this is the right choice.


I don’t think I have any specific answer, but Nate was the closest, telling me that I think of “export and non-export” instead of “public and private”.

This makes me think that not exporting anything is best. In the worst case, if I end up importing code from my application into another package, I will have to rethink what needs to be exported and what should not be. Which is good, IMO.

+5
source share
3 answers

If you are trying to make your thinking more idiotic, you should stop thinking about variables, functions, and methods, both public and private. A more precise term is exported or not exported. He definitely likes C.

, . , . . :

projectgopath/src/projectname
                  projectname/subcomponent1
                  projectname/subcomponent2

. , . . ...

go go go install, , . ​​ .

+3

, . camelCase , .

+2

go , .

, , (, ) , ( ) , ( , struct).

+1

All Articles