Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save jamesarosen/b5ab5824bad83753aaed to your computer and use it in GitHub Desktop.

Select an option

Save jamesarosen/b5ab5824bad83753aaed to your computer and use it in GitHub Desktop.
How to Name Things in Programs
  1. You find yourself asking, "I need to arrange some interactions. What should I call the players and the interaction?"
  2. For each interaction
  3. Ask "What message do I want to send?"
  4. Ask "To whom should I send it?" Be as specific as possible. changePassword goes to the PasswordChanger.
  5. Ask "Is there already another recipient that is enough like this one that I am comfortable combining them?" If so, do.

I'm considering refactoring a number Ember.Components that have API interactions to use one or more API service objects. I'm concerned with the layer violation: making API calls in the view layer.

  1. "change password"
  2. changePassword(old, new) -> Promise
  3. PasswordChanger.changePassword(old, new)
  4. Nope
  5. "reset password"
  6. resetPassword() -> Promise
  7. PasswordResetter.resetPassword()
  8. Yeah! PasswordModifier.changePassword, and .resetPassword
  9. "check two-factor token during sign-in"
  10. checkTwoFactorAuth(code) -> Promise
  11. TwoFactorChecker.checkTwoFactorAuth(code)
  12. Maybe. AuthenticationManager fits all three, but it's pretty vague. I probably would combine these, but it's not as clear a win.

With this algorithm, you could get different results depending on the order in which you consider the interactions. A hill-climbing approach would be

  1. For each interaction
    1. Ask "What message do I want to send?" (same as above)
    2. Ask "To whom should I send it?" Be as specific as possible. changePassword goes to the PasswordChanger. (same as above)
  2. Map from Recipient.message pairs to combined recipient name
  3. Choose the most obvious, clear combined name
  4. If you like combining them
    1. do
    2. put the new name back in the pool
    3. choose another name

In the passwords-and-two-factor-tokens case, I'd end up with the same result. It would probably differ (and therefore be a more interesting discussion among the team) with more input interactions.

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