![]() |
| ||
| Do you want to create C++ programs faster? You might want to try this coding method. C++ is supposed to be "superior" to C in terms of usability, upgradability, and all the fancy features. Yes, these are all good features, but if you use C++ the way it was designed, this means writing your program entirely object-oriented. Now, although object-oriented programs are considered good, they also take time to plan and think out how it's going to work as compared to a similar C program, because it's procedural programming. In fact, I've found myself to be much more productive and sucessful in C when designing my program. This doesn't mean that I'm not going to use C++, it just means I'm going to use it at a later stage. To me, even after planning out every possible class, data and function members, I find that I've made logic errors designing the whole process (usually by the time I'm half-way done coding the classes). Then I have to go back and re-think my logic before I can continue programming. Another problem I have when writing a program from scratch in C++ is the fact that a truly object-oriented program has classes that are dependant on each other. This means that quite a number of classes have to be coded before the program can run. This might work for some hot-shot programmers who don't make very many errors, but I find that using this method creates millions of bugs and errors in my program, which can only be discovered once I try to run it. Then, I'm faced with the task of debugging and removing all the errors, which can take anywhere from a few days to weeks if it's a more complex program. Not only is this slow, it's depressing and discouraging trying to debug a program that seems determined to keep you from running it. C on the other hand, doesn't require much planning. You can write sections of your program, test them, remove the 2-3 errors that crept into your little code snippets, and then run it to make sure it's doing OK. Then if you do have an error that you can't seem to fix, you know it originated from the last bit of code that you just entered. This makes coding more encouraging and faster. Am I saying that C++ is "bad" and that we should all switch back to plain-old C? Absoloutely not. Object-oriented programs have quite a number of advantages over procedural-written programs, not the least of which is maintainability. So what I find is best to do is to prototype my application in C, or at least the base of the program. Once this is working and all in good order, I convert it to C++. And not all at once either. I pick a few simple functions that seem to be related, and create a class out of them. I test the program again, and if it's working, I continue with the next class. If not, I go back to the class and keep working until it runs. This method allows you to get the best out of both worlds. It allows for quick prototyping, and once you can actually see what you're doing, you can get a better idea of what needs to go where. At this point, you convert the program into object-oriented-ness. |