Recommendations for writing flexible software?

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

For example: I didn't implement the function at first include

, but the interpreter was already up and running - I had extreme difficulties in implementing it, and it was like "fixing something" later. My system quickly lost its flexibility.

  • How can I learn to keep relatively small C ++ projects flexible and extensible during development?
+2


a source to share


3 answers


  • Determine your project structure before starting coding. Describe your main goals and think about how you can achieve this.

  • Designate the headings.

  • See if it is possible to implement each feature with this set of interfaces

  • If not → return to (2)

  • If yes -> code.cpp files

  • Enjoy.



Of course, this does not apply to really large projects. But if your design is modular, there should be no problem to split the project into separate parts.

0


a source


If you need to keep

C ++ projects are as flexible and extensible as possible during development

then you have no product specification, no real purpose, and no way to define the finished product.



This is the worst situation for a commercial product. To paraphrase one well-known blogger (don't remember who), "you don't have a product until you figure out what you're not going to do."

For personal projects, this may not be a problem. Chalk it up to experience and remember for future reference. Refactor and move on.

+1


a source


Don't be afraid of evolution (Refactoring).

If there are many classes that match the topic, create a generic base class.

Use pointers to an abstract base class instead of hard-coding data items.
For example, std::ifstream

use instead std::istream

.

In my project, I have abstract classes for reading and writing. Classes that support read and write use these interfaces. I can pass specialized readers to these classes without changing the code. The database reader will inherit from the base Reader class and can therefore be used wherever the reader is used.

0


a source







All Articles