lua-users home
lua-l archive

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


On Tuesday 22 February 2011 14:23:37 HyperHacker wrote:
> On Tue, Feb 22, 2011 at 11:52, Steve Litt <slitt@troubleshooters.com> wrote:

> > 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: http://www.twitter.com/stevelitt
> 
> 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...
> 	end
> end
> 
> as opposed to:
> 
> while something() do
> 	local x = foo()
> 	if not x then continue end
> 	--...many lines here...
> end
> 
> 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). 

You're preaching to the converted. What you have above is your basic continue 
statement like they have in C, and while it's a violation of structured 
programming, everyone uses it for the reasons you state.

I was referring to the more generic "continuation" that was being discussed 
and mentioning that as a group we're never too smart to do stupid things.

Lua not having a continue statement, I obviated my need for continue by 
creating a special skipper iterator called relevant_lines(), described at 
http://www.troubleshooters.com/codecorn/lua/luaclosures.htm#_A_Practical_Line_Skipper_Iterator.

I've taken a lot of abuse for this skipper iterator, and a lot of people have 
used its existence to make snide comments about Lua's lack of a continue 
statement, but the fact is, I like it and it's a lot more generic and 
configurable than what you can do with a continue statement.

By the way, I first got the idea for skipper subroutines while training at 
Santa Monica City College in the early 1980's. The change from 
spaghetti/goto/flowchart to structured/return/functional_decomposition was in 
full swing, and not only were we not allowed to use goto in school, but we 
weren't allowed to use break, continue, or even priming reads.

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt