Limiting scope within a procedure - Forum - OpenEdge General - Progress Community

Limiting scope within a procedure


Limiting scope within a procedure

  • But, what I am trying to do is to set aside the case of the loop variable.  Suppose that I grant that it would be nice to have a loop variable scoped to an iterating DO loop where there was a counter ... I'm not sure that I really agree, but I grant at least that this is a valid use case.

    However, this very specific use case only got teased out after a lot of discussion about how ABL was demented in general because variable definitions were not scoped to loops generally.  I contend that it is nonsense to put definitions inside an iterating loop, so the only use case other than the loop variable is non-iterating blocks.  I see no use case for scoping variable definitions in that case which is not admirably served by the existing functionality of scoping to method and IP.

    That's my bad with the definitions inside the loop thing... I agree and fixed that.  My brain got tangled up between the 'DO block' and 'iterating loop' terminology, since they are tightly coupled in ABL (most languages have separate keywords for conditional and iterating blocks).  The initial question refers to conditional blocks, not necessarily iterating blocks, which I think should also have tight variable scoping.

    I would never write DO i = 1 to 10 in production code.


    (I know I said it would be my last post before but I had to correct the error of my ways)

  • I wouldn't use a variable like i in production code because I use meaningful variable names which make it clear what they are doing.

    OK, there has been some confusion about iterating and non-iterating blocks, but I am still waiting for a use case other than the loop variable itself where block scoping provides a plus that IP or method scoping doesn't.

    Consulting in Model-Based Development, Transformation, and Object-Oriented Best Practice