metoppv / improver

IMPROVER is a library of algorithms for meteorological post-processing.
http://improver.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
105 stars 89 forks source link

Function purity / mutating inputs #1736

Open benfitzpatrick opened 2 years ago

benfitzpatrick commented 2 years ago

As per @cpelley's note, look at functions in IMPROVER and see how many both mutate their input and return output. It might be that we just want them to do one but not both. Function purity might be nice for most. Discuss with other core IMPROVER developers, then if agreed, do the work to change the functions (and/or redocument them), or propose follow on work.

cpelley commented 2 years ago

Thanks for raising @benfitzpatrick For functions where we identify a NEED to modify an object in-place (perhaps to save on memory by avoiding copies), we could adopt an approach like pandas by having an inplace=False keyword argument (making things explicit). In general, my feeling is that methods on objects are intuitively in-place operations, while module functions, given an object would not be (i.e. having an argument to make the later behaviour in-place as per suggestion above).