You do this work long enough, and you can usually tell in under a minute if you're dealing with code that takes shortcuts, or a big pile of copypasta from SO.
The question above is mixing dealing with errors and debugging with refactoring and modifying. I think this is the heart of the issue. One can (and should) modify and refactor "good" code too.