When I first began work on Morbus I didn't understand how important it is for code to be modular and easy to extend in the future. Overtime I started to learn how important this was and as much as I wanted to, I never went back and recoded all of Morbus so that it was modular and extensible. Thus Morbus slowly became a monstrous mixture of hard coded spaghetti code with a few modular systems scattered about. Sometimes I wonder if it would have been better to just keep everything non-modular since the constant switching back and forth between modular systems and hard coded systems makes working on Morbus quite challenging and rather draining.
Eventually (today) I decided i've had enough of it, i'm no longer going to deal with that monster code that it is an i'm either going to recode all of it or never touch it again*(tm). But before I cross that bridge here are some of the lessons I learned over the years from Morbus, hopefully they'll help you out in some way.
Organize your files and folders
Never use global variables
So how do you solve this in lua? By putting all of your functions inside of tables which are global variables. This way you emulate C++ namespaces and it works wonders when it comes to organizing your code, just take a look at this to see what i mean:
This is one of my biggest regrets from Morbus, not because I don't have to worry about duplicate function names though, but because it allows clarity when reading code and deciphering what function calls are from what files / modules.
Avoid confusing state data like the plague
So now that you have seen the mess, I'm going to organize it just a little bit so that related state data is next to each other..
I would say out of all my woes with Morbus, this is the greatest. It has made Morbus a truly awful pain to work in since most state data is written to directly (by setting the variables) and there are very few functions calls that do it for you. This causes problems like: "If you change the Mission type then you need to call function X, Y, and Z to ensure everything is ok." The salt still flows from me on this one.
D.R.Y (Don't Repeat Yourself)
Take a look at this beautiful function. No it's not the same one as above. Or is it?
Comment your code
How about 645. Well I guess that's something, it's around 1 line of comment per 15 lines of code. But we should probably take away file headers (yes there were actually file headers) which were at a minimum 3 lines of comments for each of the 92 files in Morbus.
That leaves us with a grand total of 1 line of comment for every 27 lines of code.
Morbus might as well not of been commented at all.