Skip to content

OOP in scientific programming

Mikhail Panko edited this page Jul 16, 2013 · 2 revisions

In software engineering the most common approach to fight code complexity is object-oriented programming. It is well-suited for most large software projects but can have disadvantages for some scientific programming applications. It is good to know differences between OOP and good modular programming and choose an approach suitable for your needs.

Advantages of OOP

  • Couples data with the corresponding methods, which leads to more organized, good code design
  • Easy to understand and grow large coding projects
  • Easy to track interactions between different parts of the project

Disadvantages of OOP

  • Designing and setting up classes introduces overhead (see this thesis for an example)
  • Once set up, classes might be harder to change abruptly, compared to separate data and methods
  • Usually, OOP code runs slightly slower than its modular analogue (especially in MATLAB)
  • Software engineers use object-oriented techniques in part because the orientation on objects is natural for many of their problem domains. The algorithms are simple, but interactions can be very complex. The situation is often reversed in scientific programming. The algorithms can be hideous while interactions can be trivial. In this regime object-oriented techniques might get in the way
  • Not well-suited for MATLAB code

Recommendations

  • Use OOP if:
    • your problem can be naturally described in classes/objects terminology
    • algorithms in your code are interacting in complicated, not well predictable or asynchronous ways
    • you want to create a large generic package for other scientists (sharing and standardizing modes)
Clone this wiki locally