Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

goto considered harmless

Name: Anonymous 2018-05-10 11:02

I was reading Bjarne Stroustrup's sepples book and found this

One of the few sensible uses of goto in ordinary code is to break out from a nested loop or
switch-statement (a break breaks out of only the innermost enclosing loop or switch-statement).
For example:


void f()
{
int i;
int j;
for (i = 0 ; i <n ; i ++)
for (j = 0 ; j <m ; j ++) i f (nm [i][j ] == a ) goto found ;
// not found
// ...
found :
// nm[i][j] == a
}

Name: Anonymous 2018-05-10 11:07

>>1
The original "Goto considered harmful" complaint was about spaghetti code that consisted of gotos. Purists extrapolated this to mean that goto is some ancient hack that should be avoided at all costs somewhere in the late 90's.

Name: Anonymous 2018-05-10 11:31

10 PRINT "LOL"
20 GOTO 10

Name: Anonymous 2018-05-10 13:23

>>2
That purist was Niklaus Wirth. You won't find goto in Pascal.

Name: Anonymous 2018-05-10 13:33

Name: Anonymous 2018-05-11 4:18

Your mom considered harmful

Name: Anonymous 2018-05-11 4:19

>>6
thanks

Name: Anonymous 2018-05-11 6:43

The scenario in OP's poast is better resolved by extracting the search code to a separate function. No
GOTO
needed and that's the standard. HIBT?

Name: Anonymous 2018-05-11 12:07

>>8
It must be trolling. No serious code would be that bad. At least not from any professional engineer.

Name: Cudder !cXCudderUE 2018-05-12 2:35

>>8
No. Why create an entire fucking function when it's a single line? That is true idiocy.

Name: Anonymous 2018-05-12 4:17

>>10
You can make new functions in a single line.

Name: Anonymous 2018-05-12 9:29

>>10
Yeah, but now you have retarded `// not found` comment to document this stupidity. A separate function would do a better job at documenting this.

Also, what kind of retarded language doesn't have flat_map and filter or similar functions to do this kind of looping in single line?

The code in >>1 is very primitive and it is quite difficult for me to understand why experienced developer would write this. It is ok for someone who's been programming less than two years to do this stuff, but not for any serious developer.

Name: Anonymous 2018-05-14 0:32

>>12
Also, what kind of retarded language doesn't have flat_map and filter or similar functions to do this kind of looping in single line?

C and C++, of course.

Also, in these languages the performance cost of adding a new function just to allow for use of return instead of goto is sometimes significant.

Don't change these.
Name: Email:
Entire Thread Thread List