Imagine making a hamburger:
- Place the bread down
- Add the burger patty
- Add the pickles
- Place the bread on top
What if you had to say each step every time you ordered a hamburger? It’s tedious. It takes a long time. (How do you fit that on a menu?) And it risks making mistakes.
In this lesson you will learn a solution to that problem: methods. A method is a reusable set of instructions that perform a specific task. Developers use methods to make their code organized, maintainable, and repeatable.
You might hear methods also called functions — for now, the difference isn’t important to us.
By the end of this lesson you will be able to recognize methods, call them with multiple arguments, capture their returned values, and define a basic method.
- First make two burgers without methods: add bread, patty, pickles, and bread.
- Then make two burgers with the method
- Which way is faster? Which is more prone to mistakes?