-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
While it's obvious that goto is considered harmful, sometimes it is still a usefull tool.
Because zig dosen't support switch falltrough, i propose an alternative: gotocase.
Let's consider this esample from https://wiki.c2.com/?GoTo in C
Mask *pMask(NULL); switch (type) {
case POINT:
Mask tmpMask;
vector<Location> &v=getVectorOfPoints();
for (iterator it=v.begin();it!=v.end();++it)
tmpMask.set(*it);
pMask = &tmpMask;
goto drawMask;
case MASK:
pMask=getBitMask();
drawMask:
// here's the code to draw the mask overlay
break;
}
This obviously saves time and looks more elegant than combination of if statements and functions.
Perhaps with gotocase it could look like this:
switch (type) {
POINT =>
//dopointstuff
gotocase else;
MASK =>
pMask=getBitMask();
gotocase else;
else =>
// here's the code to draw the mask overlay
}
To enforce good code practices one could restrict gotocase to apear only at the end of the case and only cases that are further down.
Metadata
Metadata
Assignees
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.