Graduate Program KB

Chapter 3 - Functions

  • Functions should be short and concise.
    • Should have a single purpose and and do it well.
  • Avoid side effect, which is modifying state outside of the function and have a clear return value
    • Not practical because not having side effects means the program is not doing anything.
  • At best functions should not take any inputs:
    • The more number of inputs the more messier the code gets.
    • Should split functions up depending on their inputs as well.
  • Should read from top to bottom, so a function with dependencies should then be declared afterwards,
    • but with javascript, you need to define dependencies (variables) before you call them.
  • Similar with previous chapter, function names should be descriptive. They should be named after their functionality, such as createNewTask() which is a function that creates new task in the context of a to do app.