visit
There are a lot of programming languages out there and most of them are open-source meaning they are open for the public for modification and usage.
Most of them, in terms of structure, are somewhat similar to each other and there's a chance that we will have to interact in not just one language so having basic knowledge about at least basic distinguishable features that they have is worth learning about.In terms of level, languages could be classified as either high or low-level one. What doesn't it mean? Well, the word level here is not just about the difficulty of the learning curve to get started or its usage of it. It is also not just about its superiority over the low-level ones.
Levels, in the context of PLs (or programming languages), point to how the syntax, which I will gonna talk about in a moment, is readable or understandable to human programmers. This means that not all languages are readable to us, at least at first glimpse.
Also, the levels describe the background operations a language will take to create or to do an operation commanded by us. This also means the levels describe the amount of abstraction (or basically just means simplicity or complexity) a language provides, generally speaking.
High-level programming languages are considered high due to valuable reasons. High-level languages have their code consisting of English words called keywords which makes them more readable to us and coding with them just like similar to how to write poems - line by line.
Generally, it provides a high level of abstraction which aims to lessen the difficulty of creating solutions through PLs. The code base of these PLs is easy to maintain or sustain, debug, refactor, and many other modifications.
Simple statement using Java that displays something on the screen
String greeting = "Hello, World.";
// Prints "Hello, World."
System.out.println(greeting);
Compilers and interpreters are applications that convert our high-level code into a machine or binary code that CPUs only understand to do a specific task based on the instructions that we've made. They are a middleman whose task is to just translate our code into a series of 0s and 1s. They are specifically crafted in order to do this task to be thrown to our CPU.
In terms of their difference, interpreters convert our code into machine code right when our program or application runs also known as runtime while compilers translates our code into machine code before our program or application runs also known as compile time. Interpreters are used by dynamically-typed PLs while the compilers are used by static types which we will talk about in the next part.
Low-level programming languages are considered as low due to underlying reasons. Aside from these PLs being the first ones who exist in the early days of computers, the syntax of these languages is highly similar to computer commands.
Generally, the level of abstraction it has are low which makes them albeit complex to use.
The speed and efficiency are one of its great strengths as they directly communicate to the CPU to execute instantly the created code without making any other additional background executions which also makes them for being memory-efficient.
Simple statement using Assembly that displays something on the screen
org 0x100
mov dx, msg
mov cx, len
mov bx, 1
mov ah, 0x40
int 0x21
mov ah, 0x4c
int 0x21
msg db 'Hello, World.', 0x0d, 0x0a
len equ $ - msg
Generally, programming languages could classify as being statically or dynamically typed. It also generally refers to the necessity of stating data types, alongside variables which we will talk about in a second. Both of these types of languages have their own pros and cons.
Dynamically-typed languages are considered loose or flexible because stating data types is not required by their own compilers. This also means that types are only known or recognized as the program or application is running or in runtime.
They are made to have the capability of recognizing these types upon execution that skips, ignores, or completely disregards the so-called type-checking (or basically just a way of a language to check the types and values).
Simple statement using C++ that declares variables with data types
string myFullName = "John Rommel Octaviano";
char myMiddleInitial = 'P';
int myAge = 28;
bool isHuman = true;
Statically-typed languages are considered strong or strict because they tend to require us to state data types on pretty much anything that they are required by their own compilers. This also means that those types are known or recognized before the program or application will run or in compile time.
Simple statement using JavaScript that declares variables without data types
let myFullName = "John Rommel Octaviano";
let myMiddleInitial = 'P';
let myAge = 28;
let isHuman = true;
Syntax is defined as the arrangement of words and phrases to create well-formed sentences in a language. Well, it makes sense because in programming, writing every piece of code must follow the said syntax of a specific language that we code along.
Different syntaxes for creating just a basic variable for dynamic type and static type languages and sample syntax for creating general structures
<declaration type> <name> = <value>;
<data type> <name> = <value>;
if (condition) {
<statements>
}
for(<initialization>; <condition>; <initialization modification>) {
<statements>
}
Note Lastly, when learning the fundamentals of programming, it's also important to note that even though the concepts themselves are not particular to a specific language, meaning it is a general concept most likely applied to the majority of PLs, the syntax on the other hand may vary. It's important to specifically check the official syntaxes to avoid nasty errors. The web has a very plenty amount of resources so kindly check them out to learn more about a particular language.
Most programming languages have their own syntaxes represented through the use of English words like for, do, while, if, else, switch, break, continue, and many more. These are called reserved keywords and they are mostly not allowed to be used in user-specific use cases such as naming something, etc.
They are reserved and specifically intended for special use cases. Only use them in particular use cases where they are needed.
A basic use case that shows that these reserved keywords have unique purposes in a particular language like JavaScript
let foo = 'Mamba';
let bar = 'Coco';
if (foo === bar)
console.log('They are both equal!');
else
console.log('They are not equal!');
for (let i = 0; i <= 9; i++) {
console.log(`${foo} & ${bar}!`);
}
Note One important notion to remember is that doesn't mean a language shared a syntax with another language generally means they are completely similar to each other as a whole. There is still some difference between them such as concepts that are not present in one another.They are generally the same but not at all. All language has their own unique features and we also need to learn those principles in order to grasp them.
The good thing is once we grasp the general principles just like learning the fundamentals itself, adapting to learn other languages became easier and we only need to adjust to those distinct concepts that are present in them.
Statements are just pieces of code that comprehend specific instructions or tasks that we want to accomplish. They're not producing a value on their own, unlike expressions. They are the pieces of code that hold our entire program together and they provide some sort of slots to be filled by expressions.
Expressions on the other hand produce values. Values whether a product of an operation like adding numbers or just a raw value like a number. They fill the so-called slots produced by statements.
Basic addition operation as an example of the combination of statements and expressions using Java
int numOne = 43;
int numTwo = 45;
int sum = 0;
sum = numOne + numTwo;
They are basically just multiple pieces of statements and expressions grouped or enclosed together, commonly by curly braces to do something. They are just multiple lines of code inside these braces to do tasks. Nothing special. Just a grouped source code and that's what a block or code block is.
Basic code that determines if the entered year by the user is a leap year or not using C++
int year;
cout << "Enter a year: ";
cin >> year;
if (year % 400 == 0) {
cout << year << " is a leap year.";
}
else if (year % 100 == 0) {
cout << year << " is not a leap year.";
}
else if (year % 4 == 0) {
cout << year << " is a leap year.";
}
else {
cout << year << " is not a leap year.";
}
return 0;
Conditions in real-life and conditions in programming both work the same way. They are statements that produce expressions that make our computer decide whether they return only 2 types of values - true or false. Depending on the returned value, succeeding tasks are gonna be executed aligned to them.
Just think of true or false as yes or no as responses originated from these conditions. This is a way to make computers create decisions based on specific conditions that we created.
Conditions are used in so-called structures, which is a concept in programming to do more tasks. They are some sort of machine that creates raw materials to be consumed by other machines like structures for other intended tasks.
Pieces of code to show the use case of conditions
if (foo == bar)...
while(foo == bar)...
for(int i = 0; foo <= bar; i++)...
Code using Python that solves quadratic equations
# Solve the quadratic equation ax**2 + bx + c = 0
# import complex math module
import cmath
a = 1
b = 5
c = 6
# calculate the discriminant
d = (b**2) - (4*a*c)
# find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
# displays the result
print('The solution are {0} and {1}'.format(sol1,sol2))