Commonly Confused Terms in Programming

Commonly Confused Terms in Programming

Stephen Emmanuel's photo
Stephen Emmanuel
¡Oct 20, 2020¡

6 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Hi everyone.

During my first few months of programming experience and relating with other programmers of different languages, I have noticed that some programming terms have been wrongly used interchangeably.

Some of these terms I have decided to differentiate. So sit tight, top up your coffee cup and journey along.

All coding snippets used in this article are in JavaScript.

EXPRESSIONS AND STATEMENTS.

In programming generally, expressions refer to anything that can be evaluated to produce a value (This value can be of any data type). The emphasis here is on the production of a value. If it does not produce a value, it is NOT an expression. It is worth noting that an expression may contain other expressions.

Examples of expressions include:

4    //The value produced here is a number 4

x * y /*The value produced here is the result of multiplying value stored in x  with value stored in y*/

true === !false       /*This is a Boolean expression that produces a Boolean value - true*/

Conversely, statements DO NOT produce anything. They just perform actions which introduces some form of side effects like storing values, creating variables; or affects the control flow of the program like loops, conditional statements, e.t.c.

So basically, statements just state to the interpreter what to do. Take note also that statements may contain expressions or other statements.

var x = 5 + 6;   
/*This is an initialization statement. Stated to the interpreter to create a variable x and store the value produced by the expression (5 + 6) in the variable*/

if (true) {
  /*Body of statement*/
} /*End of statement*/
/*This is a conditional statement. It states to the interpreter that if the condition is true, it should accomplish all that was stated in the body*/

return s;
/*This is a return statement.*/

Some exceptions exist though. For example ++i; This is both an expression (It produces a value, which is the value of i + 1); and a statement (it states to the interpreter to update the value of the variable i).

PARAMETERS AND ARGUMENTS.

This is one famous item on this list, sometimes causing some form of argument (no pun intended) among beginner programmers.

Simply put, parameters are placeholder identifiers used in a function's declaration that points to the value(s) that will be passed to the function when it is called. The value passed to the function when it is called are arguments.

Is this overwhelming? Take a deep breath and read on 🙂.

Let's chill out a little. Let's use a standard football match as an example. (If you know absolutely nothing about football, just read on, trust me, you'll enjoy the ride. By the way, I am a United fan).

In a standard match, there is the home team and the away team. This is a constant in all football matches but this does not mean that all football matches are between the same teams. Today the home team could be Manchester United and the away team Chelsea (it's definitely going to be a spanking). Tomorrow, the home team could be England and the away team Italy, on the same stadium!

Let's get more serious now. We could liken the stadium to a function. Here, in the declaration (when football rules were established), it was stated that all matches consist of two teams - the home team and the away team. This means the function has two parameters - home team and away team. They are constant names that refer to different teams for different matches. So for each match, there is a new call to the stadium function, providing two arguments which are the exact names of the teams that are playing. So the names home team and away team are parameters that will be referring to whatever teams (arguments) will be playing.

Still horribly confusing? ☚ī¸ Gulp some coffee, breathe in and continue.

Take a look at this function:

/*This is the function's declaration, num1 and num2 are the parameters*/
function getSum(num1, num2) {
  var sum = num1 + num2;
  return sum;
}


/*Here the function is called, 5 and 10 are the arguments*/
getSum(5, 10);

This is the function's declaration. The identifiers num1 and num2 are the parameters of this getSum function. They are placeholder identifiers such that when the interpreter encounters num1 in the body of the function, it refers to the first value that is passed to the function when it is called

In summary, parameters are used in a function's declaration, while arguments are used when calling the function.

INITIALIZATION AND DECLARATION.

I think this is quite straightforward. Declaring a variable means telling the interpreter to create a new storage space and name the storage space. That's all there is to it. Nothing more, trust me!

But initializing a variable is telling the interpreter to create a space, name the space and giving it an initial value to put in that space created.

This whole process could be likened to basic farming.

If a farmer goes to his farm - or any other farm - and digs a hole, he has created a space. And that's all he did, he just created the space. Literally anything could happen to the hole. But we don't care!

But if the farmer, after digging out the hole, puts in seeds (INITIAL VALUE), he has initialization the hole. He created the space and put an initial value in that space.

Let's run away from our farms and bring back the coding monster.

var x;

This just tells the interpreter "Hey bro!, I need you to secure a space for me, name that space x. Don't ask me why, just do as I say!".

Of course, computers are dummies. It replies "Yes boss!" and does as you said.

But,

var x = 55;

This tells the interpreter "Hey bro!, Create a space for me, and store the value 55 in it. Don't forget to name the space x!"

Oh wow!, This is getting long, so I'll stop here. There is more though. I will be creating a part 2 for this topic.

Drop a comment if you loved it or learnt something from it or decide to point out something or have questions.

Signing out, Steph Crown ✌ī¸

 
Share this