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.
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
This obviously saves time and looks more elegant than combination of if statements and functions.
Perhaps with gotocase it could look like this:
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.