To be clear this is often sloppy code that shouldn’t have been written. But in a legacy codebase this stuff can easily happen.

A huge chunk of a "legacy codebase" is "sloppy code that shouldn’t have been written"

Unless you're inheriting code written by Bill Atkinson or something.