Have you ever made origami? To make quality origami, you have to follow the instructions carefully. Thereâs a pattern of folds you have to follow, and you need to make sure that each one is clean, and in the right place.  If you do, your final product will be elegant.

If you take a few liberties with the steps or maybe donât press the folds down exactly in the same place as the instructions, youâll end up with a result, but it wonât look as great.
Itâs the same with writing functions. You need to follow a set of guidelines so that what youâre creating will end up clean and usable.  Letâs look a little more closely at how to do that with the 4 steps mentioned in the video.
You canât design something if you donât know what itâs for. It seems simple, but sometimes people get so excited about doing something, like writing a function, that they forget to pin down exactly what it's for. That's why it's the first step! You can formulate this in a simple sentence.
Once you're sure about the goal of your function, itâs critical to name it based on what itâs supposed to accomplish. This makes it easier to use, both for you or anyone else that happens upon it.Â
This is whatâs going to come out of the function. In other words, what itâs going to produce. If you have a print function, then the printed document would be the end result. If your function is for making a chocolate cake, itâs going to create a chocolate cake. đđ«You also need to be very explicit about the end result, because otherwise, your computer might not do what you expect.  Â

In the cake function example, this would be the ingredients. Â It would be something like: flour, baking powder, butter, sugar, eggs, vanilla, and so on. Â It would also specify the measurements for each one.

This is when you think up all the steps for how you put the ingredients together. It seems simple, but it is actually the trickiest and most time-consuming part. Â You have to take a lot of details and steps into account. Should the butter be cold, room temperature, melted? How should you incorporate the butter into the mixture? Â When do you add the vanilla?
Even the actions themselves need to be details. Â If you say âbreak the eggs,â the computer might just smash them on the floor:

âBreak eggs into a bowlâ might lead to a bowl full of eggs and egg shells! You have to tell the computer exactly how, what, when, how many times, and so forth.
Itâs worth it to take the time to do this. Â After all, a function works a little like a strategic plan in American football (sorry, everyone else on the planet). đ Football is run entirely on pre-planned strategies, called plays. Â These plays dictate where every single player should place themselves, where they should move, and how they should interact with the opposing team. The plays are written and defined by the coach, and all the players memorize them ahead of time.
When the players huddle up, the quarterback calls out a play by name, just like a function. Based on what he calls, the players take their positions and get ready to execute what's needed for the play to be put in motion. If the play is poorly written, or the logic isnât clear, even the best players will fail to execute it correctly.
Your functions are the same: good ones take time and energy to plan out.
Writing clean functions is critical for making sure they work well.
Good function writing takes 4 basic steps:
Choose a goal and name the function accordingly
Define the end result
Define what the function requires as input
Implement the logic