1. Why end for, end if, end while? Here's why I think...
- Posted by jeremy (admin) Jul 25, 2008
- 1152 views
foreach s[index] do -- whatever end foreach --<-- when do we get rid of that redundancy?
Chris python programmers would say:
foreach s[index] do --<-- huh? do? why have that? -- whatever end foreach --<-- huh? end???? how utterly terrible, ugly intrusive, junk
I personally like it. In C code you see all the time:
#if defined(ABC) // much code #if defined(DEF) // 20 lines later #endif // defined(DEF) #endif // defined(ABC)
Why do they do that? So you understand what the endif is ending. The same thing with Euphoria. It's clear...
if 10 then for 1 to length(abc) do if 20 then -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code end -- Huh? What am I ending? end -- Hm, was this the for or the if? Wait was there a while in there? end -- Ug, I have no idea and I just wrote it!
Jeremy
2. Re: Why end for, end if, end while? Here's why I think...
- Posted by ryanj Jul 25, 2008
- 1041 views
lol, I agree with you, Jeremy.
Ryan J.
3. Re: Why end for, end if, end while? Here's why I think...
- Posted by bryanso Jul 25, 2008
- 1031 views
With such nicely indented code a simple end is enough.
Jeremy's example is contrived. If all blocks are whiles:
while complex-condition1 do ... while complex-condition2 do ... while complex-condition3 do ... lengthy code .... end while end while end while
then one can still argue which end while is matching with which while do.
Bryan
4. Re: Why end for, end if, end while? Here's why I think...
- Posted by jaygade Jul 25, 2008
- 1033 views
With such nicely indented code a simple end is enough.
Jeremy's example is contrived. If all blocks are whiles:
while complex-condition1 do ... while complex-condition2 do ... while complex-condition3 do ... lengthy code .... end while end while end while
then one can still argue which end while is matching with which while do.
Bryan
Which is why I would use comments in such a case:
while complex-condition1 do ... while complex-condition2 do ... while complex-condition3 do ... lengthy code .... end while -- complex-condition1 end while -- complex-condition2 end while -- complex-condition3
5. Re: Why end for, end if, end while? Here's why I think...
- Posted by CChris Jul 28, 2008
- 1030 views
foreach s[index] do -- whatever end foreach --<-- when do we get rid of that redundancy?
Chris python programmers would say:
foreach s[index] do --<-- huh? do? why have that? -- whatever end foreach --<-- huh? end???? how utterly terrible, ugly intrusive, junk
I personally like it. In C code you see all the time:
#if defined(ABC) // much code #if defined(DEF) // 20 lines later #endif // defined(DEF) #endif // defined(ABC)
Why do they do that? So you understand what the endif is ending. The same thing with Euphoria. It's clear...
if 10 then for 1 to length(abc) do if 20 then -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code -- much code end -- Huh? What am I ending? end -- Hm, was this the for or the if? Wait was there a while in there? end -- Ug, I have no idea and I just wrote it!
Jeremy
No one prevents you from adding a comment to the end statement.
And your point doesn't apply when there are 5-6 piled up end for's and end if's, which is not rare. With proper indent, you exactly know where the block started, hence what it is.
Even if not so, because the innermost block is long for whatever reason, You'd add a comment anyway, so the end is of no help.
CChris ot checking the forum often, because my landline needs repair.
6. Re: Why end for, end if, end while? Here's why I think...
- Posted by unkmar Jul 29, 2008
- 985 views
- Last edited Jul 30, 2008
I myself have run into the following in recent weeks.
for i = 1 to 20 do if (this) then if (that) then end if end if if (something) then --whatever end if if (more_if) then --go crazy end if end if -- Syntax error
Notice, the code structure is perfectly accurate. I rarely spot these bugs before execution. Usually I have written a good 40 or 50 lines of code with 3 or 4 of these errors. Some of ifs that are suppose to be fors. Some fors that are suppose to be ifs. And the occassional change of a loop that causes me to have a for that should now be a while.
But hey, I love my little language that catches all my little mistakes.
Come back next week when I complain about back, neck, and knee pain.
7. Re: Why end for, end if, end while? Here's why I think...
- Posted by ray Jul 29, 2008
- 1013 views
- Last edited Jul 30, 2008
Chris python programmers would say:
foreach s[index] do --<-- huh? do? why have that? -- whatever end foreach --<-- huh? end???? how utterly terrible, ugly intrusive, junk
There are no "end" commands in Python. Scope is defined by indentation, so Python programmers would say:
foreach s[index] do --<-- huh? do? why have that? -- whatever
Ray Smith http://RaymondSmith.com
P.S. Hi to all the old Euphoria heads!