Is global data ever appropriate in functional programming? I’d be interested in what Scala FP experts think about that. I am not an FP expert, but I do try to apply the basics. Virtually all of my classes are immutable case classes, for example.
I am developing prototype software in Scala for an air traffic control automation concept that I proposed several years ago called Trajectory Specification. I recently had a paper published on it in the AIAA Journal of Air Transportation for anyone who might be interested:
https://arc.aiaa.org/toc/jat/27/2
Although my software is a prototype, I try to apply the same basic standards that would apply to actual operational software in the field. No, I can’t develop operational ATC software by myself, but my goal is to develop software that can be used as a starting point for operational software (i.e., not just a “throw-away” prototype).
In any case, here is the reason for my question. I have come to the conclusion that global data is sometimes appropriate in FP, but I’d like to get feedback to make sure I am not missing something important.
I have two examples of where I think global data is justified in my application: airspace data and wind data.
Airspace data is static data about the airspace, including airspace boundaries, named waypoints, and runway parameters. It seems to me that this data should be conveniently available without the tedious boilerplate of references passed down the stack (which can be several levels deep).
Wind data is slightly more dynamic. It is currently updated once per hour (and possibly at a higher rate in the future), but it seems to me that it too should be available without having to pass it down the stack. Care must be taken when it is updated, but that is not particularly difficult with basic locks.
I realize that immutable case classes cannot contain references to global data, but that should not be a problem. References to global data cannot be included as fields in immutable classes, but they can be accessed in methods of those classes when necessary. For example, if I need to know airspeed, I can pass groundspeed to a method that subtracts the along-track component of wind speed to obtain airspeed.
What do you think?