c++flexibility

Guidelines for writing flexible software?


I've been developing an interpreter in C++ for my (esoteric, if you want) programming language some time now. One of the main things that I have noticed: I start with a flexible concept, and the further I code (Tokenizer->Parser->Interpreter) the less flexible the whole system gets.

For example: I didn't implement an include function at first, yet the interpreter was already up and running - I had extreme difficulties implementing it and it was just like "patching something out" later on. My system had lost flexibility very quickly.


Solution

    1. Define the structure of the project before you start coding. Outline your main objectives and think about how can you achieve that.

    2. Code the headers.

    3. Look if it's possible to implement every feature using this set of interfaces

    4. If no -> go back to (2)

    5. If yes -> code .cpp files

    6. Enjoy.

    Of course, this doesn't apply to really large projects. But if your design is modular, there shouldn't be any problems to divide the project into separate parts.