Friday, October 11, 2019

introduction-to-programming

What is computer program and programming


Programming is an art, skill, poetry that is mastered through immense practice, patience, and experience. Before I formally define programming, let us talk about what is a computer program?

What is a computer program?

A Program is a set of instructions compiled together in a file to perform some specific task by the CPU (Central Processing Unit). It is a series of binary numbers (0s and 1s) arranged in a sequence, which when given to the computer performs some task.

Computer is a dumb machine with expeditious computational speed. It can give quick results to many of the complex scientific calculations but it can’t perform a task on its own. A computer needs set of instructions to do some task. This set of instructions is contained in a computer program. Computer program is basically in binary language i.e. series of 0s and 1s. A large bunch of programs makes the computer functional without which the computer would be like a paralyzed machine.

You may think computer as an idiot person who does not know to cook. If you provide ingredients for cooking Pasta to that idiot person, you cannot expect a delicious dish. However, if you provide ingredients along with the full step-by-step recipe of cooking Pasta then you may expect a real Pasta from that idiot person. Same is the concept with computers, for computers the ingredients are data (might be an integer, string, images, videos or anything) and the recipe is a program.

Computer and computer program

In my early ages one question always ponders in my mind, how can I create my own programs? Smaller but effective and my own. Programs like Calculator, Notepad, Music Player, A Website and many complex as a Remote Administration Tool, Search Engine etc. I found programming is the only way through which I can create my own program. Surely you won’t be creating complex and big software’s in few days, with little or no programming knowledge and experience. But definitely, you can create different small programs designed for specific tasks.

What is Programming?

Programming is the process of writing an algorithm into a sequence of computer instructions. Or you can simply say it is the process of writing programs. We generally transform the solution of a specific problem into computer language. It is the only way through which we can create our own programs and can execute them on a computer. Programming requires skill, logical thinking and lots of experience.

Programmers are the person who writes programs in a specific computer programming language. They are highly skilled, hard working, problem solvers. The world’s first programmer was Ada Lovelace. She was widely known for her work on Charles Babbage’s Analytical Engine (general-purpose mechanical computer).

World's first programmer - Ada Lovelace

Various programming paradigms


Programming paradigm is a way to classify programming languages according to their style of programming and features they provide. There are several features that determine a programming paradigm such as modularity, objects, interrupts or events, control flow etc. A programming language can be single paradigm or multi-paradigm.
With the wide spread of programming, various programming paradigms came into existence. Some popular programming paradigms are:

Imperative programming

Imperative programming is the oldest paradigm and is still in practice. It is the widely practiced paradigm in the day-to-day programming. It mainly focuses on steps to be done and works on the logic of “First do this then do that”. It defines a sequence of statements in order of which the operations must take place. In imperative programming, the control flow is explicit and depend on collection of GOTO statements. Imperative programming lacks the support of modularity.
Examples of imperative programming languages are – Assembly, C, C++, Java etc.

Below is the imperative programming approach of listing the first and last name of students from a list student whose marks is greater than 90.
names = []
i = 0
totalStudents = length(student)
start:
    if i >= totalStudents then goto end
    current = student[i]
    marks = current.marks
    if marks < 90 goto next
    addToList(names, current.firstname + current.lastname)
next:
    i = i + 1
    goto start
end:
    print names

Declarative programming

Declarative programming focuses on the logic of computation neglecting the control flow. It specifies what the result should be, without specifying how to obtain the result. Declarative programming generally does not contain if-else, loops and other control flow statements. Imperative programming defines each minute steps to get the result, whereas in contrast declarative programming only defines the logic of computation.
Popular declarative programming languages are: SQL, XQuery
Below is the declarative programming approach to get first and last name of students from a list student whose marks is greater than 90.
select firstname, lastname
from student
where student.marks >= 90

Structured programming

Structured programming is a kind of imperative programming, focuses on modular programming. It makes extensive use of for, while, subroutines, blocks and sub-blocks, rather than simply using GOTO which leads to complex and tangled code. Structured programming was introduced as an improvement over the imperative programming approach to get more control over the program.
Examples of structured programming languages are – C, C++, Pascal, Ada etc.
Below is the structured programming approach to get first and last name of students from a list student whose marks is greater than 90.
names = []

for i = 0, i <= length(student), i = i + 1 {
      if student[i].marks >= 90 {
            addToList(names, student[i].firstname, student[i].lastname)
      }
}

for i = 0, i <= length(names), i = i + 1 {
      print(names[i])
}

Procedural programming

Procedural programming is derived from structured programming. It inherits all properties of structured and imperative programming. Procedural programming is based on procedural calls. Each statement of a procedural language is either procedure call or data assignment.
Note: Procedures, routines, subroutines and functions all are same thing with little difference.
Some popular procedural programming languages are: C, Pascal, BASIC, Fortran
Below is the procedural programming approach to get first and last name of students from a list student whose marks is greater than 90.
void main() {
    names = getStudentNames()
    printList(names)
}

names getStudentNames() {
    names = []
    for (i = 0; i <= length(student); i = i + 1) {
        if (student[i].marks >= 90 ) {
            addToList(names, student[i].firstname, student[i].lastname)
        }
    }
    return names
}

void printList(names) {
    for (i = 0; i <= length(names); i = i + 1) {
        print(names[i])
    }
}

Object oriented programming

Object Oriented Programming paradigm is widely practiced programming paradigm. It is based on the concept of objects. Objects are real world entity. Everything present around us is an object. Every object has two important property attribute (data) and behavior (function).
For example:
Car is an object having
attributes – type, color, model etc.
behavior – turnLeft(), turnRight(), accelerate() etc.
Object-Oriented programming is also inherited from imperative and procedural programming.
Popular object oriented programming languages are – Simula-67, Java, C++, C# etc.
Below is the object oriented programming approach to get first and last name of students from a list student whose marks is greater than 90.
for s in student {
      if s.marks >= 90 {
            print(s.firstname + s.lastname);
      }
}

Functional programming

Functional programming paradigm is completely different programming approach from all paradigms mentioned above. Functional programming uses a combination of functions calls to drive the flow of the program. The result of a function becomes the input to another function.
Popular functional programming languages are – Python, Lisp, Clojure, Haskell etc.

What is a compiler and its need?


A Compiler is a program or set of programs that converts source code written in a high-level language to low-level language (assembly language or machine language). A programming language can have many compilers. For example – GCC C, Turbo C, Quick C etc. are different compilers for C programming language.

Why do we need a compiler?

A Computer understands only binary language and executes instructions coded in binary language. It cannot execute a single instruction given in any other form. Therefore, we must provide instructions to the computer in binary language. Means we must write computer programs entirely in binary language (sequence of 0s and 1s).
But think for a while, how cumbersome programming would have been, if we have to write every program as a sequence of 0s and 1s? It would have been a nightmare to write complex software's. Humans are good at giving instructions in English language, whereas computers can only process binary language.
So, there was a need of a translator that translates the computer instructions given in English language to binary language. Hence, to accomplish the job of a translator compiler was invented. The world’s first compiler was written by Grace Hopper in 1952 for the A-0 programming language.

What do a compiler do?

Apart from translating source code from high level language to low level language, compiler has other responsibilities too. After reading source code written in high level language it performs below operations -
  1. Performs a pre-processing of source code. Gather all files required for the source code to compile.
  2. Parses the entire source code. Checks for any syntax errors in the source code.
  3. Performs a thorough syntax analysis of the source code. To understand the structure and semantic of the source code.
  4. Optionally translates the source code in an intermediate code known as object code to enhance the performance.
  5. Translates the object code to binary language known as executable code.

Source code and object code

LanguageCompilersDeveloped by
BASICFreeBASICFreeBASIC development team
QuickBASICMicrosoft
Visual BasicMicrosoft
CGCC CGNU Project
Borland Turbo CEmbarcadero
Quick CMicrosoft
C++GCCGNU Project
Borland C++Borland
Visual C++Microsoft
C#Visual C#Microsoft
MonoXamarin
JavajavacSun Microsystems (Owned by Oracle)
gcjGNU Project

What is an interpreter and its need?


An interpreter is a program that translates source code written in high-level language to machine code. It is similar to compiler and does the same task of translation from high-level to low-level language. Despite of its similarity, the working mechanism of interpreter and compiler are different.
An interpreter does not translate whole code at once like compiler. Rather, is reads entire source code at once. Translates single instruction to machine code or some intermediate code. Then executes the translated machine code instruction immediately and translates next instruction if needed.

Why do we need an interpreter?

The first and vital need of an interpreter is to translate source code from high-level language to machine language. However, for the purpose there exists another program called compiler. The compiler also translates source code from high-level language to machine language. So, why we need an interpreter when there exists a similar software compiler.
The real need of interpreter comes where compiler fails to satisfy the software development needs. The compiler is a very powerful tool for developing programs in high-level language. However, there are several demerits associated with the compiler. If the source code is huge in size, then it might take hours to compile the source code. Which will significantly increase the compilation duration. Here interpreter comes handy and can cut this huge compilation duration. Interpreters are designed to translate single instruction at a time and execute them immediately.

An interpreter also comes handy when you frequently update the source code. As if it takes 5 minutes to compile entire source code. If you have updated it 5 times. Then the total compile time would be 25 minutes which is significantly big. However, if we use an interpreter we can reduce this compile time.

Compiler vs Interpreter – Difference between compiler and interpreter


Compiler and interpreter both are tools to translate source code from high-level language to machine language. Both does the same task of translation. But the working mechanism of compiler is different from interpreter. Below are some differences between compilers and interpreters

Translation mechanism

Compiler reads entire source code and translates to machine language at once. If any error is generated during compilation, it terminates the entire process without executing single instruction.
Whereas interpreters translate instruction-by-instruction. It reads single instruction at a time. Translates it to machine language and executes it. This process continues till the last instruction. If any error is generated during the interpretation, it terminates the execution of further instructions.

Translation time

Compilers reads entire source code at once. It pre-processes, parses, analyses the source code and translates it to machine code at once. Hence, it requires more translation time than interpreters.
Interpreters reads single instruction of source code at a time. Unlike compilers, it doesn’t translate entire source code to machine code at once. Rather it translates the source code, instruction by instruction. Hence, requires less translation time.

Program speed

Compilers translate entire source code at once. After the compilation process, it generates an executable file containing complete instruction set of the program in binary language. Hence, it doesn’t require any further translation which enhances the program execution speed.
Interpreters translate the source code instruction by instruction. It translates single instruction then executes it. Each time before executing an instruction, it must first translate it to machine language. Which increases the overhead of interpretation, hence decreases the program execution speed.

Memory consumption

Compilers usually generate an intermediate code called object code, during the compilation process. Hence it requires more memory than interpreters.
Unlike compilers, interpreters do not generate any intermediate code, during the interpretation process. Thus, interpreters are memory efficient.

Debugging

Compilers continues to process entire source code also if it contains errors. It generates list of all error messages (if any) at the end of the compilation process. Which makes debugging a little difficult.
Interpreters stops the interpretation process if an error is encountered. It generates the error message as the error is met during the interpretation process.

Deployment

Compilers generate an executable file of the source code. This executable file is deployed instead of source code. Which increases the security, by hiding the source code from others.
Interpreters do not generate any executable file of the source code. Therefore, in the case of interpreter’s entire source code needs to be deployed. Causing a security concern as the source code is visible to everyone.

Compiler vs Interpreter

Summing up the differences between compiler and interpreter.
CompilerInterpreter
It translates entire program to machine code at once.It translates single instruction of a program at a time.
It requires more translation time.It requires less translation time.
Program execution is faster than interpreted languages.Program execution is slower than compiled languages.
It usually generates additional intermediate code.It doesn’t generate additional intermediate code.
It requires more memory as it generates extra object code.It requires less memory as it does not generate any intermediate code.
Errors are displayed at the end of the compilation process.Errors are displayed as they met.
Executable code needs to be deployed.Source code needs to be deployed.
Example of compiled languages – C, C++, Java etc.Example of interpreted languages – Ruby, Python, Shell script etc.

Life cycle of a computer program

A computer program goes through many phases from its development to execution. From the human readable format (source code) to binary encoded computer instructions (machine code). Here in this section, I will be explaining the different phases of a program during its entire lifespan.


Source code

Source code is a plain text file containing computer instructions written in human readable format. It is simple text file written by programmers. It contain instructions in high-level language that the programmer intended to perform by a program. Source code is later compiled and translated to Object code.


Programmer writing source code

Object code

Object code is a sequence of computer instructions in an intermediate language. It is generated by compiler after the compilation process. The compiler reads source code written in high-level language and translates it to an intermediate language. After translation a file containing instructions encoded in some intermediate language is generated called object code.
Note: The intermediate language may or may not be machine language.
Despite of being in binary language object codes cannot execute by its own as they lack the main entry point. Various object codes are further linked together by a linker to generate final executable file.


Source code and object code

Machine code

Machine code is a set of computer instructions written or translated in machine language. It is the final executable file generated by compiling, assembling or linking several object files together. It is the only code executed by the CPU.
Machine code and object code both are encoded in machine language and may seem to be similar in nature. However, you can directly execute a machine code, whereas object codes cannot execute on their own. Machine code is the result of linking several object files together. Whereas object code is a result of translating source code of single module or program into machine language. Machine code always contains an entry point to the program while object code does not contain any entry point.

 Machine code


Programming language – history and popular languages


The world of computer science, programming and software development starts here. Before I formally define programming language. Let’s dissect it. Programming language is made of two parts “programming” and “language”. We already learn't about what is programming. Here we will learn about language. Think for a while and try to define what language means.

What is language?

Language is a medium of interaction between two objects. It is a system of communication between any two objects either spoken or written.
Humans have invented thousands of spoken languages to interact with other human. Birds, animals, insects and every living creature interact in their own language. Likewise machine also interact with the other machines in the language of electrical signals. Computers internally interact in the language of low voltage and high voltage (known as binary).

Programming language

Programming language is the language of computers. Through programming language, we can communicate with a computer system. Computers can only understand binary, but humans are not comfortable with binary number system. Humans cannot interact fluently with computers in the language of 0's and 1's. Programming language act as an interface between computers and humans.

Programming languages are used to create programs. A computer program is intended to perform some specific task through computer or to control the behavior of computer.
Using a programming language, we write instructions that the computer should perform. Instructions are usually written using characters, words, symbols and decimal. These instructions are later encoded to the computer understandable language i.e. binary language. So that the computer can understand the instructions given by human and can perform specified task.
Thousands of programming language have been created till date and many are still being developed every year. Every programming language is designed for some specific purpose. Such as FORTRAN, OCaml, Haskell are best suited for scientific and numerical computations. Whereas Java, C++, C# are best suited for designing server applications, games, desktop applications and many more.

History of programming language

Earlier when there was no concept of programming languages. Computer instructions are directly given to the computer in decimal or binary form. These instructions are given through punch cardsmagnetic tapes or through switches.
Later on when computer started growing, more and more programs were written day-by-day. Writing programs completely in binary was cumbersome and error prone. Therefore, we developed various mnemonics for different instructions. These mnemonics are in human readable format. Such as ADD for adding values of two registersJMP for conditional controls. Now, the programs were written using mnemonics and decimal values known as assembly language.
Mnemonics are short abbreviated English words used to specify a computer instruction. Each instruction in binary has a specific mnemonic. They are architecture dependent and there is a list of separate mnemonics for different computer architectures.
Mnemonics gave relief to the programmers from writing programs directly in binary language. However, it was still a tedious work to remember the complete list of mnemonics for various computer architectures.
During 1950's the first high-level programming language Plankalkül was written. As the computer started expanding from scientific to business and to many other fields. Many more high-level programming languages were written for various specific purposes. Unlike binary and assembly, programs in high-level languages are written in English like statements. High-level languages are programmer friendly, less error prone, easy to write and maintain.
High-level languages were like a magic wand to the programmers. However, they lack the facility to perform several low-level activities. Which gave the birth to several other programming languages with different paradigms. During 1960's to 1980's several popular programming languages were written for specific purposes. This was the phase when the programming languages were more influenced. Popular languages developed during this period was ALGOL, Lisp, C, Prolog etc. Languages that we use today are either directly or indirectly inherited from this period.
Modern programming languages provide rich support of security and error checking. They provide higher level of abstraction of hardware details.
There are thousands of programming languages and many more are being written every year.  Here is a list of some popular programming languages and software’s written using them.
LanguageSuited forPopular software’s developed
JavaServer applications,
Web development,
Desktop applications,  Android apps development
Netbeans,
Eclipse,
OpenOffice,
Google (backend),
Facebook (backend)
CSystem softwares,
Device drivers,
Database packages,
Operating Systems
UNIX,
Linux,
C++ (Programming language)
Microsoft Windows (Some parts)
C++Operating system,
Game development,
Server applications,
Database packages,
Desktop applications
Microsoft Windows,
Apple OS-X,
Google (backend),
Adobe Photoshop,
MySQL,
Various popular games
PythonWeb development,
Software development,
Game development,
Network programming,
Mobile apps development
Google,
YouTube,
Quora,
Blender,
BitTorrent
C#Windows Client applications,
Web applications development,
Mobile apps ,
Cloud apps development,
Enterprises application
Microsoft Office,
Visual Studio,
Almost all Microsoft websites (ASP.NET),
Microsoft SQL Server
PHPWeb developmentFacebook,
WordPress,
Wikipedia,
Yahoo,
Flipkart
JavaScriptWeb development,
Apps development
Almost all popular website uses JavaScript for client side activity.
SQLDatabase development,
Database Query
Almost all software’s database uses SQL as query language.
RubyWebsite developmentTwitter,
Github

Classification of programming languages

Thousands of programming languages have been written till date. Each for some specific purpose. Some programming languages provide less or no abstraction from the hardware. Whereas some provide higher abstraction. To separate programming languages on the basis of level of abstraction from hardware, they are classified into various categories.

Programming languages are basically classified into two main categories – Low level language and High level language. However, there also exists another category known as Middle level language. Every programming language belongs to one of these category and sub-category.


Below image describes the abstraction level of programming languages from hardware.  As you can see machine language provides no abstraction. Assembly language provide less abstraction from the hardware. Whereas high level language provides a higher level of abstraction.


Low level languages – advantages and disadvantages

Low level language abbreviated as LLL, are languages close to the machine level instruction set. They provide less or no abstraction from the hardware. A low-level programming language interacts directly with the registers and memory. Since, instructions written in low level languages are machine dependent. Programs developed using low level languages are machine dependent and are not portable.

Low level language does not require any compiler or interpreter to translate the source to machine code. An assembler may translate the source code written in low level language to machine code.

Programs written in low level languages are fast and memory efficient. However, it is nightmare for programmers to write, debug and maintain low-level programs. They are mostly used to develop operating systems, device drivers, databases and applications that requires direct hardware access.

Low level languages are further classified in two more categories – Machine language and assembly language.

Classification of low level programming language

Machine language

Machine language is closest language to the hardware. It consists set of instructions that are executed directly by the computer. These instructions are a sequence of binary bits. Each instruction performs a very specific and small task. Instructions written in machine language are machine dependent and varies from computer to computer.
Example: SUB AX, BX = 00001011 00000001 00100010 is an instruction set to subtract values of two registers AX and BX.

In the starting days of programming, program were only written in machine language. Each and every programs were written as a sequence of binaries.

A Programmer must have additional knowledge about the architecture of the particular machine, before programming in machine language. Developing programs using machine language is tedious job. Since, it is very difficult to remember sequence of binaries for different computer architectures. Therefore, nowadays it is not much in practice.

Assembly language

Assembly language is an improvement over machine language. Similar to machine language, assembly language also interacts directly with the hardware. Instead of using raw binary sequence to represent an instruction set, assembly language uses mnemonics.
Mnemonics are short abbreviated English words used to specify a computer instruction. Each instruction in binary has a specific mnemonic. They are architecture dependent and there is a list of separate mnemonics for different computer architectures.
Examples of mnemonics are – ADD, MOV, SUB etc.
Mnemonics gave relief to the programmers from remembering binary sequence for specific instructions. As English words like ADD, MOV, SUB are easy to remember, than binary sequence 10001011. However, programmer still have to remember various mnemonics for different computer architectures.
Assembly language uses a special program called assembler. Assembler translates mnemonics to specific machine code.
Assembly language is still in use. It is used for developing operating systems, device drivers, compilers and other programs that requires direct hardware access.

Advantages of low level languages

  1. Programs developed using low level languages are fast and memory efficient.
  2. Programmers can utilize processor and memory in better way using a low level language.
  3. There is no need of any compiler or interpreters to translate the source to machine code. Thus, cuts the compilation and interpretation time.
  4. Low level languages provide direct manipulation of computer registers and storage.
  5. It can directly communicate with hardware devices.

Disadvantages of low level languages

  1. Programs developed using low level languages are machine dependent and are not portable.
  2. It is difficult to develop, debug and maintain.
  3. Low level programs are more error prone.
  4. Low level programming usually results in poor programming productivity.
  5. Programmer must have additional knowledge of the computer architecture of particular machine, for programming in low level language.

High level languages – advantages and disadvantages


High level language is abbreviated as HLL. High level languages are similar to the human language. Unlike low level languages, high level languages are programmers friendly, easy to code, debug and maintain.

High level language provides higher level of abstraction from machine language. They do not interact directly with the hardware. Rather, they focus more on the complex arithmetic operations, optimal program efficiency and easiness in coding.

Low level programming uses machine friendly language. Programmers writes code either in binary or assembly language. Writing programs in binary is complex and cumbersome process. Hence, to make programming more programmers friendly. Programs in high level language is written using English statements.

High level programs require compilers/interpreters to translate source code to machine language. We can compile the source code written in high level language to multiple machine languages. Thus, they are machine independent language.

Today almost all programs are developed using a high level programming language. We can develop a variety of applications using high level language. They are used to develop desktop applications, websites, system software’s, utility software’s and many more.
High level languages are grouped in two categories based on execution model – compiled or interpreted languages.


Classification of high level language on the basis of execution model

We can also classify high level language several other categories based on programming paradigm.


Classification of high level language on the basis of paradigm

Advantages of High level language

  1. High level languages are programmer friendly. They are easy to write, debug and maintain.
  2. It provide higher level of abstraction from machine languages.
  3. It is machine independent language.
  4. Easy to learn.
  5. Less error prone, easy to find and debug errors.
  6. High level programming results in better programming productivity.

Disadvantages of High level language

  1. It takes additional translation times to translate the source to machine code.
  2. High level programs are comparatively slower than low level programs.
  3. Compared to low level programs, they are generally less memory efficient.
  4. Cannot communicate directly with the hardware.

Low level vs High level language – Difference between low and high level language


We already learn't about low level and high level language. We have seen their advantages and their disadvantages. Let’s compare them on various grounds.

Memory efficiency

Low level languages are memory efficient. They generally consume less memory.
High level languages are not memory efficient. They generally run inside a specific runtime environment. Also there are several other programs running concurrently to increase optimal efficiency of the program which consumes memory. Thus, the overall memory consumption of high level language is comparatively more than low level language.

Easiness

Low level languages are machine friendly languages. To write a program in low level language we must know binaries or mnemonics of low level instruction sets. Remembering various instructions sets for different architectures is nearly impossible. Thus, low level programming is difficult to learn. Learning low level languages requires additional knowledge and experience about the specific machine architecture.
High level languages are programmer’s friendly language. Programs in high level language are written using English statements. Which is much easier to remember than low level binaries or mnemonics. Hence, high level programming is easy to learn.

Portability

Low level language contain low level computer instructions set. These instructions are machine dependent and are different for different architectures. Hence, programs developed are also machine dependent and are not portable.
High level languages uses English statements to write programs. They are further translated to machine language using a compiler or interpreter. There exists a separate compiler or interpreter for different machine architectures. That translates the source to specific machine language. Hence, high level languages are machine independent and are portable.

Abstraction level

Low level language provides less or no abstraction from the hardware. They are the closest language to the hardware. They interact directly with the computers register and memory.
High level language provides a high level of abstraction from the hardware. They run on top of the machine language. They do not interact directly with the computers register and memory. There is a layer of operating system and other software’s through with they interact with the hardware.

Debugging and maintenance

Low level languages are more error prone. From small syntactical error to big memory leaks. Error detection and maintenance is a tedious and time taking process.
High level languages are less error prone. Almost all syntactical errors are identified using compilers or interpreters. They are generally easy to debug and maintain.

Additional knowledge and experience

Low level languages are machine dependent. They require a prior knowledge of the particular computer architecture. Before one can actually write a program for that computer.
High level languages are machine independent. They do not require any prior knowledge of the computer architecture.

Applications

Low level languages interacts directly with the hardware. They provide very less or no abstraction from the hardware. But, they are blazing fast when compared to high level languages. Thus, they are generally used to develop operating systems and embedded systems.
High level languages provide a higher level of abstraction from the hardware. Nowadays, almost all software’s are developed using a high level language. It is used to develop variety of applications such as – desktop applications, websites, utility software’s, mobile applications etc.

Differences between low level and high level programming language.

Summing up the differences between low level and high level programming language.

Low level languageHigh level language
They are faster than high level language.They are comparatively slower.
Low level languages are memory efficient.High level languages are not memory efficient.
Low level languages are difficult to learn.High level languages are easy to learn.
Programming in low level requires additional knowledge of the computer architecture.Programming in high level do not require any additional knowledge of the computer architecture.
They are machine dependent and are not portable.They are machine independent and portable.
They provide less or no abstraction from the hardware.They provide high abstraction from the hardware.
They are more error prone.They are less error prone.
Debugging and maintenance is difficult.Debugging and maintenance is comparatively easier.
They are generally used for developing system software’s (Operating systems) and embedded applications.They are used to develop a variety of applications such as – desktop applications, websites, mobile software’s etc.

Introduction to Programming – Errors


Errors are the mistakes or faults in the program that causes our program to behave unexpectedly and it is no doubt that the well versed and experienced programmers also makes mistakes. Programming error are generally known as Bugs and the process to remove bugs from program is called as Debug/Debugging.
There are basically three types of error:
  1. Compilation error or Syntax error
  2. Runtime error or exception
  3. Logical error

Compilation error

Compilation errors are the most common error occurred due to typing mistakes or if you don't follow the proper syntax of the specific programming language. These error are thrown by the compilers and will prevent your program from running. These errors are most common to beginners. It is also called as Compile time error or Syntax error. These errors are easy to debug.
Example: Typing int as Int

Runtime error

Run Time errors are generated when the program is running and leads to the abnormal behavior or termination of the program. The general cause of Run time errors is because your program is trying to perform an operation that is impossible to carry out.
Example: Dividing any number by zero, Accessing any file that doesn't exist etc are common examples of such error.

Logical error

Logical error will cause your program to perform undesired operations which you didn't intended your program to perform. These errors occur generally due to improper logic used in program. These types of errors are difficult to debug.
Example: Multiplying an uninitialized integer value with some other value will result in undesired output.

What are Tokens in programming

Smallest individual element of a program is called as Token. Everything you see inside a program is a token.
For example - Suppose an English sentence. "C language is an awesome language. C was developed by Dennis Ritchie at AT&T Bell labs in 1972."
The above sentence is made of Alphabets (a-z A-Z)Blank spacesDigits (0-9) and special characters (full stop in our case). These are building blocks or basic elements of our sentence. Similarly there are various basic programming elements that makes any program.
There are five types of tokens.
  1. Keyword
  2. Identifier
  3. Operator
  4. Separator
  5. Literal

What are Keywords?

Keyword is a reserved word whose meaning is already defined by the programming language. We cannot use keyword for any other purpose inside programming. Every programming language have some set of keywords.
Examples: int, do, while, void, return etc(Note: These keywords are common to C and C influenced languages).

What are Identifiers?

Identifiers are the name given to different programming elements. Either name given to a variable or a function or any other programming element, all follow some basic naming conventions listed below:
  1. Keywords must not be used as an identifier.
  2. Identifier must begin with an alphabet a-z A-Z or an underscore_ symbol.
  3. Identifier can contains alphabets a-z A-Z, digits 0-9 and underscore _ symbol.
  4. Identifier must not contain any special character (e.g. !@$*.'[] etc.) except underscore _.

Examples of some valid identifiers

num, Num, _num, _Num, num1, Num1, _num1, _Num1, _1num, _1Num, _num_, number_to_add
etc.

Examples of some invalid identifiers

1num, number to add, 1_num, num-to-add, num@
etc.

What are Operator?

Operators are the symbol given to any arithmetical or logical operations. Various programming languages provides various sets of operators some common operators are:
Lets suppose two variables a=10, b=5
- operator subtracts second operand from first i.e. a - b and results 5.
OperatorDescriptionExample
Arithmetic operator
Arithmetic operator are used to perform basic arithmetic operations.
+Adds two operand.a + b gives 15
*Multiplies two operands.a * b gives 50
/Divides two operands.a / b gives 2
%Modulus operator divides the first operand from second and returns the remainder. It is generally used for checking divisibility.a % b gives 0 (As 10/5 will have 0 remainder)
Assignment operator
Assignment operator is used to assign value to a variable. The value is assigned from right to left.
=Assigns value from right operand to left operand.a = 10 will assign 10 in a

Relational operator

Relational operator are used to check relation between any two operands. Whether any of them is greater, equal or not equal.
>If value of left operand is greater than right, returns true else returns false(a > b) will return true
<If value of right operand is greater than left, returns true else returns false(a < b) will return false
==If both operands are equal returns true else false(a == b) will return false
!=If both operands are not equal returns true else false.(a != b) will return true
>=If value of left operand is greater or equal to right operand, returns true else false(a >= b) will return true
<=If value of right operand is greater or equal to left operand, returns true else false(a <= b) will return false
Logical operator
Logical operator are used to combine two boolean expression together and results in a single boolean value according to the operand and operator used.
&&Used to combine two expressions. If both operands are true or Non-Zero, returns true else false((a>=1) && (a<=10)) will return true since (a>=1) is true and also (a<=10) is true.
||If any of the operand is true or Non-zero, returns true else false((a>1) || (a<5)) will return true. As (a>1) is true. Since first operand is true hence there is no need to check for second operand.
!Logical NOT operator is a unary operator. Returns the complement of the boolean value.!(a>1) will return false. Since (a>1) is true hence its complement is false.
Bitwise operator
Bitwise operator performs operations on Bits(Binary level). Lets suppose a = 10, b = 5
a = 0000 1010 (8-bit binary representation of 10)
b = 0000 0101 (8-bit binary representation of 5)
&Bitwise AND performs anding operation on two binary bits value. If both the values are 1 then will result is 1 else will result in 0.
  0000 1010
& 0000 0101
____________
  0000 0000
|Bitwise OR returns 1 if any of the two binary bits are 1 else returns 0.
  0000 1010
| 0000 0101
___________
  0000 1111
^Bitwise XOR returns 1 if both the binary bits are different else returns 0.
  0000 1010
^ 0000 0101
___________
  0000 1111
~Bitwise COMPLEMENT is a unary operator.It returns the complement of the binary value i.e. if the binary bit is 0 returns 1 else returns 0.
~ 0000 1010
___________
  1111 0101
<<Bitwise LEFT SHIFT operator is also unary operator. It shift the binary bits to the left. It inserts a 0 bit value to the extreme right of the binary value. Or we may say it generally multiplies the value with 2.
  0000 1010 << 2 
= 0010 1000
>>Bitwise RIGHT SHIFT operator is an unary operator. It shifts the binary bits to the right. It inserts a 0 bit value to the extreme left of the binary value. Or we may say it generally divides the value with 2.
  0000 1010 << 2
= 0000 0010
Increment/Decrement operator
Increment/Decrement operator is a unary operator used to increase an integer value by 1 or decrease it by 1. Increment/decrement operator are of two types Postfix and Prefix.
++Increment operator will add 1 to an integer value.a++ will give 11
++a will also give 11
--Decrement operator will subtract 1 from an integer value.a-- will give 9
--a will also give 9
Conditional/Ternary operator
Ternary operator as a conditional operator and is similar to simple if-else. It takes three operand.
?:It is used as conditional operator. Syntax of using ternary operator:
(condition) ? (true part) : (false part)
b = (a>1) ? a : b;
will store the value 10 in b as (a>1) is true hence true part will execute, assigning the value of a in b.

What are Separators?

Separators are used to separate different programming elements. The various types of separators used in programming are:
 (Space) \t(Tab) \n(New line) . , ; () {} []

What are Literals?

Literals are constant values that are used for performing various operations and calculations. There are basically three types of literals:
  1. Integer literal

    An integer literal represents integer or numeric values.
    Example: 1, 100, -12312 etc
  2. Floating point literal

    Floating point literal represents fractional values.
    Example: 2.123, 1.02, -2.33, 13e54, -23.3 etc
  3. Character literal

    Character literal represent character values. Single character are enclosed in a single quote(' ') while sequence of character are enclosed in double quotes(" ")
    Example: 'a', 'n', "Hello", "Hello123" etc.

What are Escape sequence characters?


Escape characters are sequence of characters that are converted to some another character which are difficult or impossible to print directly. Characters such as new lines, you cannot print a new line directly in any programming language by hitting enter key. To print new line an special character is given \n which is later converted to new line by compiler. Likewise there are many escape sequence character used in programming languages.
An escape character begin with backward slash \ followed by escape character.

List of all escape sequence characters

Escape characterDescription
\0NULL
\aAlert (Beep)
\bBackspace
\eEscape
\fFormfeed (Return)
\nNew line
\rCarriage return
\tHorizontal Tab (Eight blank spaces)
\vVertical Tab
\\Backslash
\'Single quotes
\"Double quotes
\?Question mark

What is ASCII character code?

ASCII stands for American Standard Code for Information Interchange. It was developed by ANSI (American National Standards Institute).
It is a set of decimal coded value for all basic printable and non-printable characters. For example - A is represented as 65 in ASCII standard. Similarly, there exists an integer value to represent every printable and non-printable character.
ASCII exists in two versions 7-bit ASCII and 8-bit ASCII. The first 7-bit version of ASCII contains 128 characters (including upper and lower case alphabets, digits, punctuations, special characters, non-printable and control characters). It uses 7 bit in memory to represent single character.
Later 7 bit variant of ASCII was extended to 8 bit and is popularly known as Extended ASCII. It uses 8 bit to represent a character and can represent upto 255 characters.

List of all ASCII character codes

 Non-Printable ASCII characters
 Printable ASCII characters
 Extended ASCII characters
BinaryOctalDecimalHexadecimalSymbol
00000000000000NULL
00000001001101SOH
00000010002202STX
00000011003303ETX
00000100004404EOT
00000101005505ENQ
00000110006606ACK
00000111007707BEL
00001000010808BS
00001001011909HT
00001010012100ALF
00001011013110BVT
00001100014120CFF
00001101015130DCR
00001110016140ESO
00001111017150FSI
000100000201610DLE
000100010211711DC1
000100100221812DC2
000100110231913DC3
000101000242014DC4
000101010252115NAK
000101100262216SYN
000101110272317ETB
000110000302418CAN
000110010312519EM
00011010032261ASUB
00011011033271BESC
00011100034281CFS
00011101035291DGS
00011110036301ERS
00011111037311FUS
001000000403220SPACE
001000010413321!
001000100423422"
001000110433523#
001001000443624$
001001010453725%
001001100463826&
001001110473927'
001010000504028(
001010010514129)
00101010052422A*
00101011053432B+
00101100054442C,
00101101055452D-
00101110056462E.
00101111057472F/
0011000006048300
0011000106149311
0011001006250322
0011001106351333
0011010006452344
0011010106553355
0011011006654366
0011011106755377
0011100007056388
0011100107157399
00111010072583A:
00111011073593B;
00111100074603C<
00111101075613D=
00111110076623E>
00111111077633F?
010000001006440@
010000011016541A
010000101026642B
010000111036743C
010001001046844D
010001011056945E
010001101067046F
010001111077147G
010010001107248H
010010011117349I
01001010112744AJ
01001011113754BK
01001100114764CL
01001101115774DM
01001110116784EN
01001111117794FO
010100001208050P
010100011218151Q
010100101228252R
010100111238353S
010101001248454T
010101011258555U
010101101268656V
010101111278757W
010110001308858X
010110011318959Y
01011010132905AZ
01011011133915B[
01011100134925C
01011101135935D]
01011110136945E^
01011111137955F_
011000001409660`
011000011419761a
011000101429862b
011000111439963c
0110010014410064d
0110010114510165e
0110011014610266f
0110011114710367g
0110100015010468h
0110100115110569i
011010101521066Aj
011010111531076Bk
011011001541086Cl
011011011551096Dm
011011101561106En
011011111571116Fo
0111000016011270p
0111000116111371q
0111001016211472r
0111001116311573s
0111010016411674t
0111010116511775u
0111011016611876v
0111011116711977w
0111100017012078x
0111100117112179y
011110101721227Az
011110111731237B{
011111001741247C|
011111011751257D}
011111101761267E~
011111111771277FDEL
1000000020012880Ç
1000000120112981ü
1000001020213082é
1000001120313183â
1000010020413284ä
1000010120513385à
1000011020613486å
1000011120713587ç
1000100021013688ê
1000100121113789ë
100010102121388Aè
100010112131398Bï
100011002141408Cî
100011012151418Dì
100011102161428EÄ
100011112171438FÅ
1001000022014490É
1001000122114591æ
1001001022214692Æ
1001001122314793ô
1001010022414894ö
1001010122514995ò
1001011022615096û
1001011122715197ù
1001100023015298ÿ
1001100123115399Ö
100110102321549AÜ
100110112331559B¢
100111002341569C£
100111012351579D¥
100111102361589E
100111112371599Fƒ
10100000240160A0á
10100001241161A1í
10100010242162A2ó
10100011243163A3ú
10100100244164A4ñ
10100101245165A5Ñ
10100110246166A6ª
10100111247167A7º
10101000250168A8¿
10101001251169A9
10101010252170AA¬
10101011253171AB½
10101100254172AC¼
10101101255173AD¡
10101110256174AE«
10101111257175AF»
10110000260176B0
10110001261177B1
10110010262178B2
10110011263179B3
10110100264180B4
10110101265181B5
10110110266182B6
10110111267183B7
10111000270184B8
10111001271185B9
10111010272186BA
10111011273187BB
10111100274188BC
10111101275189BD
10111110276190BE
10111111277191BF
11000000300192C0
11000001301193C1
11000010302194C2
11000011303195C3
11000100304196C4
11000101305197C5
11000110306198C6
11000111307199C7
11001000310200C8
11001001311201C9
11001010312202CA
11001011313203CB
11001100314204CC
11001101315205CD
11001110316206CE
11001111317207CF
11010000320208D0
11010001321209D1
11010010322210D2
11010011323211D3
11010100324212D4
11010101325213D5
11010110326214D6
11010111327215D7
11011000330216D8
11011001331217D9
11011010332218DA
11011011333219DB
11011100334220DC
11011101335221DD
11011110336222DE
11011111337223DF
11100000340224E0α
11100001341225E1ß
11100010342226E2Γ
11100011343227E3π
11100100344228E4Σ
11100101345229E5σ
11100110346230E6µ
11100111347231E7τ
11101000350232E8Φ
11101001351233E9Θ
11101010352234EAΩ
11101011353235EBδ
11101100354236EC
11101101355237EDφ
11101110356238EEε
11101111357239EF
11110000360240F0
11110001361241F1±
11110010362242F2
11110011363243F3
11110100364244F4
11110101365245F5
11110110366246F6÷
11110111367247F7
11111000370248F8°
11111001371249F9
11111010372250FA·
11111011373251FB
11111100374252FC
11111101375253FD²
11111110376254FE
11111111377255FF










No comments:

Post a Comment