Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Are hyphens and/or underscores valid in golang package names?

+2
−0

Can a Go package name validly contain a hyphen and/or an underscore?

The godocs say that

By convention, packages are given lower case, single-word names; there should be no need for underscores or mixedCaps.

However, this does not indicate if underscores are invalid/illegal vs. simply not following the convention, and it says nothing about hyphens.

Similarly, I searched for "hypen" and "underscore" in a blog post on Go package names and found nothing about hyphens. There was an example with an underscore in a package name with an introductory comment indicating that it does "not fit well in Go," but again does not indicate whether or not it is invalid.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+1
−0

Disclaimer: I don't know Go. This is all just me reading the specification.


In the Go specification under Packages, it defines PackageName.

PackageName    = identifier

Under Identifiers

identifier = letter { letter | unicode_digit } .

Under Letters and digits

letter        = unicode_letter | "_" .

Underscores are therefore legal, according to the spec.

Under Characters, it says what constitutes a unicode_letter and unicode_digit.

unicode_letter = /* a Unicode code point classified as "Letter" */ .
unicode_digit  = /* a Unicode code point classified as "Number, decimal digit" */ .

In The Unicode Standard 8.0, Section 4.5 "General Category" defines a set of character categories. Go treats all characters in any of the Letter categories Lu, Ll, Lt, Lm, or Lo as Unicode letters, and those in the Number category Nd as Unicode digits.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »