# Swift Package Naming Conventions

**URL:** <https://forums.swift.org/t/swift-package-naming-conventions/33931>\
**Category:** Package Manager\
**Created:** [February 19, 2020, 12:15pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931 "2020-02-19T12:15:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaishin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kaishin/32/10616_2.png) [@kaishin](https://forums.swift.org/u/kaishin)\
**Post date:** [February 19, 2020, 12:15pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/1 "2020-02-19T12:15:03Z")

</div>

Hi,

I spent some time asking package maintainers and searching these forums, but I didn't find a satisfactory answer to my question: _are there any package naming conventions/guidelines for SPM packages?_

Some background:

As someone who values consistency, I've been paying closer attention to how package authors name their packages in the manifest. I've looked at official packages, SSWG packages, iOS/macOS packages, etc. To clarify, I am referring to the `name` property of the `Package`, not products or targets.

Here's what I found:

- Some packages use _dash-case_ (aka kebab-case). Notable examples: `swift-driver`, `swift-numerics`, `swift-log`, `swift-crypto`, and `swift-nio`. Other that fall into this group are SSWG packages and the new standard library preview packages.
- Some packages use _CamelCase_. Notable examples: `SwiftPM` itself, `SourceKitLSP`, and `SwiftSyntax`. Almost all iOS/macOS packages follow this convention.

I understand if this detail is considered trivial or irrelevant, especially since package names play a much lesser role compared to other package managers such as `npm` ([link](https://docs.npmjs.com/files/package.json#name)). It is also worth noting that this situation is not unique to SPM and can be found in other ecosystems, such as [Rust](https://rust-lang.github.io/api-guidelines/naming.html), where `snake_cased` and `dash-cased` crate names are both widely used (although the latter is gaining more momentum).

At the same time, I think that with the eventual introduction of a package registry (GitHub's or otherwise), these naming inconsistencies are going to surface to the end user much more than they do today.

Is the absence of SPM package naming guidelines by design? If so, can someone shed some light on this?  
If it is not, would it make sense to pursue converging towards one convention? Could it happen organically or should it be enforced on the manifest level?

---

<div class="post-metadata">

**Author:** ![Alejandro\_Martinez](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro_martinez/32/821_2.png) [@Alejandro\_Martinez](https://forums.swift.org/u/Alejandro_Martinez)\
**Post date:** [February 19, 2020, 2:23pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/2 "2020-02-19T14:23:11Z")

</div>

Good question! Thanks for opening this thread.

IMHO I prefer _CamelCase_. That's what the modules are usually doing, so you can `import CamelCase`, and I prefer when a package name is the same as the module name.

EDIT: My comment was referring to this [SE-0226: Package Manager Target Based Dependency Resolution](https://forums.swift.org/t/se-0226-package-manager-target-based-dependency-resolution/15404) but reading it again I'm not sure it applies. Sorry for that.

---

<div class="post-metadata">

**Author:** ![Mordil](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mordil/32/5840_2.png) [@Mordil](https://forums.swift.org/u/Mordil)\
**Post date:** [February 19, 2020, 6:55pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/3 "2020-02-19T18:55:34Z")

</div>

I appreciate these threads popping up!

In general I follow the pattern established by `swift-nio`, `swift-numerics`, etc, but I'm beginning to agree with @Alejandro_Martinez that the Package name should be `PascalCase` and match the first/primary product, to be closer to what the first expected `import` statement would be.

I also realize that I'm not entirely consistent:

- Package: `redi-stack`  
Repo: `swift-redi-stack`  
Primary Product: `RediStack`
- Package: `swift-currency`  
Repo: `swift-currency`  
Primary Product: `Currency`

I think the primary goal of pattern I followed was to associate strongly between the git URL and the project name. But as you say, it'll become more apparent at how redundant or "off" this will look as soon as a Swift Package Index is off the ground.

> Is the absence of SPM package naming guidelines by design?

The fact that we need a unique package name, git URL, and target / product names is by design and influenced by technical limitations (that existed at least initially).

A lot of SPM's design is also geared towards decentralization and being unopinionated where it doesn't matter - such as how to actually name your project or structure it.

> If it is not, would it make sense to pursue converging towards one convention?

Of course! Having established conventions makes it _easier_ for someone to jump into an ecosystem, as they understand how to contribute or even _search_ for what they need.

> Could it happen organically or should it be enforced on the manifest level?

I think it should _not_ be enforced at the manifest level. This is highly a preference thing, and way less a technical thing. Our build and package tools don't care about what we name our projects - they could just be SHA hashes - and everything would continue to work the same.

---

<div class="post-metadata">

**Author:** ![pvieito](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/pvieito/32/33613_2.png) [@pvieito](https://forums.swift.org/u/pvieito)\
**Post date:** [February 19, 2020, 7:17pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/4 "2020-02-19T19:17:54Z")

</div>

I think we should follow the style used by the vast majority of packages:

- Repo: `https://example.com/user/ExampleKit.git`
- Package: `ExampleKit`
- Product: `ExampleKit`

I understand why Apple uses the other approach to namespace their packages, but I think it would be a lot better to have them use this style, ie:

- `https://github.com/swift/Foundation.git`
- `https://github.com/swift/XCTest.git`
- `https://github.com/swift/NIO.git`
- `https://github.com/swift/Crypto.git`
- `https://github.com/swift/Logging.git`  
...

---

<div class="post-metadata">

**Author:** ![bzamayo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bzamayo/32/764_2.png) [@bzamayo](https://forums.swift.org/u/bzamayo)\
**Post date:** [February 19, 2020, 7:54pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/5 "2020-02-19T19:54:59Z")

</div>

Also, something that is becoming a factor with the introduction of the new package dependency resolution stuff in SwiftPM 5.2, is that a client package needs to declare the name of a product dependency explicitly _unless_ it matches the last path component of the URL. Whereas before the URL didn't really matter, now choosing it to match the product name brings a functional convenience for users of the package.

---

<div class="post-metadata">

**Author:** ![kaishin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kaishin/32/10616_2.png) [@kaishin](https://forums.swift.org/u/kaishin)\
**Post date:** [February 24, 2020, 9:58am UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/6 "2020-02-24T09:58:19Z")

</div>

> [@bzamayo](#):
>
> Whereas before the URL didn't really matter, now choosing it to match the product name brings a functional convenience for users of the package.

I haven't considered the URL when I initially posted this, but there are other aspects to account for when it comes to that. Since many packages are composed of 2 words or more, dash-case makes for better URL readability, especially with URL case-insensitivity being a factor. Not the main concern, but one to keep in mind.

That being said, I am starting to believe that the pros of using CamelCase across the board, including the URL, outweigh the cons.

---

<div class="post-metadata">

**Author:** ![phoneyDev](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@phoneyDev](https://forums.swift.org/u/phoneyDev)\
**Post date:** [February 25, 2020, 12:05am UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/7 "2020-02-25T00:05:56Z")

</div>

Just to be clear: UpperCamelCase and lowerCamelCase. Swift classes use the former and variables use the latter.

---

<div class="post-metadata">

**Author:** ![jonprescott](https://avatars.discourse-cdn.com/v4/letter/j/e36b37/32.png) [@jonprescott](https://forums.swift.org/u/jonprescott)\
**Post date:** [February 25, 2020, 12:53am UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/8 "2020-02-25T00:53:23Z")

</div>

I would say that it is a popular convention, but, not a requirement. The compiler accepts any set of cases.

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [February 25, 2020, 1:30am UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/9 "2020-02-25T01:30:04Z")

</div>

> [@kaishin](#):
>
> with URL case-insensitivity being a factor

FYI: Only the domain portion of a URL is case‐insensitive; the path is not. (But if you get lucky and the server happens to have its file system configured to be case‐insensitive, you may not notice the difference.)

---

<div class="post-metadata">

**Author:** ![kaishin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kaishin/32/10616_2.png) [@kaishin](https://forums.swift.org/u/kaishin)\
**Post date:** [February 25, 2020, 3:16pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/10 "2020-02-25T15:16:41Z")

</div>

> FYI: Only the domain portion of a URL is case‐insensitive; the path is not. (But if you get lucky and the server happens to have its file system configured to be case‐insensitive, you may not notice the difference.)

That's correct. I was looking at GitHub when I wrote that, and their repo URLs are case-insensitive based on my own tests.

---

<div class="post-metadata">

**Author:** ![capnslipp](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/capnslipp/32/10716_2.png) [@capnslipp](https://forums.swift.org/u/capnslipp)\
**Post date:** [February 28, 2020, 12:23am UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/11 "2020-02-28T00:23:56Z")

</div>

Would it be non-Swift-idiomatic or out of scope to consider having SwiftPM consider alternate casing/word-breaking package names as the same name? I.E. To grab or interact with the SwiftSyntax package, a user could type "SwiftSyntax", "swiftSyntax", "swift-syntax", "swift\_syntax", etc.

Implementation-wise, we'd need 2 things: 1. a simple spec for how word breaks are determined (for which there's plenty of precedence in the Obj-C & Swift docs and community), and 2. a way to check for similar package names (internally normalizing all names to a standard form, say hyphen-separated words, and then doing checks and comparisons only on normalized names seems easy and efficient enough).

---

<div class="post-metadata">

**Author:** ![kukushechkin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kukushechkin/32/10940_2.png) [@kukushechkin](https://forums.swift.org/u/kukushechkin)\
**Post date:** [March 20, 2020, 1:24pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/12 "2020-03-20T13:24:43Z")

</div>

What about 3-letters prefixes for modules, like we do it in Objective-C world? Should SPM module be named ABCCoolThing and, e.g. contain ABCCoolThing class, or module should be named CoolThing and class be ABCCoolThing or even class should be CoolThing. What about names collisions?

---

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [March 20, 2020, 1:48pm UTC](https://forums.swift.org/t/swift-package-naming-conventions/33931/13 "2020-03-20T13:48:31Z")

</div>

IMO, the best way to avoid name collisions for modules is to add structure to the name. We could use a reverse URL structure like Java, allowing for simple vendor prefixes which may be omitted if the desired module is unambiguous.
