“A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs to control the behavior of a machine or to express algorithms.” (source Wikipedia)

Programming languages have been around for a while now, many people consider FORTRAN (first version appeared in 1954) as the first real computer programming language and even today there are systems which still use it. In the 1970’s C appeared, which was designed by Dennis Ritchie, his programming language was primarily adopted in the Unix environment and the beginning of the 21st century was C’s renaissance era, but nowadays its not so widely spread. Instead of C people tend to use C++ (also called C with classes), developed by Bjarne Stroustrup (I had to honor to chat with him about technology, he is an exceptionally bright mind), the first version appeared in 1979. Since its first version the language has changed much and nowadays has modern constructs like lambda expressions and automatic type deduction system.

Type System

Most programming languages have a type system or simply called types for the usage of variables, of course there are exceptions, like Assembly based programming languages, which are untyped languages.

Typed programming languages can be divided into statically typed and dynamically typed languages, for example Java and C are statically typed languages, meanwhile Python and JavaScript are dynamically typed Languages. Below you can find some examples:

Types can be grouped in three large buckets. The first bucket contains the types which can help to manipulate text (strings). Since most of the developed software applications are designed and used by people, these have to use text when displaying calculation results or when requesting user input. String as a type is the most frequently used in almost every programming language. As you can see in the example above almost in any programming language strings can be defined using double quotes.

The second bucket contains number based types (or numerical types), those which are used for mathematical or statistical calculations or for implementing algorithms. The examples below demonstrate some mathematical calculations in different programming languages using different number types:

Loops

The for loop (or repeat loop)

In many cases programming languages need to execute the same code many times, for example when an ERP (Enterprise Resource Planning) application calculates the salaries and the taxes of employees which have to deducted. Another example is a banking software, which transfers money from one account to another, it repeats the same operation, only the account numbers, the amount of money and the currency changes but the actual operation, like creating the database level transaction, handling the audit tables, sending out the confirmation messages to the clients and so on are changed for each iteration of the transfer operation.

#
# Python code for adding a list of integers
#
sum = 0
for number in [1,2,3,4,5,78,99,101,123,1332,321,3322]:
sum += number
print(sum) # will print 5391 in python

In the code samples above you can see how the for loop can be used to add up elements of an array (or list), the first code section is in Python, where the for in construct is used, then you have the Java code sample, here the array of elements is declared before the for loop. Then we have the sum variable declared. After that comes the for loop - even more it’s a foreach like loop in Java – which sums up the numbers. The last code part is in JavaScript and does the same thing, first we have the array declared, then the sum variable. The sum variable in JS is of type Number.

The do-while loop

Another option is the do while loop it is also called post-test loop. Meanwhile the for loop does not run at all, if the stop condition specified within the loop is false the do while loop for sure executes at least once. The Pascal programming language is interesting from this point of view because it does not have a do while loop, but it does have a REPEAT … UNTIL construct, which is basically the same. On the code below we can see the same sum calculation algorithm what we have implemented before using the for loop.

Be aware that if the numbers array would not have any element, then this code would raise an error, because the loop’s stop condition is evaluated after the first execution cycle.

In programming languages there are other types of loops too, like the while loop.

Conditional statements

Software by it’s nature has to be able to decide based on some conditions what to do. For example, when we want to calculate the absolute value of a number we need to decide whether the number what we want to use is negative or positive. Another example of conditional statements is for example in recommendation engines, there are a lot of conditions, for example if the target audience in mid-age single women then most probably they will be interested in shopping and some party places.

The if-else statement

The if statement is one of the easiest constructs which helps making decisions within our applications. Let’s take a look at some examples:

As you can see in the code there is no major difference between programming languages in case of the If-else statement.

The switch statement

There is one interesting conditional statement in most programing languages, this is the switch statement, it is also called multiway branching. Let’s see the examples below:

//
// Java switch
//
int myAge = 30;
switch (myAge) {
case 20: {
System.out.println("You are too young to get married :P ");
break;
}
case 30: {
System.out.println("You should get married ASAP :P ");
break;
}
default: {
System.out.println("You should have been married or you are way to young to even think about it :D ");
break;
}
}

There are some programming languages, like C and C++ which do not support usage of string in switch statements, this is because in C and C++ there is no real string type, strings are basically an array of characters. For instance, Java, C# and JavaScript do support the usage of the switch statement with string values.

The ternary operator

There are cases in programming when a simple condition has to be used for branching the code execution, of course we could use the traditional if-else construct, but some programming languages has added the ternary operator (for example in Java and C# these the ? and : ). The reason for adding these is that it saves space when using it and makes the code more readable and understandable.

In this article we covered the 4 base concepts (type system, loops, conditional statements and user notification) which appear in every programming language, these can be considered as the building blocks of programming and without these it would be quite hard to build applications in the 21st century.

I am a Software Engineer with over 7 years of experience in different domains(ERP, Financial Products and Alerting Systems). My main expertise is .NET, Java, Python and JavaScript.
I like technical writing and have good experience in creating tutorials and how to technical articles.
I am passionate about technology and I love what I do and I always intend to 100% fulfill the project which I am ...