Skip to content

Instantly share code, notes, and snippets.

@nyctef
Last active November 15, 2017 02:22
Show Gist options
  • Save nyctef/1fffae6302d6af9d6e3f395111ca68ba to your computer and use it in GitHub Desktop.
Save nyctef/1fffae6302d6af9d6e3f395111ca68ba to your computer and use it in GitHub Desktop.
Don't make decisions across different levels of abstraction

instead of

if (use_alternate_frob_strategy) {
  bloo_counter += 1;
}

do

if (use_alternate_frob_strategy) {
  convert_bloos_to_frobs = true;
  dispose_bloos = true;
  count_bloos = true;
}

[...]

if (count_bloos) {
  bloo_counter += 1;
}

advantages:

  • each part of the code is individually a lot more obvious
  • the whole meaning of use_alternate_frob_strategy is a lot clearer

disadvantage:

  • larger disconnect between cause and effect; more code reading required to understand why bloo_counter is being modified
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment