Updated June 7, 2023
Concepts of Programming Languages
I knew nothing like the basics when I started learning programming language concepts. I just knew the basics of A+ and Network+. But C, Java, Python was altogether different world for me. Besides, hardly anyone could help me since I was the only one among my friends from an IT background. So, I finally decided to start learning from the most common concepts of programming languages out there. I then came to know about C and C++. I started learning C, but I was head over heels since importing modules, and all those stuff usually went bouncer for me. I knew C for a month; then, I thought C was a bit tough and thus started learning Bash.
Though bash is a scripting language and not a programming language concept, it was, again, difficult to understand. I got stuck at cron jobs and stuff. Finally, with nowhere to go, I started learning Python. But heck no…It was the worst. When I used to write codes in C, I had to write every piece of code. But in Python, there was a lot of magic going around actually to understand what was happening. And yup, this magic differs from the ones you are considering, and ‘magic’ is the official word in Python. Magic in Python means that you want to do something, and that thing happens, but you don’t know how it happened. Python tends to get complicated in that regard.
When I began learning programming language concepts, I struggled to understand why I needed to import a specific module. For example, when writing a hello world program in C, we usually write ‘include stdio.h’ or ‘include conio.h’. So, my question was, why only this? I even saw some people not even typing in the conio part. Similarly, in Python, to do complex math, we import cmath, but why don’t developers already combine math and cmath and shorten the whole process of importing it twice? But then I thought, let’s do one thing. Let’s start with the very basics of programming language concepts.
I decided to hit rock bottom and start back from there. And as of now, I can write any program in almost any concept of programming languages, such as Java, C, C++, Haskell, Scala, Python, Ruby, and many more. Over the years, I have built a rock-solid foundation in programming concepts. And the main reason for this because I cleared all of my fundamentals in concepts of programming languages. While a solid understanding of programming fundamentals is crucial for comprehending advanced concepts, they are often overlooked. This is precisely why I chose to write this blog. Let’s begin by exploring the fundamental concepts and terminology of programming languages.
Pseudo Codes, Mathematics, and Comments on Concepts of Programming Languages
If you know math, then most things will come by quickly. Writing a program is not much different from solving a math problem. Besides, when learning functional languages like Haskell, math is the only thing that can be a prerequisite for understanding the concepts of programming languages. Simple mathematics and pseudocodes can solve most problems. Math and pseudocodes go hand in hand. For example, whenever you want to solve a specific issue, please write it down in simple algebraic and geometrical format in the form of theorems and hence proved formats. Now write down these pieces of code in pseudocode format. When I say pseudocodes, I mean writing the program in such a way that when you write an actual program, you would only need to change some values and vocabulary, and the program would work. For example, say, to calculate the sum of all the numbers from 1 to it reaches to 20, one can write pseudocode in the following manner:-
let x = 1x = x + 1if x = 20, then stop and print xelse continue and repeat everything again |
This code is a bit buggy, but we are not here for that. As you can see, first, I assigned the value of x to 1, then added 1, 2, and 3 until it reached 20. If x reaches 20, the program will stop and print the output; else, it will continue and repeat the same thing. So, converting this pseudocode into an actual program becomes straightforward when you write it. And also, make sure you write comments next to all those lines which you think are confusing. The main reason for writing words is because it doesn’t get executed first; second, you can always point out what you did, where you did it, and why you did something. Comments may not benefit small blocks of code 5-10 lines long. However, in cases with multiple files, each containing around 40-50 lines of code, comments can make it easy to identify the location of bugs or understand why a particular file was imported just by examining the comments.
Variables, Constants, and Datatypes on Concepts of Programming Languages
A variable is a container storing various data types, such as strings, numbers, or other values. An array is a collection of multiple variables of the same type held together. If I refer to the previous example, you can see that I have assigned the value of one to X at the start; thus, it makes X a variable. Here the one is an integer, and X is the assigned variable. Similarly, I can also input string into a variable as well. A simple example would be:-
X = ‘Hello world’echo $X |
The above is a concept of programming languages that can be executed in bash, an excellent Linux terminal. X is assigned the value of the string ‘hello world,’ and echo prints whatever is inside of X. We use the dollar sign to represent that we are calling the value of X.
Similarly, constants are also variables, but constants cannot be changed, unlike variables. In the first example of concepts of programming languages, I assigned the value of one to X; then, I kept increasing it in ascending order. A constant value, such as X being set to one, remains unchanged throughout the program’s execution and cannot be modified until the program is terminated or the relevant programming concepts are exited. Data types are just bifurcations of different types of data—for example, real numbers, integers, floats, or Boolean and strings. In programming, True and False boolean values are often represented by 1 and 0.
Functions and Procedures on Concepts of Programming Languages
In this programming language, concepts and functions can be assigned values representing large code pieces. Programmers often design functions to avoid repetitive code and execute it with a single syntax by calling the function. A Function is just an encapsulated task that contains multiple lines of instructions to be executed. When writing large pieces of code, functions are often pre-developed and stored in separate files within a folder for easy organization and reuse. When a piece of code needs to be executed multiple times, it can be done by calling the file name or function name in which it is defined. This will execute the entire piece of code within the file.
All variables inside a function are usable only until the code’s execution is completed because functions have their workspace. Once it gets completed, the variable gets undefined (except in the case of garbage collection, which I have not mentioned here since that is a huge topic to discuss). Additionally, functions can be nested within another function. This means that one function can call any other function, even itself. Experts do not recommend doing so, as it can cause the program to crash or become unresponsive unless executed in a controlled manner.
On the other hand, procedures are almost similar to Functions except that functions always return a value, whereas a procedure is just the execution of commands. When learning programming concepts, you may see many people use the terms functions and procedures interchangeably. But this isn’t the case if you start learning functional concepts of programming languages like Haskell or Scala. One thing to remember when writing functions is to ensure they don’t have side effects.
Conditions and Loops on Concepts of Programming Languages
Condition and Loops are something I have explained previously in the example. They go by the manner of something like this ‘If it rains, I will be wet. Else I will not be. Yeah, that sounds like a dumb example, but that is the most easier it can get. Conditional statements depend on each other. These programming constructs are often interconnected and are typically structured using conditional statements such as “if-then-else” and “elif”. These days, nested conditional statements are common. However, without proper indentations and comments, the program can become hard to understand and highly buggy.
Loops execute a block of code, functions, or procedures repeatedly until a desired result is obtained. If you check my first example, you will see I have stated something to repeat everything. Thus, loops are compelling, making concepts of programming languages extremely compact. But too much use of loops will make the program slow. They should be used only when necessary. Loops go in the form of “for, While, Do-While loop, and for-each loop.” The most commonly used loops are the while loop, do-while loop, and for a loop. The pseudocodes for the while, do-while, and loop would go in the following manner:-
While Loop: |
While the condition is false,{execute the code and check whether the condition is true}Stop when the condition becomes true. |
Do – While Loop: |
Do{execute a code} while (check whether a statement is true, else repeat the Do) |
For Loop: |
for ( a, b, c){execute code} |
In the above code, a is a condition that gets executed once, and first, b is the condition of the loop, and c is the code that gets executed once the loop is about to stop. |
Control Structures on Concepts of Programming Languages
Control Structures in programming concepts are just a combination of conditions, loops, and other code sets. The control structure is a block of codes, which analyzes the whole structure of the programming language concepts, then decides which to go further, as in whether to stop, repeat or call for a function or execute the other block of codes. In short, to be more specific, Control structures in concepts of programming languages are just a decision-making process that decides the flow of a program. One whole piece of code performs in the following block-type of manner:
Pre ConditionControl StructureEnd of Control StructurePost Condition |
Object-Oriented Programming and Functional Programming
Now, this is one of the most debated topics by developers. Object-oriented programming deals with just ‘objects.’ Don’t take that statement too literally. Object-oriented programming, or OOP, basically deals with data that contain fields, attributes, procedures, and methods. C is an object-oriented programming language concept. Python is not a purely object-oriented language. But there have been books where some people tend to say that Python can, too, work in an object-oriented way. Functional programming languages are more math-based, similar to object-oriented programming. A purely functional concept of programming language I can remember is Haskell. You can make Scala work fully functional, even though it is not so by default. On the other hand, Haskell doesn’t tend to work like other concepts of programming languages, and it is based on pure logic. Bug in Haskell is significantly less since there are at least no side-effects of functions in Haskell, unlike Java, C, Python, or most other languages.
All in all, programming concepts are elementary to learn. One needs to input proper logic into a problem and find multiple ways of solving a problem rather than just one to sort the problem. Once you have the basics right, developing software or learning frameworks based on them would be a piece of cake.
Recommended Articles
This has been a guide to Programming Languages Concepts. Here we have discussed how programming concepts are easy to learn if one has a proper idea of solving problems in multiple ways. You may also look at the following articles to learn more –