Today I was thinking about something about programs. In most languages, you have to literally declare stuff before it can be used. This is true in C, Python, and a bunch of other languages. The annoying example that I’m thinking of is the ‘they are in the same file’ case. For example, in Python, if you try to call functions defined after the if name == “main“, it will fail. It will state that the function is not defined.
This is so damn annoying. What is annoying is that the compiler is going to discover all the functions and methods when it compiled the module. There shouldn’t be any ambiguity here. Yet, this little stuff forces the programmer to organize their software in a certain way. I have to have my ‘main’ at the bottom. In C, it also forces me to define my function prototypes. This is ok for external functions… but why do I have to do this for internal static functions?? Extra work.
When I have to look at someones code, I have to search for the bottom, and then scan around. It just seems unnecessary and inverted. If the main is the ‘top’, shouldn’t it be at the top for ‘top-down-design’?
C is rife with the same requirements. I’ll bet there is a story from 1972 where one of the designers said, ‘eh, lets just do it this way… we’ll fix it later’. How many hours of time has this consumed of programmers?
Ok, so what if… what if programs had their ‘main’ at the top? It seems trivial, but I’ll bet if you add all these little ‘decisions’ up you will understand why certain ‘new’ ways of doing things will make your existing code start to feel like cobol. (Example: semicolons at the end of the line :-). Has anyone else noticed the rise of languages that put significance in the EOL? It matters. )