This post will be somewhat conceptual but equally as important as any of the other ones. It’s 2 weeks into the Lighthouse Labs course right now and one of the instructors David VanDusen has dawned on me an extremely important concept. Method Contracts.
Methods/functions in programming have all have a specific purpose, and their method contracts define their functionality. When writing any method, you should be able to clearly state it’s method contract in one sentence WITHOUT using the word and.
The blueprint for a method contract is as follows:
- What arguments are the method parameters taking, and what are the argument types?
- What functionality is the method responsible for?
- What are the values the method returns and their value types?
- What exceptions do the method raise under what circumstances?
A method is definitive and well designed when you can answer those 4 questions without a shadow of a doubt.
Invaluable expertise; I’ll never look at methods the same again.