Re: Goto (Was Re: Open Source)
- Posted by CChris <christian.cuvier at agriculture??ouv.fr> Oct 29, 2007
- 804 views
Jason Gade wrote: > > c.k.lester wrote: > > > > CChris wrote: > > > c.k.lester wrote: > > > > CChris wrote: > > > > > loop do > > > > > -- some code > > > > > until some_condition > > > > > end loop > > > > The "end loop" is redundant, isn't it? > > > Sure, but in keeping with all other Euphoria code block syntactic markers. > > > > IMHO, we should never choose tradition over efficiency. :) > > But we should choose consistency and the principle of least surprise over > efficiency. > You probably expected it: I simply and completely disagree on this. Efficiency first, consistency next (as close as possible). Least surprise is another name for consistency, or is it something else? If I know the docs well and if they are precise, I never have surprises, or they are called bugs. > Some languages, such as the BASH shell, put the until clause at the beginning > of the loop. > > I don't know how hard it would be with regards to parsing, but I would prefer > it be done as it is done in C: > > The current Euphoria while loop, > > or > > }}} <eucode> > do > -- some statements > while x > end while > </eucode> {{{ > > For loops which are required to be executed at least once. I disagree with > adding > a keyword that only reverses the truth of a decision. > It does not do that _only_. You can always emulate a loop block like this:
while 1 do .. some code if not some_cond() then exit end if end while
How needlessly verbose! What does the "then exit end if" give you? One thing I'm contemplating to add is an extra "entry" keyword, valid in both while and loop blocks. If this keyword is present inside the block, the first iteration of the loop will start there rather than at the top. There are quite a few cases where you need to write hard to understand - and usually forgotten in the first place - code to take account of some quantity just not being defined at the start of first iteration. It would make code quite clearer in some cases. Not hard to implement I think. I have nothing fundamentally against the C-like }}} <eucode>do ... while something end while</eucode> {{{ syntax. However, what makes the more sense? Stating an end condition at the end of the loop, or the keep-looping condition? As you said, both are equivalent logically. I still think stating the end condition at the end of the loop is slightly more intuitive. Plus: how would you add a label to your construct, since it has no header? Perhaps the label keyword should always follow do or then, after all, in which case this difficulty disappears. CChris > -- > 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.