6 ms·
From my experience if you are familiar with both C and C++, you do not end up writing C++ code that is completely obnoxious.
by pavanky 14y ago
From my experience if you are familiar with both C and C++, you do not end up writing C++ code that is completely obnoxious.
- angersock 14y agoIndeed, given the option, you may not write C++ code at all!
- duaneb 14y agoI am a diehard fan of C, and even I think that C++ is preferable past a certain size of program. Classes and templates are far too powerful to not use; just consider things like `scoped_ptr`. Just because C++ has nasty parts doesn't mean you have to use them, in my experience most of my worst experiences with C++ come from reading other peoples' code (Boost.Spirit, I'm looking at you).
- rayiner 14y agoI'm going to be a contrarian, and say that I've just never found a program that was more readable with classes. Classes tend to rip up your algorithms to shreds and spread them over dozens of different files, which is really painful. I've been reading through the code in libfirm lately and it's incredibly refreshing. A pass is usually in a single file (how novel!) instead of being scattered around because of the visitor pattern.
- duaneb 14y agoReally? Classes never made source more readable? How on earth is `Vector<Int64>` or whatever less readable than rolling a custom struct and functions?
- rayiner 14y agoBasic logic error (that it doesn't make things more readable doesn't mean that it's less readable). I just don't see the big readability win going from vector_push_back(my_vec, 53) to my_vec.push_back(53)
- duaneb 14y agoOh, well the dot syntax is just, well, syntactic sugar, and arguing that THAT is the reason anyone (who knows what they are doing) uses C++ is silly. It's because of inheritance and DRY so you write less code.
- rayiner 14y agoRight, and my point is that I've never seen a situation where inheritance really makes things dramatically clearer versus the alternatives (indeed, the mantra in C++ these days is that you should have "has-a" relationships with composition versus "is-a" relationships with inheritance). I think inheritance/OOP encourages you to draw module boundaries in the wrong place. It encourages you to spread the logic of an object over several modules of code. If you find yourself using inheritance, you'd better ask yourself: could I instead abstract my base class into a self-contained object that my new object could hold a reference to? See: http://www.paulgraham.com/noop.html http://www.paulgraham.com/noop.html
- rayiner 14y agoI used to be super into using Boost, etc. I found that it became really unmaintainable (though compiler errors might be better now). My personal style is basically C with STL containers.