[swift-evolution] Swift case conventions for Enums

Jonathan Hise Kaldma info at hisekaldma.com
Tue Dec 22 05:50:25 CST 2015


-1.

Please don't change the guideline. It's good as it is.

First, there's an important precedent for UpperCamelCase enums in other languages that Swift has some kinship with, e.g. C#, Rust, and Scala. People coming to Swift from these languages immediately feel at home with the current guideline.

Second, there's an even bigger precedent for treating enums differently from other identifiers. In languages where UpperCamelCase isn't the rule, e.g. C, C++, and Java, the practice is often to name enums using UPPERCASE. This says something about how people see enums: as something that should stand out. Making them lowerCamelCase goes against this.

Finally, using UpperCamelCase makes enums much more readable when used with Swifts's ability to infer the enum type. It's immediately clear that this is an enum:

suit = .Hearts

But it's not so clear what this is:

suit = .hearts

What is hearts? Is it a property? Where does it come from? This makes the language harder to learn and harder to read.

Consistency should be a goal when it aids clarity and readability. In this case, it would make code less clear and less readable, and it would go against established practice.

/Jonathan

> 22 dec. 2015 kl. 03:38 skrev Dave Abrahams via swift-evolution <swift-evolution at swift.org>:
> 
> 
>> On Dec 21, 2015, at 3:58 PM, Michael Wells via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> I love that Swift has a published API design guidelines at https://swift.org/documentation/api-design-guidelines.html, but one thing about it bugs me: the use of UpperCamelCase for cases. I know this ship has long sailed,
> 
> It has not sailed at all.  This is totally open for discussion.
> 
>> but why didn't the team choose lowerCamelCase for these? The current style seems inconsistent and requires an “instances are lowerCamelCase, aside from Enums” clarification.
>> 
>> -mw
>> 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> -Dave
> 
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151222/73262ca7/attachment.html>


More information about the swift-evolution mailing list