Proposal: Remove the "fallthrough" keyword


(Rainer Brockerhoff) #1

It's somewhat funny seeing you guys all avoiding the word "goto"... :slight_smile:
Hey, it's just a unconditional branch!

Now seriously, in a past incarnation I used C in very resource-limited
contexts (both in execution time and code size) and goto-ing around
inside a switch statement was often the only solution.

Not that porting Swift to a Raspberry Zero should be a short-term goal,
but if the current "fallthrough" stays in whatever incarnation, I'd be
happy.

Typing this in reminded me of a possible way to allow common code to be
executed at the end of some cases, but not others: before the switch,
set up a closure (or an array or dict of closures, whatever) and call
that as the case's last statement; no doubt you-all would have
suggestions about properly scoping such a thing.

···

On 12/5/15 22:02, swift-evolution-request@swift.org wrote:

Date: Sat, 05 Dec 2015 18:23:28 -0500
From: Steve Canon <scanon@apple.com>
To: John McCall <rjmccall@apple.com>
Message-ID: <CA6BFF82-A212-41B6-8104-A0527E84D31C@apple.com>

Very much thinking out loud and not really the implications, I wonder if we might just use "continue" instead of "reswitch".

I very much like specifying what case to fall through into, no matter how we spell it.

--
Rainer Brockerhoff <rainer@brockerhoff.net>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://brockerhoff.net/blog/