[swift-evolution] Enums and Source Compatibility - defaults

Tino Heth 2th at gmx.de
Sun Aug 13 02:25:44 CDT 2017

> Say we split up Foundation's enums roughly into categories. You have your policies (NSURLCacheStoragePolicy, NSDateFormatterStyle), states/answers (NSURLSessionTaskState, NSQualityOfService), and, well, lists (NSSearchPathDirectory, NSStringEncoding). Given those, I’d say protocols, generics, and zero-cost abstractions are frequently a better choice (but not always). For instance, IMHO a closed protocol better models commonly-used styles.
I agree a lot that enums are not nearly as useful as they seem at first sight, and I know I'm not the only one who started with an enum-based solution and realised later that it doesn't work out as expected.
But I didn't encounter that with enums in Foundation — obviously, because I'm not writing Foundation code ;-), so could you give some concrete examples where the different alternatives would be a better fit?
My experience is that enums loose their appeal quickly when you want to attach behaviour or properties to the different cases… but I think closed protocols would also be just a workaround, inferior compared with case classes and ad-hoc union types. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170813/16a1277d/attachment.html>

More information about the swift-evolution mailing list