Kick off your book project in 2 hours, get started with GhostAI in 2 hours, or do both! Free live workshops, on Zoom. You’ll leave with a real book project and a clear plan to keep going. Saturday, June 27, 2026.

Leanpub Header

Skip to main content

Modern Software Design in Fortran

This book is 100% completeLast updated on 2026-06-19

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

Buying multiple copies for your team? See below for a discount!

PDF
EPUB
WEB
322
Pages
About

About

About the Book

Fortran is one of the first high-level programming languages. Today it's still heavily used by development teams that maintain important software. Fortran is an old language, it currently goes through an intense modernization phase. Although the ecosystem catches up with other programming languages, it's sometimes not as straightforward to write truly modern Fortran code.

In this book, Matthias Noback explores many ways in which Fortran code can be redesigned to implement powerful ideas from various contemporary software design paradigms. Using lots of code samples, the author provides step-by-step refactoring scenarios that help improve the structure of existing Fortran code bases. Along the way you'll find out how to overcome some of the language's limitations and work around its quirks.

How to deal with errors in a language that has no exceptions?

How to implement an enumeration type?

How to write unit tests for code that behaves differently all the time?

How to share services and create them only once?

This book answers all these questions, and many more.

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 3 members

    Minimum price
    $47.00
    Suggested price
    $72.00
  • Up to 5 members

    Minimum price
    $76.00
    Suggested price
    $116
  • Up to 10 members

    Minimum price
    $133
    Suggested price
    $203
  • Up to 15 members

    Minimum price
    $190
    Suggested price
    $290
  • Up to 25 members

    Minimum price
    $285
    Suggested price
    $435

Author

About the Author

Matthias Noback

Matthias Noback has been building web applications since 2003. He is the author of Principles of Package Design and Object Design Style Guide and Advanced Web Application Architecture. He is a regular blogger, public speaker and trainer.

Leanpub Podcast

Episode 224

An Interview with Matthias Noback

Contents

Table of Contents

Preface

Introduction

  1. Wo are you?
  2. Overview of the contents
  3. About the author

Fortran – An Introduction for Programmers

  1. Running a simple Fortran program
  2. Active environment: not selected?
  3. Configure the default compiler with an environment variable
  4. Programs and modules
  5. The program keyword
  6. Repeat the name of an element in the end statement
  7. The module keyword
  8. Make everything private by default
  9. Aways add only to use statements
  10. Types and Variables
  11. Declaration comes first
  12. Intrinsic types
  13. Don’t assign a default value while declaring it
  14. Add implicit none(type, external) to every module
  15. Printing values
  16. Complex numbers
  17. Arrays
  18. Parameters
  19. Type kinds
  20. Functions and Subroutines
  21. Subroutines
  22. Functions
  23. Dummy arguments
  24. Declare each variable on its own line
  25. Pure functions
  26. Optional arguments
  27. Don’t use optional arguments
  28. IAdvanced Design Concepts

Object-Oriented Programming and Design

  1. Derived Types
  2. Declaring a derived type and its data components
  3. Naming types
  4. Default structure constructor
  5. Passing derived types as arguments
  6. Keep your lines short
  7. Encapsulation
  8. Type-bound procedures
  9. The first argument is the instance
  10. Type-bound and normal procedures
  11. Naming procedures
  12. Private data components
  13. Factory functions
  14. An interface for the factory functions
  15. An interface with the same name as the derived type
  16. Modeling Services as Derived Types
  17. The initial situation
  18. What are file units?
  19. A derived type for the logger service
  20. Can a user really be forced to use the factory function?
  21. Refactoring towards a better design
  22. Abstract Types and Deferred Procedures
  23. A deferred procedure and its interface
  24. An abstract factory
  25. Do we need two variables?
  26. Updating the old log() subroutine
  27. Polymorphism
  28. Service Composition and Aggregation
  29. The do-it-both-logger
  30. An array of abstract loggers?
  31. An array of logger references
  32. Delegating to any number of loggers
  33. Decoration
  34. Decorating a service abstraction
  35. Log levels
  36. Optional delegation
  37. Prefer to return early
  38. Maximum flexibility
  39. Module Design
  40. Each derived type gets its own module
  41. FPM naming convention
  42. A façade for users
  43. Module dependencies
  44. Compilation cascades and submodules
  45. Conclusion

Intermezzo: Enumeration

  1. Introduction
  2. A derived type for log levels
  3. Making the constants really constant
  4. Collapsing to a single data component
  5. Increasing type-safety
  6. Separating log level and log level factory
  7. Operator overloading
  8. Restoring encapsulation
  9. Subtypes
  10. Encapsulation and cohesion
  11. Conclusion

Functional Programming and Design

  1. Introduction
  2. Transforming lists with a filter function
  3. Using intrinsic function pack
  4. Passing a function as an argument
  5. Generic filtering
  6. Closures
  7. Making it generic, again
  8. Map
  9. Elemental functions
  10. A map function
  11. Mapping to other types of values
  12. Looking ahead
  13. A list type
  14. Reduce
  15. Intrinsic function reduce
  16. Recursion
  17. Pure functions
  18. Impure functions
  19. Undeterministic behavior
  20. Pure functions that aren’t actually pure
  21. Making impure functions pure
  22. Conclusion

Errors and Error Handling

  1. Introduction
  2. The naive way; ignoring problems
  3. A sensible default or alternative
  4. Using a boolean success return value
  5. Using an error return value
  6. Optional results
  7. A single, optional return value
  8. Preventing edge cases with types
  9. The Either type
  10. Returning either a point or an error
  11. Either and Option types
  12. Enforcing either of the data components to be provided
  13. Error propagation and nesting
  14. Nesting errors
  15. Guarantees; the Evidence pattern
  16. Language limitations
  17. Fatal errors
  18. Non-zero exit codes
  19. Printing an error
  20. Tracing the origin of an error
  21. Stack traces
  22. Conclusion

Intermezzo: A Generic to_string Function

  1. Introduction
  2. Getting started with to_string functions
  3. A generic to_string function
  4. Turning arrays into strings
  5. Derived types to string
  6. An abstract to_string_t type for derived types
  7. Conclusion
  8. IITest-Driven Development and Design

Designing a test framework

  1. Introduction
  2. Temporary test programs
  3. Manually comparing output
  4. Using assertion functions
  5. Dealing with error margins
  6. Not stopping on the first failed assertion
  7. Printing a description of the test
  8. Integrating with FPM
  9. Unit tests and test suites
  10. Moving tests to their own procedures
  11. Moving tests to their own modules
  12. Generalizing the test program
  13. Collecting unit tests from multiple test modules
  14. Could the test framework discover all test modules and test procedures automatically?
  15. Towards a generic test runner
  16. Breaking out of the main program
  17. Making run_test_suites testable
  18. Collecting more test results
  19. Showing progress and printing results
  20. Making an abstract progress printer
  21. Returning test and assertion errors
  22. Printing the test error using the progress printer
  23. Adding custom messages
  24. More assertion functions
  25. Introducing an interface for assert_equals
  26. Minimizing code duplication
  27. Supporting multiple kind-types
  28. Comparing derived types
  29. Improving the design: types and encapsulation
  30. A reusable type for “test result”
  31. Letting the test result handle assertion results
  32. Encapsulating data components of test_result_t
  33. Preventing “uncaught” errors
  34. Reporting “risky” tests
  35. Modularization
  36. Publishing the framework as a reusable FPM package
  37. Conclusion

TDD by Example

  1. Introduction
  2. About the test framework
  3. A first test case
  4. Considering a starting water level
  5. Taking into account a stop level
  6. Refactoring: Introduce Parameter Object
  7. Introducing pump state
  8. Keep running or stop running
  9. Loading configuration
  10. A generic data structure for configuration values
  11. Testing the happy path
  12. Adding the custom check procedure
  13. Testing a custom check procedure
  14. Implementing the configuration loader
  15. Checking for required values
  16. Type validation
  17. Good test names
  18. Conclusion

Testing Hard-to-Test Code

  1. Introduction
  2. Returning instead of printing output
  3. Wrapping calls to system_clock
  4. Using a procedure pointer
  5. Replacing behavior with a polymorphic service
  6. Conclusion

Dependency Location and Injection

  1. Introduction
  2. Initialization procedures and temporal coupling
  3. Splitting service locator and service factory
  4. Introducing a service container
  5. Copying by default
  6. Stateful services
  7. Sharing services as pointers
  8. Freeing up memory
  9. Service dependencies
  10. Passing and fetching dependencies
  11. Forcing services into module variables
  12. Turning procedures into services
  13. Conclusion

Epilogue

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub