generic icon indicating copy to clipboard operation
generic copied to clipboard

Recommend to keep the visibility of the top-level identifiers

Open hjianhao opened this issue 9 years ago • 3 comments

If the new package starts with ".", All top-level identifiers will have prefixes to prevent conflicts, and their uses will also be updated.

for example, I use ".int" package name to generalize queue, the "New" function will rewrite to "intNew", this changed the visibility of the template function "New". If I used ".Int", it may changed the visibility of those identifiers started with lower case character. So I recommend to keep the visibility of the top-level Identifiers.

hjianhao avatar Jun 01 '16 07:06 hjianhao

I think this issue only applies to .result package target.

Do you have a suggestion to keep top-level identifiers to be exported while we still have prefixing?

For me, it is nice to have all top-level identifiers unexported:

  1. prefixed identifier name is ugly for exported API.
  2. Although it was exported, it might not be needed to be exported after rewrite under the new package.

If it is needed, I often create aliases in the current package in another file like:

func New() *IntQueue {
   return intNew()
}

taylorchu avatar Jun 01 '16 21:06 taylorchu

I think the simple rule is : if top level identifier start with lower case character, then Chang the prefix first letter to Lower case, vice versa.

hjianhao avatar Jun 02 '16 06:06 hjianhao

prefix in general should be all lowercase yyy. Could you explain more about your idea if the generic package has uppercase top-level identifiers, like Xxx? The current behavior is yyyXxx.

taylorchu avatar Jun 04 '16 03:06 taylorchu