10 Tips to become a better Swift Developer
Bob Lee
2.3K45

// Beautiful Code
enum People { case adult, child, senior }
switch People.adult {
case .adult: print("Pay $7")
case .child: print("Pay $3")
case .senior: print("Pay $4")
default: print("You alive, bruh?")
}

This was a good read, thanks for putting it together, Bob Lee. This switch statement stuck out to me. Since it’s switching on People.adult it’ll never hit any of the other cases. Seems to me it should read more like this:

enum People { case adult, child, senior }
let person = People.adult //or some func that produces a People var
switch person {
case .adult: print("Pay $7")
case .child: print("Pay $3")
case .senior: print("Pay $4")
default: print("You alive, bruh?")
}
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.