A former coworker of mine was a huge fan of functional programming, and also deeply allergic to mutation. So if you reused variables like that you’d get an angry earful.
Though if you replaced each subsequent line with df1 and df2 and so on he wouldn’t mind as much.
I can’t opine as to whether one approach or the other is intrinsically better. But echoes of his tirades still ring when I see the same variable name redefined.
I would probably come across as matching that description. So perhaps I can speak for that position a bit.
In this case I would not think re-assigning df as being in violation those principles. Might even be useful if it plays better with how the code interacts with debuggers and version control.
Its not really re-used in the sense that would motivate making up new names for the intermediate steps. It’s clearly just used as a syntactic aid for the
operation chaining. So in my mind both expressions are equivalent from that perspective.
I would probably insist on limiting its scope to precisely that expression though, to maintain that obviousness.
There's no mutation there; it's just rebinding the name. Rebinding is very different from mutation. It wouldn't be my stylistic choice either but your FP friend wouldn't be complaining about mutation here.
Though if you replaced each subsequent line with df1 and df2 and so on he wouldn’t mind as much.
I can’t opine as to whether one approach or the other is intrinsically better. But echoes of his tirades still ring when I see the same variable name redefined.