While we are used to it, prefixing static members and enumeration constants with dots introduces visual noise, looks like a too clever hack and always amazes my colleagues from other languages' backgrounds:
func foo(_ v: Color) {...}
object.foo(.red) // 🤔
There's also this disturbing asymmetry between the absence of dot prefixes in declarations:
enum Color {
case red
case green
static var blue = ...
}
and having those prefixes elsewhere:
switch color {
case .red: break
case .green: break
}
foo(.red)
foo(.blue)
Interestingly I can already use "object.foo(red)" in some contexts (e.g. when in a static method of Color) but not others.
I appreciate this would be a breaking change and no way we could possibly fit this change in swift at this stage. Forgetting that for a moment, do you think that Swift would have been better off or worse with the following change?
func foo(_ v: Color) {...}
...
object.foo(Color.red) // ok
object.foo(.red) // 🛑 prohibited
object.foo(red) // âś…
switch color {
case .red: break // 🛑 prohibited
case red: break // âś…
}
dispatchPrecondition(condition: .onQueue(.main)) // 🛑
dispatchPrecondition(condition: onQueue(main)) // âś…
bar(.init()) // 🛑
bar(init()) // âś…
// While choosing what "red" to use – follow these new resolution rules:
// - use local variable if exists
// - or use instance variable if exists (in which case self should be captured strongly explicitly or implicitly)
// - or use static variable if exists (in case of enum could be an enumeration constant)
// - or use global variable if exists
// - otherwise emit an error