improver icon indicating copy to clipboard operation
improver copied to clipboard

Function purity / mutating inputs

Open benfitzpatrick opened this issue 2 years ago • 1 comments

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.

benfitzpatrick avatar Jun 06 '22 16:06 benfitzpatrick

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).

cpelley avatar Jun 07 '22 08:06 cpelley