4 ms·
> Logging is an example of code duplication. Is it? What am I missing here?
by aranchelk 5y ago
> Logging is an example of code duplication.
Is it? What am I missing here?
- xboxnolifes 5y agoI think the idea is you have: (1) Some code that does a thing (2) Another line of code that logs that the thing happened And, like in-lined documentation, the code can diverge from the text that says what it does.
- aranchelk 5y agoPrescriptive example from the article: userRoles.addMember( p ); RoleAssignedEvent.publish( p, roleName ); Seems to have the exact same risk of divergence. Depending on the language you can (and I have) used decorators/higher order functions to log the invocation of a function with its name and arguments. Zero risk of divergence there, but it was still logging not some kind of event system. The problem of divergence seems to me to be orthogonal.
- seanhunter 5y agoSo the author proposes we replace it with: (1) Some code that does a thing (2) Another line of code that sends an event that the thing happened