D15694: Make implicit fallthroughs a compiler error, remove unneeded breaks
Aaron Puchert
noreply at phabricator.kde.org
Sun Sep 23 22:21:53 BST 2018
aaronpuchert added a comment.
After testing the GitHub provider and the QmlJS code completion I'm somewhat confident that these changes are correct, but I want to give the experts on that code a chance to weigh in before I merge this. Now onto the discussion.
In D15694#330761 <https://phabricator.kde.org/D15694#330761>, @rjvbb wrote:
> It's a shortist word that's easily recognisable that serves as a closing tag. Remove it, and my first impression will be that there's a fallthrough (because I'm not that used to returns in a switch). And a default: without break feels ... incomplete, makes me wonder if I missed a brace.
As discussed earlier, switch statements do have a weird syntax and I'm completely with you if you don't like it. They are basically a glorified `goto` cascade. The case labels actually behave like `goto` labels in a lot of ways, which is the basis of oddities like Duff's device <https://en.wikipedia.org/wiki/Duff's_device> (which is a horrible idea, but it illustrates what switch statements can do). The normal way to exit a switch statement is obviously `break`, but another terminator does just fine as well, depending on what you want to do. It might take some time to get used to it, but I don't think it's crazy.
>> When case labels follow directly after others, no annotation is necessary.
>
> I don't disagree, but it *is* an exception that you can easily extend to other cases where it's evident that a fallthrough is intended:
Like @kossebau, I'm not sure these obvious cases occur so often in practice. In the two cases here where I had to figure whether the fallthrough was intended, it took me quite some time, and in one of them I think it actually wasn't intended. I don't think of it as an exception to allow multiple case labels directly after each other, but more of a way to handle multiple cases in //exactly// the same way. Note that you can freely reorder the case labels of such a block. It's just grouping cases together.
That isn't happening in your example, the cases are actually handled differently. One case, after some preprocessing, "falls through" to the second.
> After all that mumbling in my beard (because that's what it is really) I wouldn't be doing that so much if we were encouraged (or obliged) to use braces systematically:
If we got to redesign C from scratch, I would probably agree. But it's probably a bit too invasive for existing code bases, compared to adding a few annotations. That is the fine line compiler writers want to walk on, making switch statements behave more sanely while at the same time not completely changing everything about the language.
REPOSITORY
R32 KDevelop
REVISION DETAIL
https://phabricator.kde.org/D15694
To: aaronpuchert, #kdevelop
Cc: rjvbb, brauch, mssola, kossebau, kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20180923/2266b18d/attachment.html>
More information about the KDevelop-devel
mailing list