Re: Short-circuit warning
- Posted by Andy Drummond <andy at k?strelt?le.com> May 20, 2008
- 641 views
Jason Gade wrote: > > Jeremy Cowgar wrote: > > > > Is this warning really valid: > > > > Warning: ../bin/indent.ex:53 - call to matches() might be short-circuited > > > > Well, maybe valid, but useful? For instance, I specifically made the if > > statement > > to short-circuit, that's the way I want it. I program all the time counting > > on short circuits and do not really feel as though I need a warning about > > it. > > I thought short-circuits were a benefit? > > > > -- > > Jeremy Cowgar > > <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a> > > I think it was a valid warning when short-circuiting was new to Euphoria. I > guess the question is whether short-circuiting is expected behavior by people > new or relatively new to programming? > > Personally, I say do away with it and make it very clear in the docs that that > is how things work. > When I first used Euphoria the docs DID describe the short-circuiting process. It was very clear, and made coding easier with things like:
if atom(res) or length(res)=0 or res[1]='+' then do something end if
To do that with three nested if statements would be silly. As is the process of hiding side-effects within if statements. An if statement is a condition testing statement, and just because you CAN hide assignments within it hardly makes for clear coding and good practice. So please stick with short-circuiting if statements and recommend that users do actually read the original Euphoria documentation first. > -- > A complex system that works is invariably found to have evolved from a simple > system that works. > --John Gall's 15th law of Systemantics. > > "Premature optimization is the root of all evil in programming." > --C.A.R. Hoare > > j.