Does anyone have suggestions they want to share for writing clean, maintainable code, either general tips that apply to Inform 7, or Inform-specific tips?
I don’t have a programming background but I’ve been reading about this recently. I’ve come across tips like
- define things close to the place in the code where they are used
- a huge part of making code maintainable is making it readable/understandable
- give things specific, unambiguous names to make it easy to figure out what they are for
- code that’s “tricky” is likely not good code
- make the intended route through the code clear, putting the expected route first so other people reading it can follow it (e.g. try to make the “ifs” the expected behavior and the “elses” the problems/less likely behavior)
- make stuff extensible (i.e. make it so that it’s easy to extend things beyond their immediate intended use)
- if you have lots and lots of “decision points” in a chunk of code (ifs, thens…), it may be a good idea to break it into parts and/or simplify. The book gave some numbers to use as a rule of thumb but I don’t know where my notes are at the moment.
Most of these come from the book “Code Complete” although I’m going from memory here so take my version with a grain of salt. And I suppose the readability factor is more crucial in things that could end up publicly maintained, such as extensions, than in individual works where the code is not public.
If there’s already a resource that covers these sorts of things as they apply to Inform, I’d be interested to hear about that too.