HanPBF wrote:
Any hints for "organizing procedural programs"?
There are lot of ways, but I like the most "logical separation" doing it through code folding.
There are so called 'regions' in C#, and that's the idea I've adopted for this. In PB similar can be done using ";{" and ";}" to hide whole regions of code.
For example, that's how main file of my game is looking using concept of regions:
http://rgho.st/7wNHrYSVH
The 'regions' of course can be nested too and so on + additional folding is provided by other PB keywords like "if", "for", "select", "procedure"...
Cool & simple, just unfold what you need and edit it not seeing anything else. For me the result of it is very clear and I never encountered problems with code organized such way (I'm working on that game code almost one year already and total its size is large enough, also for this time I wrote lot of other stuff organized the same).
But of course only that is not enough to not drown in long-term perspective. Important parts of the game are separated from others into "subsystems", and they are isolated classes by fact. One subsystem can store local pointer to instance of another [that pointer is received only through subsystem init procedure] and then access its properties by that pointer (there are also additional rules to how they can be accessed). To use other subsystem functions, instance pointer is not needed - I'm just declaring required functions (some internal subsystem code cannot be called such way from another subsystem).
That's all also clear enough and similar is used in large projects on C, so I call it "OOP in C style".
Same can be done using Purebasic modules, which are very close to a classes and truly isolating code (not only "logically"), but I still didn't found a valuable reason to use them - they requiring to be declared, UseModule(), etc, which is additional bureaucracy.
Also subsystems of course are placed in different source files, and all is joined to a project. But all their headers/structures I'm gathering into a single declare file (such also used in C projects, for example lib Leptonica provides only one but very large file "allheaders.h" ^^ which is generally much better that 1000 small files trashing project folders).
Within this file (and basically any other file) also regions are used to organize code the most efficiently (for example, separated region are defined for every subsystem).
In total, the base of my code organization is code folding, and some rules I'm always keeping on, when writing something larger than script-like stuff in only one source file (and also some rules about code documentation, used notations, etc).
You of course should find your own way (in meditation ^^), which will be really better for you.
After all It is fact for me, that procedural code is clearer and is less boring and time-wasting to organize it well, than to write code in OOP languages.
At least, that is fully true when working with PB and it's IDE ^^ (which however lacks several important functions, like "go to definition/declaration", but that's another talk). For C it depends on IDE mainly. I'm not writing much own things on C and have no formed strategy to organize C code, just sometimes learning how others are doing that in large stuff.