1. Why end for, end if, end while? Here's why I think...

CChris said...
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

new topic     » topic index » view message » categorize

2. Re: Why end for, end if, end while? Here's why I think...

lol, I agree with you, Jeremy.

Ryan J.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Why end for, end if, end while? Here's why I think...

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: Why end for, end if, end while? Here's why I think...

bryanso said...

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 


new topic     » goto parent     » topic index » view message » categorize

5. Re: Why end for, end if, end while? Here's why I think...

jeremy said...
CChris said...
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.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Why end for, end if, end while? Here's why I think...

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.

Lucius L. Hilley III - Unkmar
Come back next week when I complain about back, neck, and knee pain.

new topic     » goto parent     » topic index » view message » categorize

7. Re: Why end for, end if, end while? Here's why I think...

CChris said...

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!

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu