Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xpepper/acbc47ecbe9ec77646fc to your computer and use it in GitHub Desktop.
Save xpepper/acbc47ecbe9ec77646fc to your computer and use it in GitHub Desktop.
CleanCode episode 3 on functions

Functions

Functions should be small

Four to six lines long

  • "A long function is where the classes go to hide"

Functions should do only one thing

  • "if a function manipulate more than one level of abstraction, it's clearly doing more than one thing"
  • "in order for a function to do one thing, it must not cross level of abstraction"

Extract 'till you drop!

But level of abstractions are fuzzy... is there a deterministic way to decide if a function is doing more than one thing? Extract 'till you drop!

"If you can extract one function from another, this means that the original function was doing more than one thing by definition"

"I look at braces as an opportunity to extract!"

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