Simple is better than complex. Complex is better than complicated.
–Tim Peters, The Zen of Python
Although a mantra of Python, the opening quote applies well to Fortran and programming in general. We always aim for simple, whenever possible. This is especially true in software design, where we often deal with increasingly complex systems. Simple is easy to read, understand, and explain to our friends and colleagues. However, it’s a challenge to maintain simplicity as we build an app, a library, or a framework. The more features we add and corner cases we handle, the more bloated our app seems, and we worry that the project will spin out of control. It inevitably becomes more complex. Does that also mean it has to become more complicated?
I don’t have a traditional computer science background. I first learned to program so I could solve physics problems, much like the one we worked on in the previous chapter. Programming for me was more a tool to accomplish a given task than an art in itself. Some of my programs could easily grow to thousands of lines of code, consisting of inscrutable reads and writes to binary files, multiply-nested loops, and endless lists of imperative expressions and assignments. No function calls, no code reuse. Abstracting data with object-oriented classes and methods? Forget about it! It was a programmer’s nightmare.
Over time, I learned about Fortran features designed specifically to make programming easier. For example, rather than repeating the same calculation on different data, you can write it as a function and call it many times with different inputs. You can use modules, introduced by the Fortran 90 standard, to define variables and procedures, which can then be accessed from elsewhere in the program or library. Carefully put together, these elements will make your life easier, whether you prefer an object-oriented, functional, or plain procedural programming approach to your problem.