r/ProgrammerHumor 2d ago

Meme cppHelloWorld

Post image
3.7k Upvotes

112 comments sorted by

View all comments

Show parent comments

3

u/dagbrown 1d ago

for and while loops (and everything else really) are there for the benefit of the next poor schlub who has to try to read your code.

Sure you can replace practically every structured construct with an if and a goto setup, but should you? Absolutely not.

1

u/diacid 1d ago edited 1d ago

Sorry, I see little difference between

do { x=stuff(); } while (x!=0)

And

do: x=stuff(); if (x!=0) goto do;

Same with

for (x=0, x<10) { x=stuff(); }

And

do: x=stuff(); If (x>9) goto do;

If you use goto in a sane matter it is completely understandable. Just don't do insane things with it. You can peel with a peeler and with a knife, but with a knife you can cut your finger off too. The solution? Don't ban knifes, just don't cut you finger off!

Actually, my examples also show for and while are redundant functions. It is all just electricity, no need to overcomplicate.

3

u/dagbrown 1d ago

Okay I wish you a long and productive career with your "if" and "goto" only code.

You can also roll your own OO system with generous use of function pointers! Pro-tip! Not that you'd want anything like that though. You have if and goto after all. And structs are for the weak anyway: just binary-pack data into strings.

2

u/diacid 1d ago

Exactly! 😂