3 ms·
You're not wrong, per se, but C++'s memory model tends to make refactoring this sort of thing a lot more painful than needed. If you introduce function you have
by overgard 12y ago
You're not wrong, per se, but C++'s memory model tends to make refactoring this sort of thing a lot more painful than needed. If you introduce function you have to spend a lot of time thinking about how do the variables copy over the stack, is this data structure safe to pass to a function? And do I pass by reference? And do you return values from the stack or in allocated memory or write into a passed reference? Or do you get really gross and write a macro? And so on, until you just think "fuck it, copy-paste".
It's not an excuse, but languages definitely shape how you think, and C++ definitely encourages long functions and copy pasta.
- shadowfox 12y agoI don't disagree with you per se. But I think you may be overstating the case. Once you are a C++ programmer for a while, you start to discern "standard" patterns for this sort of thing and tend to automatically use them. (The patterns might depend on the C++ version and to an extent the code base in question; but it is common to have such helper function take a const ref as input, return non-primitive return values via a out-parameter etc). So while C++ might "encourage long functions", I think that may be the case only for newbies to the language. Once you have a some experience working with it, you no longer need to put that much thought in to every little decision.