2 ms·
"Structured programming" has a very specific meaning. Or at least, it did in Dijkstra's goto paper. It's not that all uses of goto are terrible, it's that if yo
by regularfry 5y ago
"Structured programming" has a very specific meaning. Or at least, it did in Dijkstra's goto paper. It's not that all uses of goto are terrible, it's that if you restrict goto's uses to specific types of control flow, you can make provable statements about the behaviour of the code, which other uses blow up.
The goto's you've used here are within the set of allowable uses, so can be mapped directly onto structured constructs. There's literally no advantage either way, other than introducing the possibility to the reader that there could be something weird going on in your code.
> Would love to see a faster version in some popular, "structured" scripting language in the same number of characters.
How's this?
#include <stdio.h>
void main(){
for(int a=1; a<100; a++){
int y = a % 3;
int z = a % 5;
int x = y + z;
if(!x) puts("fizz");
else if(!y) puts("buzz");
else if(!z) puts("fizzbuzz");
else printf("%d\n",a);
}
}
Same technique, give or take some unimportant details. Not particularly golfed. 240 characters to your 312. I have no idea if it's faster because I don't know how good the spitbol interpreter is, but I do know that because I've used "structured programming" structures, the compiler (or interpreter, whichever you prefer) can in principle make more safe optimisations to my code than to yours.
If C doesn't meet the "scripting language" constraint (which I find arbitrary, but not insurmountable), I'd throw Julia or FORTH at it and probably shave a considerable number of bytes off.
- 1vuio0pswjnm7 5y ago"How's this?" Unoptimised, it's already roughly 3x faster than the spitbol script. Moving the "int" specifier out of the for loop allows this to compile under -std=C89. How does one suppress the warning about the non-int return value for main().
- regularfry 5y agoThe easiest way is to `return 0;`. We've got the character budget for it.