I’m writing a hobby project wherein I write to .wav files. I decided that the best way to do this is to create a single C file with a bunch of routines to initialize and manipulate a struct with metadata about the wave file that the user should never manually manipulate, but should instead pass a pointer to routines. An example of how using this interface would look like is the following:
/* wave_new_file() implicitly allocates memory for the struct */
Wavefile *outputWave = wave_new_file("out.wav", WAVE_mono);
int i;
for (i = 0; i < MAX_RANDOM_SAMPLES; i++)
wave_write(outputWave, rand());
wave_close(outputWave);
I realize that the rest of my design could potentially be simplified in the long-run by using an OOP approach, such as in the following pseudo-C++ (since I’m not actually familiar with C++; more on that later):
Wavefile *outputWave = new Wavefile("out.wav", WAVE_mono);
for (int i = 0; i < MAX_RANDOM_SAMPLES; i++)
outputWave->write(rand());
outputWave->close(); /* Or delete perhaps? */
The problem with this is that: the rest of my project is written in C99; and I don’t actually know C++ (I learned OOP from Python, but am now concentrating on programming in C).
Should I: refactor my design to not rely heavily on OOP principals or should I take the time and learn C++ and migrate my entire program to C++? It’s not a large program and it is just a hobby project (which explains my reinventing the wheel by making my own .wav writing module). Or should I continue with my pseudo-object-oriented design I currently find myself writing?
I think it really comes down to your ultimate goals. If you are purely doing this as a hobby and you are developing this for your own use, then you might be happy enough to stick with what you are doing. However, if you are looking not just for a solution but a good solution to a problem, looking for something new, or doing this as preparation for searching for a job, I would move forward with more heavily investing yourself into either C++ or potentially a completely different language like Java.
Summary in code: