I am working on a Swift library that is based on Java and C++ implementations, and a convention used in the existing implementations is to name all constants (static and class) in ALL_CAPS_AND_UNDERLINES, e.g., SOME_IMPORTANT_CONSTANT. The implementations otherwise follow CamelCase.
I would like, as a goal, for the Swift version of this code to conform to Swift API Design Guidelines as much as possible. The Swift guideline that comes nearest to addressing this is:
Follow case conventions: names of types, protocols and enum cases are
UpperCamelCase. Everything else is
lowerCamelCase.
If I follow this for the constants, they will all start lowercase, which makes them harder to distinguish as constants in code, e.g., someImportantConstant. I am considering the following alternatives:
- Break Swift convention and capitalize the constants, e.g., SomeImportantConstant
- Group as many of the constants as possible as enumerations (thereby deciding for me to capitalize them)
- Start constants with a lowercase "k" (harkening back to my MacApp days), e.g., kSomeImportantConstant
If you were to consider using a new Swift library based on an existing third party library, which convention would feel most natural to use? Would you have issues with or distrust the library if the library's public APIs used "k" in front of constants, or mixed ALL_CAPS_AND_UNDERLINES contants in its code?