According to Online Historical Encyclopaedia of Programming Languages(HOPL) there are 8945 programming languages from the 18th century to the present. These programming languages are created by a person, small groups or organisations. Some of the languages are general while others are designed for specific purposes. We would see more programming languages being created as the power of the hardwares advances and our evolving needs.
The languages may differ in terms of their syntax and semantics. We can draw parallels between the natural languages. Natural languages are those languages spoken by the people for communication; such as Dzongkha, Tshangla, English, et al.
All these languages are to help the human to write code to instruct the computers. These languages are categorized as high level, middle level and low level programming languages. However, computers understand machine code only. So compilers or interpreters are used to convert human-readable code into machine code.
In most of these programming languages the fundamentals are the same. That is why, if you master one language it would be easy to learn other programming languages. Some of the fundamental concepts are Data Types, Variables, Operators, Data Structures, Loops, Control Statements and functions.
I will briefly touch those concepts and try to relate them with examples.
Data TypesLet's say you want to write a program to generate a student report card. You need to get data like student name, marks obtained for each subject and status of the promotion. The student name would be in alphabets. The marks of the subjects could be a whole number or with a decimal. And the status of the promotion of the student could be either pass or fail.
The data type of student name is a string, marks could be either integer or a float, and the status of the promotion is boolean.
Knowing the types of the data ensures we collect them in the correct value and in the correct format. This also makes sure that the data are interpreted the same by the computer and programmer.
VariablesIn mathematics or experiments, a variable is a quantity that changes depending on certain factors. However, in computer science, a variable is like a container that stores a value. This container is a space in the computer memory. The data type of a variable depends on the type of value stored in it.
If we have to use the same data more than once in your code then it is better to store the data in a variable. In the previous example, we need to get the marks of each subject and then those marks are used to calculate the average marks obtained by a student. Here, english marks can be stored in a variable called english_marks, dzongkha marks in dzongkha_marks, etc. Thus we just need to get the marks once only.
The programmer needs to follow certain conventions in naming variables. In order to enhance the readability of the code, variable names are usually descriptive.
OperatorsThe operators used in computer science are similar to one used in mathematics. The operators are grouped as Arithmetic operators, Comparison operators and Logical operators.
Arithmetic operators includes addition(+), subtraction(-), division(/), multiplication(*) and modulo(%). All arithmetic operators are similar to mathematics except the modulo operator returns the remainder part of the division. For example, 5 % 3 returns 2.
Comparison operators are also called relational operators. It includes greater-than(>), less-than(<) , equal-to (==) and not-equal-to(!=). Here == is the equal-to operator and = is the assignment operator. When two or more expressions are compared the boolean value will be returned.
Logical operators includes AND(&&), OR(|) and NOT(!). In Python we have used both the symbols and the word.It is used to connect two or expressions. Expressions with logical operators also return a boolean value; either True or False.
Data StructuresIn a variable we can store only one value at a time. And there are times we need to store more than one value, that is when data structure comes to the picture. In python we have learned data structures like list, tuple, dictionary and set. Each data structure has their own unique properties and methods to manipulate the values or objects stored in them.
ListList is a collection of values enclosed within square brackets. The values with string data type must be enclosed in double quotes while integer, float and boolean are written as they are. List is a mutable which means we can add or remove values from the list once it is created. For example, I would store student names and marks in a list.
TupleTuple is also a collection of values enclosed inside a parenthesis. It is immutable which means the items stored can’t be changed once it is created. I would use tuples to store bank details. So that the details will not be changed intentionally or accidentally.
DictionaryDictionary as well is a collection of values enclosed inside curly brackets. It is called a dictionary because the items are represented in terms of name and value pair. I would prefer to organize the student’s report card in the dictionary. Representation in the dictionary would be more clearer than in the list.
SetSet is another collection of distinct values enclosed in curly braces preceded by a set keyword. I would use a set to store student id so that distinct identification of the students.
Those are some of the data structures and there are more important ones that you can explore. Understanding the data structures is an asset in solving problems.
LoopsWhen you write programs to develop an application, some parts of the program keep repeating. In such cases we can use loops to reduce the number of lines of code. In most programming languages loops are implemented using for and while statements.
You should use a for loop when you know the number iteration(number of repetition) beforehand. Let’s say you know that you require marks of 20 students. In this case you can use a for loop. A while loop is usually used when you are uncertain about the number of iterations.
For example, while loop is used in computer games. A game continues till the user quits or runs out of lives or other conditions. In this case, the programmer can’t be certain of the number of loops which are dependent on a player.
Our students usually find loop concepts difficult to understand, especially the while loop. It becomes more complex when the loops are nested; for within another for loop. It’s recommended to invest a lot of time.
Control StatementsThe computer makes decisions using conditional statements. Humans also make decisions based on certain conditions. In almost all the programming languages I have come across uses if and switch statements. However, switch statements are not available in the Python programming language.
Let’s say you got students' names and marks of different subjects. And the averages of the marks are calculated. In order to check whether the students passed or failed based on the average marks if statements can be used; if the average marks is greater than 40 than the student passed else failed.
FunctionsFunction is a block of code that does a specific task. The function helps in code reuse and also improves the code readability of the program.
Let’s say you want to develop a user login system. We can break down the system into different tasks like user login, register and change password. Now we can create a function for user login, register and change password. We can reuse the function as many times as you need in your code.
Again the functions implemented in different programming languages defer in terms of the syntax and semantics.
Finally, those are the concepts that you need to learn in almost all the programming languages created so far. If you understand these concepts in depth in a programming language then learning any other programming languages would be easy.
Learning a programming language is one thing and using it to solve problems requires another set of skills. I feel learning a programming language is like learning a natural language; their syntax and semantics. And writing the codes to solve real life problems is akin to writing an essay or a book in natural language. I strongly believe creating software is an Art.