Functions

  • encapsulate logic that manipulates data.

Aspects of functional abstraction:

DRI:

  • Domain - the set of arguments it can take

  • Range - the set of output values it might return (behavior)

  • Intent - the relationship it computes between input and output

Designing Functions

  • each function should have exactly one job, identifiable with a short name

  • one job, but make it apply to many related situations

  • DRY

  • define functions generally (pow vs square)

Last updated