3 ms·
It does not have features that often lead to bugs. E.g. the switch statement does not allow fall through and enforces a default case.
by orkoden 12y ago
It does not have features that often lead to bugs. E.g. the switch statement does not allow fall through and enforces a default case.
- m_mueller 12y agoThe lack of fall through makes me a bit sad since I think that it's a very powerful programming construct and it usually only hurts people new to the concept - but of course one can live without it.
- mantrax5 12y agoThree things. First of all, while you can't do this: case val: case val: case val: ... You can do this in Swift, which does the same thing: case val, val, val: ... Second, you can fall through in Swift, but you need to ask for it: case val: ... fallthrough case val: ... So don't be sad. And third... Seriously now, it's a "very powerful programming concept"? I bet 9 times out of 10 you use this very powerful programming concept in other languages, you did it by accident, not because you needed its pawa.
- m_mueller 12y agoThanks for the clarification on how to use it in Swift - like this it's indeed the perfect solution by enforcing it to be explicit. Having multiple cases rolled into one is also a very nice option. The snark wasn't really called for though. No, I don't 'use' it by accident, that would in most cases just become a bug. I use it when it makes code more concise rather than having nested ifs. Consider for example ACL rules where you set different privileges by default according to an access level.