Skip to content

Instantly share code, notes, and snippets.

@kchien
Last active August 18, 2022 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kchien/0b2fe50ff4e2bbef1e1126a3773f0a54 to your computer and use it in GitHub Desktop.
Save kchien/0b2fe50ff4e2bbef1e1126a3773f0a54 to your computer and use it in GitHub Desktop.
Personal thoughts on writing readable, friendly code so those that come after you can maintain it

Description

This is a work in progress and is not to be interpreted as hard and fast rules or laws, but rather just guidelines and observations from the code I've been working on.

Unexplained numbers, constants, etc. in tests

Example: a test that I was reading made an assertion that expected an audit count to increase by seven (7). It wasn't obvious at all why the SUT would generate seven audit records. I suppose this exposed another code smell, since a lot of the auditing occurred magically (implicitly via ActiveRecord callbacks), so I would recommend: "don't test implicit, hidden behavior" by testing other things.

This could be filed under Martin Fowler's extract method refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment