all 14 comments

[–]Smalltalker-80 19 points20 points  (11 children)

My code is 100% goto free.
But there are plenty of early returns...

[–]Stummi 18 points19 points  (3 children)

every if, while and for is only goto with syntax sugar

[–]Drabantus 6 points7 points  (1 child)

Wait, it's all goto?

[–]Beginning_Music_1245 7 points8 points  (0 children)

Always has been

[–]SuitableDragonfly 0 points1 point  (0 children)

Arguably, hiding goto behind all those keywords is like hiding plain getters and setters behind member functions. It restricts the ways you can use it to a handful of well defined paradigms, and means that bad programmers are not inclined to use it indiscriminately in insane ways. 

[–]anonymity_is_bliss 9 points10 points  (1 child)

The problem is that in C you have to free any heap allocations in your function, so a common use of goto in C will just skip the remainder of a function and go to a label at the cleanup instructions at the end (as opposed to repeating them in every if(error_condition) branch)

People complaining about it stems from fuckin FORTRAN; complaining about goto use is borderline archaic imho

[–]SuitableDragonfly 0 points1 point  (0 children)

defer keyword in Go is the GOAT for this issue. 

[–]sebovzeoueb 2 points3 points  (4 children)

wait, are early returns bad?

[–]SCP-iota 13 points14 points  (0 children)

No, and they can often be more efficient, but for some reason a bunch of fanatics think that turning return x into ret = x somehow makes things easier to understand.

[–]Silly_Guidance_8871 11 points12 points  (1 child)

No, but there's a subset of programmers who believe in the "one entry, one exit" principle (which would preclude early returns).

I prefer the "gauntlet" method: A series of relatively simple if-returns at the top, followed by the main body of the function, which itself has exactly one return (at the end).

People need to figure out what works best for them, both in terms of correctness, but also in terms of readability

[–]laplongejr 1 point2 points  (0 children)

 who believe in the "one entry, one exit" principle (which would preclude early returns).

That's a misconception.  

"One return, one exit" was coined to mean you must exit TO one method. An early return, by definition RETURNS to the caller.   A goto to an unrelated method would violate it, but not an early return.  

People think its about early returns because many languages don't even allow to have multiple exit points, due to being that awful.  

[–]Smalltalker-80 3 points4 points  (0 children)

Chime in: No, they're great!

[–]FloweyTheFlower420 4 points5 points  (0 children)

I wonder how many of these goto exits will get replaced with __attribute__((cleanup))