lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Tue, Feb 22, 2011 at 11:52, Steve Litt <> wrote:
> On Tuesday 22 February 2011 13:17:00 Pierre-Yves Gérardy wrote:
>> > roberto> It always strike me why gotos are considered evil and ugly,
>> > roberto> but continuations, which are a completely unrestricted form
>> > roberto> of computed/assigned gotos, are considered beautiful. Maybe
>> > roberto> the problem with gotos is that they are too restrictive?
>> I think that the problem is social, not technical.
>> Continuations are conceptually more complex, and as such are less
>> likely to be abused by clueless people.
> This would be my guess also.
>> The "considered evil" essay was necessary in its time because, outside
>> accademia, goto was the dominant branching construct, ingrained in
>> programming habits, and this was causing damage. Continuations never
>> were popular enough to warrant such a rant.
> Yes. Any fool can use goto. Anyone in the business before 1985 has been forced
> to deal with goto and understands on a gut level its horrors. As for myself, I
> was TAUGHT to use gotos in college, along with that perverse matching design
> tool, the flowchart. I was a terrible programmer. I wasn't able to become a
> professional programmer until discovering return from subroutine and
> functional decomposition in 1982.
>> By now, good practice are taught from day one, so I think that the
>> Dijstra ban of the goto statement from structured languages and their
>> descendants could be lifted without harm.
> I disagree. To paraphrase PT Barnum, there's an idiot born every minute.
> :-)
> SteveT
> Steve Litt
> Recession Relief Package
> http://www.recession-relief.US
> Twitter:

I think the biggest issue people have is that goto can easily be
abused to create unreadable spaghetti code, whereas continue is a bit
harder to misuse. Of course both can be used well and both can be used
poorly, but goto makes it much easier to construct big tangled messes
that become difficult to follow or debug.
Goto also has some negative stigma attached to it, and so I fear
people would look down on any language that encourages its use, even
if it's used well.

I also wonder, if Lua had goto, what syntax would define a label?
"foo:" and ":foo" would both be ambiguous, and I'm having trouble
thinking of anything else that wouldn't be ugly. Then as well there
needs to be a mechanism for keeping track of those labels.

In all my years of coding I've never found a need or desire to use
goto, whereas continue is something I often find myself wishing when I
have to write a loop like:

while something() do
	local x = foo()
	if x then
		--...many lines here...

as opposed to:

while something() do
	local x = foo()
	if not x then continue end
	--...many lines here...

The latter saves a level of indentation and avoids wrapping a large
block in an if/end (which is especially troublesome in Lua since there
are no braces for IDEs to match). While large blocks can usually be
moved into functions (where you can then use return for a
continue-like effect), this isn't always feasible especially if the
large block is in fact several small blocks ending in conditional
continues or nested blocks. Anyway, moving the loop body into a
function means moving it outside the loop, which isn't terribly
helpful for readability either.

Though, I think the biggest reason people have for wanting continue is
that we already have break, and the two go hand in hand. While named
break and computed goto and other such nice features may be more
useful, they'd also require bigger changes to the language; continue
should only require a few added lines. (There's a patch on the wiki
that adds it if someone wants to check that out.)

Sent from my toaster.