Functions & Methods in 60 Seconds

Eddie Knight
2 min readFeb 6, 2019

--

Ever play Mouse Trap?

If you look at advanced code, it can seem like a jumbled mess of words, numbers, and squiggles that perform magic. That might be partially right.

Real code is like a Rube-Goldberg machine. Ever play mouse-trap? In that staple children’s board game, you build a complex machine one part at a time. Pretty soon, you have a comical but effective mouse trap.

Before I continue, I’ll note the difference between functions and methods: One is used in a class, and the other isn’t. Effectively, they’re the same thing- so I’ll just say “function” from now on.

Writing a is similar to setting up one part of the Rube-Goldberg machine.

When triggered, the function does a specific little job. If we were to program mouse trap, one of the functions would drop the cage at the end. Like a variable, you want the name to clearly describe what the function does, so we would call that function “dropCage”.

Each programming language has it’s own way to do the little tasks necessary to accomplish your goals, but all of your code will built from small functions that work together. A huge key to success is this: Keep your functions small and specific!

Next, learn about how you can control your functions using parameters & arguments!

Tell me whether I should write more content like this by hitting the applause button or leaving a comment below!

--

--

Eddie Knight

Senior Consultant at Citihub & Developer Advocate for Probr