Fortran

Guide To Learn

Why are pure functions important?

Including a pure attribute in your function and subroutine statements forces you to write side effect-free code. This has two principal benefits:

  • Side effect-free code is easier to debug. It comes with a guarantee that the code isn’t changing the state of the program anywhere outside of the procedure, and any effects are localized.
  • It allows the compiler to execute the procedure in the most efficient way. A good compiler on a multicore system can even execute a pure procedure in parallel, if that would be more efficient.

Tip Write pure procedures whenever possible.

As I’ll show you later in the book, using the pure attribute can get you a long way toward functional programming with Fortran.

Why are pure functions important?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top