QamoosTech
Programming FundamentalsFunctions and scopeBeginner

Function

PronunciationFUNK-shun

Definition

A reusable block of code that does one job. You give it inputs and it can return a result.

Where you hear it

Everywhere: "call the function", "extract this into a function", "pure function".

Examples

  • Extract the validation logic into its own function.
  • This function returns null when the user is not found.
  • The function takes a price and a tax rate, and returns the total.

Common mistake

Writing one huge function that does many things. A function should do one thing and be easy to name.

Don't confuse with

Function vs Method: A function is a standalone block of code, whereas a method is a function that is associated with an object or a class.

Say it at work

  • In a meeting or chatI think we should break this logic down into a smaller helper function to make the code cleaner.
  • In an email or ticketPlease ensure that this function includes proper error handling before we merge the pull request.