Just now I got an email from a mailing list, saying that C++ helps to greatly reduce coding time in comparison to C. I have heard a lot about this argument. But is that true?
C++ can possibly accelerate development in two ways: firstly, OOP (Object-Oriented Programming) helps to organize large projects, and secondly, STL (Standard Template Library) saves time on reimplementing frequently used subroutines. However, I do not find C++ OOP greatly helps me. To me, it is not right to clearly classify a programming language as a procedure-oriented or object-oriented language. It is only right to say a development methodology is procedure-oriented or object-oriented. We can effectively mimic the fundamental OOP ideas in C, a socalled procedure-oriented language, by packaging related data in a struct and transfer the a pointer to the struct to subroutines. I know C++ programmers would argue doing in this way is far from OOP, but it has captured the essence of OOP and in practice sufficient to organize large projects with this simple and natural idea. The large amount of existing C projects, such as Linux kernel, gcc and Emacs, prove this is the truth. With OOP ideas, we can use C to organize large projects without difficulty. C++ does not provide more power except introducing more complicated concepts.
I do not use STL most of time. I have implemented most of useful subroutines in C/C++ by myself. I actually spend less time in using my own library than using STL as I am very familiar with my own codes. Of course, implementing an efficient and yet generic library by myself takes a lot of time, but I really learn a lot in this invaluable process. I can hardly imagine how a programmer who does not get a firm grasp of data structures, which can only be achieved by implementing by him/herself, can ever write good programs. To this end, I agree that for elementary programmers using STL reduces coding time; but this is achieved at the cost of weakening the ability to write better programs. And for an advanced programmer, using STL may help but probably does not save much time.
Note that I am not saying C++ is a bad language as a whole. In fact, I use C++ template functions a lot and C++ template classes at times. In this post, I just want to emphasize the importantance to focusing on the art of programming instead of on the artificial concepts or on the degree of laziness a language can provide.
yo opino lo mismo respecto al tema, C++ acelera el proceso de escritura de un programa por esas 2 razones que planteaste, existen programadores que eliminan los runtime para acelerar la ejecución, pero si no usas herencia y polimorfismo, utiliza c, con esto no digo que el c++, sea malo ni nada por el estilo, solo que en rendimiento de tiempo, no pienso que aventaje al c standar.
I am surprised there isn’t 1000 posts here saying you are crazy!
I’ll respect your opinion though. You make some good points. But I’d like to comment on one particular point:
“I have implemented most of useful subroutines in C/C++ by myself”
Now consider the scenario where you move on to your next project and I take over your code. You just increased development time significantly because now I have to learn your code really well. But had you used the STL, I could of came in and started contributing much sooner.
Your argument makes me think of the the steam engine versus John Henry. http://en.wikipedia.org/wiki/John_Henry_%28folklore%29
Sure John Henry won, but whoever replaced him probably dragged that company to the ground!
The arguments you make about OOP and STL are all sound, but in my opinion you missed the one feature which makes coding in C++ much faster. To me, the thing that saves most coding time is the presence of constructors and destructors. Especially destructors.
The ability to execute a piece of code whenever some object goes out of scope greatly reduces my memory management and rollback logic’s complexity and size (not to mention the nagging feeling I’ve missed something that makes me double-check the code), and thus the time it takes me to implement them. Using RAII allows me to spend less time worrying about house-keeping and more time writing the code that really gets the job done.
Also, the ability to redefine operators for user-defined types is very convenient in certain types of software. Image if everytime you had to add to vectors you had to write “VectorAdd(v1, v2)” instead of “v1 + v2”, and you’re writing a raytracer where almost everything you have to do is sum and multiply vectors and matrices. Being able to follow the mathematical notation produces more maintainable code and in shorter time.
Precise point. Well said. Don’t use C++ to learn data structures & algorithms which is the essence of the logical challenge. Learn that in C and then learn (advanced) C++ by implementing DS using C++.
Right now I’m maintaining a program that happens to use your implementation of poor man’s STL. If it was actual STL, I’d already know how to use it. But it isn’t, and the different and not very uniform conventions in your code cost real time. So does not being able to use the generic algorithms of STL.
Moreover, the whole procedural-vs-object-oriented argument is a distraction. IMHO, the whole OOP concept is a scam that made Grady Booch and Jim Rumbaugh rich, but didn’t benefit anyone. C++ differs from C in having an improved type system, a meta programming facility, and exception handling with automatic cleanup through destructors. If you work with the grain of those features, they save time and make your programs more robust. (If you insist on using C-style coding, they get in the way. It’s a different language after all.)
By all means, use portable assembly (often called C) to learn about the innards of computers built ca. 1985. But please think twice before using it in production code that needs to be distributed and maintained. I sure do.