Functions, the building block that turns your code into a beautiful sculpture or into something that resembles a plate of spaghetti.

Functions seem like a mysterious concept, but the essence of it is a set of instructions you can call by name, and give an input, that will then do something and give you an output.

As an example let say we have a function called Add_Numbers this function will 3 and 6 together and output 9. Let’s see an example below in pseudo code.

// the keyword function is used to define a function. The rest of this code snippet will be explained below.
function Add_Numbers(){
    return 3 + 6
}

There are a lot of new concepts in the example, so lets breakdown everything in the above example.

“function”: This is just a keyword we will use to state what follows is a function.

“Add_Numbers”: This is the name we give to the function. This can be anything you want it to be. In other posts we will learn more about Naming Conventions in coding.

“( )”: The round brackets / parentheses are where we will put arguments. This will be covered in the following post.

“{ }”: Curly brackets / braces is used as a way to define where the code starts and ends.

“return”: This keyword does as it says on the tin, it returns a value. Not all functions need to return a value.

Those are all the components to making a function. A basic one, but a function none the less!

Functions come in a great many shapes and sizes, they will be covered in more detail in the following posts!

Congratulations! You have leveled up in programming!

Next Demystifying Programming – 7 Function Arguments

Previous Demystifying Programming – 5 Loops

Leave a Reply

Your email address will not be published. Required fields are marked *