Re: rant // OE scope \\ forked out of 500 Rosetta

new topic     » goto parent     » topic index » view thread      » older message » newer message
_tom said...
Spock said...

I once analysed the distributions of variables declared inside routines. So few private variables are used on average that it seemed to me scopes are pointless inside routines - particularly when realising that routines should be kept short and single purpose. I made the conscious decision to not include them. However I think it is useful to be able to declare variables at the point in code when they become needed, rather than interrupting the typing flow by inserting them at an earlier point in the text. YMMV but I just don't see the need to have any structural scopes inside routines. Perhaps someone could point out just where i got it wrong.

Spock

You need micro scopes because certain curmudgeons use only x,y,i,j,k as the only identifiers in source-code.

Interesting that the primary (first) reason given for micro scopes seems to be to add protection against supposedly poor coding habits. I find that having short identifiers can actually help clarity. My programs have a very light feel to them compared to other stuff coded in Eu. Part of that will also be the programming style since I fully concur that routines themselves should be short.

_tom said...

A language structure is "a feature that starts with a keyword (like procedure, function, for, if, while, ..., and a few others). Each structure extends up to end <keyword>." Structures act like small detours in the natural flow of code execution. Since they are detours it makes sense that they also have some independent properties like: selective code execution, and scope. Structural scope is "the nested scope that corresponds to the extent of the structure."

For example look at the routines in the standard libary; most have parameters and many have locally declared variables. The main program is cleaner because none of these structural scope identifiers mess with the code you write.

I had a look at \std (Oct 2010). There is a monster (580 GLOC) in text.e - format(). Of the variables maybe half a dozen were declared inside micro scopes. Surely the correct approach would have been just to refactor the code down into more sane-sized chunks - which wouldn't then need micro scopes..

Spock

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu