Re: RE: silly statement terminators
- Posted by Derek Parnell <ddparnell at bigpond.com> Feb 17, 2002
- 515 views
18/02/2002 7:53:55 AM, Ed Davis <ed_davis2 at yahoo.com> wrote: > >Derek Parnell wrote: >> >> Scans:for i = 1 to length(s) do >> c = getc(h) >> while find(c, charlist) do >> if c = AbortCode then >> exit (ScanS) >> end if >> RoutineA(c) >> end while >> RoutineB() >> end Scans >> >> (I'd also like to get rid of this silly 'end for', 'end while', >> 'end procedure', 'end function' stuff. Just a maintenance >> headache and serves no useful purpose, but that's another issue >> ) > >So what would you use to terminate statements? > >Modula 2 and Oberon use just a plain "END", but that can be >confusing (for me at least!). C/C++/Java/JavaScript et al >use the "}", which has the same problem as Modula 2 and >Oberon. > >Don't tell me you're leaning toward the big snake way of >doing it? <grin> > >I kind of like it on the surface, but what if I >accidentally forget to indent correctly? I haven't used >Python enough to really get a feel for that feature. > >So, what would you use? > >Thanks! > > > > --------- Cheers, Derek Parnell Like I said, this is really another issue. But anyhow... I agree that they are a useful mnemonic device and thus should be allowable. Plus I wouldn't like to break existing code. I also use a language called Progress extensively and that too only has END. Thus people's code is often littered with things like ... for each Customer where Customer.Zip = UserZip: . . . end. /* each Customer */ In Euphoria, my problem stems from the current requirement to change two lines of code when one one really needs changing. For example, if I change a PROCEDURE into a FUNCTION, or copy an exiting PROCEDURE/FUNCTION as a template for a new routine of the other type, I must also remember to change its END statement. This is an unnecessary manual effort. In fact, the whole dichotomy between function and procedure is another interesting issue. Why not have 'END ROUTINE' and be done with it? But back to the issue. With FOR/WHILE loops, the maintenance issue is again a minor problem. If I change a FOR to a WHILE I must also remember to change its END statement. Why? It still ends a loop. Why does the interpreter need to know that I know what type of loop I'm marking the end of? My guess is that RDS have designed the language this way to make it easier (and possibly faster) for their Euphoria implementation, ex.exe. With the IF statement, the argument is not so strong as these rarely get modified into another type of statement, thus the need to change its END is also remote. But as to what to use instead, then I suggest the following: 1) In the construct, END <x>, where <x> is FOR/WHILE/PROCEDURE/FUNCTION/IF, make the <x> optional. 2) Allow the naming of loops, like routines can now be named. Then use the name of the block on the END statement. E.g. for i = 1 to 20 do:Main . . . end Main procedure MyRoutine() . . . end MyRoutine 3) Make 'END <x>' report a warning if the <x> is of the 'wrong' type. E.g. procedure MyRoutine() . . . end function -- A warning is given. ---------- Derek