Re: Declaring a Function Before it is used
- Posted by "Michael Nelson" <MichaelANelson at worldnet.att.net> Oct 31, 2003
- 398 views
Rob, I program professionally in Visual Basic, where forward references are legal. I find most of my code structures itself as use-it-before-you-define-it. For example, let's say that foo is a routine and bar implements some detailed functionality for foo. In Eu, I must code this as procedure bar() -- do highly technical stuff end procedure global procedure foo() -- do stuff bar() -- do more stuff end procedure Admittedly on reading foo, I have already read bar and "know what it does". On the other hand, as likely as not I can't really understand what bar does until I see it in its context in foo. If forward referencing were allowed, I would put the general routine foo first and the implementation routine bar() after it. I submit that ordering routines from general to specific (top-down) is at least as logically coherent nad readable as specific to general (bottom-up) as mandated by Eu. I agree with Al Getz that forward referencing in top-lvel code should still be prohibited. This is much less needed and would require a two-pass interpreter. If I am so inclined, I can write excellent, comprehenisble code in either mode. I can also write unmaintainable garbage in either mode. Obfuscated Eu code is perfectly possible, it just takes more creativity than in C. Unlike many other proposals (structures, OOP, built-in Windows, etc.), allowing forward referencing does not complicate syntax or add overhead to the interpreter. It also can't be implemented in a library. So your objections in this matter are purely philosophical. OK, it's your language--but why make developers of major libraries unhappy for the sake of pure philosophy? If Derek says that forward refencing would simplify Win32Lib and its absence makes his programming tasks more complicated, I am certain he knows what he's talking about. In Diamond, this is not a significant issue, but the routines are far less interdependent than in Win32Lib. By the way, Diamond allows forward referencing of methods (no problem to implement as all methods are called via routine_id). -- Mike Nelson