Hacker News new | ask | show | jobs
by ChrisMarshallNY 2267 days ago
Cool story.

I use Swift. It does not have default switch fallthrough. After a couple of versions, I learned about the fallthrough statement.

I remember being frustrated by it, at first, but, like so many Swift oddities, it rapidly became second nature; thus, proving out that one of the goals of Swift is to train developers to write code properly.

2 comments

Go also has the same behaviour, with the fallthrough keyword. I find myself using a switch so rarely anyway...
Go has a fallthrough keyword, but you can also do case "a", "b": for simple things where two cases are the exact same.
Swift allows the same thing. In fact, Swift switch statements are powerful as all git-go. You can do things like specify ranges and whatnot.

https://littlegreenviper.com/miscellany/swiftwater/ranges-an...

https://docs.swift.org/swift-book/LanguageGuide/ControlFlow....

That said, I don't use them that often. They tend to take up a lot of real estate on the screen, and introduce a fair bit of CC.

I thought the first release of Swift had fallthrough?
Maybe it did, but I didn’t learn about it for quite some time. I just learned to work around it.

Swift is a deep river. I still learn new stuff every day, and I write Swift, seven days a week.