Many computational scientists that I know of, including myself for example, are not computer scientists. As such they are often not very well aware more advanced techniques in OOP. On the other hand, most of advanced programmers are not computational scientists. They may not be well aware of what OOP features are essential or relevant when it comes to write a scientific computing software.Considering mainly C++ (but maybe also in general), what OOP features do you think are absolutely necessary in a number crunching software and why? What features do you think are generally considered good, but might cause unnecessary overhead? What are some of the myths when it comes to overhead of using more advanced features?I generally like to hear things regarding:1 - templates2 - virtual functions3 - smart pointers and garbage collectors[EDIT:] 4 - operator overloading5 - Boost library (technically not an OOP feature but very popular C++ library)
What modern OOP features should a computational scientist use?
libraries;c++;programming paradigms
I'm not a big user of OOP in general, and this has its reasons. My thoughts on some of the features you mention:Templates: Convenient when they work, a massive nightmare to debug when they don't. Furthermore, you don't really know what's going on behind the scenes, which can be a source of errors or inefficiencies.Virtual functions: Can be very convenient and elegant, but keep in mind that calling that function is more expensive than calling a static function. Don't use these things in the innermost loop of a big calculation.Smart pointers: As with virtual functions, watch out for hidden overheads when assigning and dereferencing. Don't use in performance-critical parts of your code.Garbage collectors: Not necessarily an OOP feature (e.g. the Boehm GC), but an awesome thing nevertheless. Again, this can cause your program to pause and wait while cleaning up the memory, but you should avoid excessive creation/allocation and destruction/freeing of objects in performance-critical parts anyway, right?One thing you left out is operator overloading, which is an extremely convenient way of expressing things in a readable manner. Again, though, watch out for overheads in tight loops, and remember that in general, the compiler will not be able to optimize anything (think common sub-expression elimination, register variables, etc.). A good alternative are expression templates, but writing your own can increase code complexity and give you weird bugs, think the same kind of mess as regular templates can be.Having said that, using other people's templates, assuming they are tried and tested and mostly bug-free, can make life so much sweeter. Remember though: can, as in not always.In summary, it's a performance/elegance trade-off. I would definitely recommend OOP, or anything similar, for the user interfaces and/or big picture parts of the code. I would, however, stay away from it in kernels or anything performance-critical due to the hidden overheads and the fact that the compiler usually can't optimize much.