From: Phlip Date: 2004-08-21T22:00:48+09:00 Subject: This naughty language of ours violates hallowed Structure Programming sophistries Rubies: Please review for accuracy: Before Object Oriented Programming, people who studied the difference between cruft and maintainable code learned to improve things by linking control flow to variable scope. An example in C: if (whatever()) { int x = something(); somethingElse(x); } x; /* this line won't compile, unless another x is available from above */ Structured Programmers decry the mighty goto keyword, able to leap tall procedures in a single bound. When a language permits a goto unfettered by that language's block system, {}, variables defined in statements controlled by goto have ambiguous scope. Structured Programming enables the style guideline "give identifiers the most restricted scope possible". I am unaware if Ruby supports goto. (Please please please don't tell me if it does or not!) Object Oriented Programming subsumes all Structured Programming ideals. However, Ruby permits this: def newThing() if something() then element = constructor(TkcLine) else element = constructor(TkcPolygon) end element.configure('smooth', '1') end Ruby creates variables by assigning to them. That cures an ancient problem with the C languages, where variables can define without values. The lowly C statement int x; efficiently produces an x that might contain anything, and should not be used until assigned. Ruby fixes that problem by forbidding creation without assignment. Ruby variables create into their method's scope, not their block's scope. That's why the above code works - it tweaks the Structured Programming rules. The element inside the if statement's blocks should, in theory, exit scope and disappear before the last element. Ruby supports Structure Programming much more subtly than by decrying goto. When a goto leaps a tall procedure in a single bound, the root problem is that tall procedure itself. Ruby's syntax maximizes opportunities to minimize code. The style guideline "don't goto" is subservient to the Simplicity Principle "Minimize Statements, Methods, and Classes". For example: def newThing() klass = if something() then TkcLine else TkcPolygon end element = constructor( klass ) element.configure('smooth', '1') end -- Phlip http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces