Programming languages such as C, Haskel and Clojure their focus is more on the funcional aspects of programming. Such languages concentrate more in writing programs using functions.
In these languages, writing functions is easy but things tends to get hard when combining these funtions to create a complete software.
In order to make programming easier, computer scientists came up with a new methodology and that is creating a computer program by mimicking real life entities. This led to the development of Object Oriented Programming
.
Object Oriented Programming languages such a Java
, C++
and .Net
are based on classes and objects. Programmers started migrating from funcional programming languages such as C
to Object Oriented Programming languages such as Java
Programmers have to express their logic through classes and objects. This inturn results into creating lengthy source codes. Example, a simple program to calculate product of two numbers.
//Java program to find product of a number class Product{ public static void main(String[] args){ int x, y; x = y = 30 System.out.println("The product is: " + (x * y)); } }
Not in every scenerio do programmers have to create classes and this programming technique consumes time. If we were to write the above same code above in C which is a functional programming language, the code would be less lengthy as an example below.
#include <stdio.h> void main(){ int x, y; x = y = 30; printf("The product of the two numbers is: " + (x * y)); }
The two programs perform the same function but the program in C
is less lengthy as compared to Java
. But the problem arises when the C programmers want to utilize the Object Oriented Programming
features which appears to be the setback of C
, likewise Java
developers wont have the benefit writing less lengthy code. To resolve these issues, Python turns out to be the solution.
Python is a programming language that has both functional and object oriented features just like C and Java respectively. In python, the program to find the product of two numbers is as follows.
x = y = 30 print("The product of two numbers is: ",(x + y))
Python was developed by Guido Von Rossum in the year 1991 at the center of Mathematics and Computer Science under the Dutch Government management. At the time, Guido Von Rossum was developing system utilities using C
where he had to interact with Bourne Shell
which was based on Unix
. The invention on Python came when he felt the necessity of developing a language to bridge the gap between C and Shell.
Guido Von Rossum gave his programming language a name Python after Monty Python’s Flying Circus and this is because he wanted a peculiar short unique name. Python was first released to the public on 20th February 1991.
Python is licenced as open source software, it’s source code can be accessed and modified as per developer’s project and anybody can download it from www.python.org.
The following are the reasons as to why python has been gaining popularity in the programming community.
Open source: Python can be freely downloaded, modified and used as per user or developers’s need. In shot there is no need to pay for Python software
Platform independent: When Python code gets executed, it generates byte code
which inturn can be run on any hardware or operating system.
By using PVM(Python Virtual Machine) the byte code instructions can be ran on any computer system.
High level language: As a high level language, python has been designed to be simple and easy to learn hence letting a programmer to focus more on business logic and not on the complexity of the syntax and semantics. In addition, Python uses English like words to make it even more simpler
Dynamically typed: Python doesn’t require declaration of anything. As a dynamic programming language, anything can be changed at run-time that hasn’t been explicitly coded in the source code. Any assigned statement binds a name to an object having any data type. This means that an object can be re-assigned to a different object bearing different data-type.
Portable: Python outputs the same result regardless of the computing machine. Python pgivees the same result to different computing machines sinnce it is platform independent. Once a python program has been written, it can run on any machine with the help on PVM(Python Virtual Machine). Conversely, Python has system dependent modules that are specific to a particluar operating system.
Interpreted: After writing a python program, we compile its source code using a Python compiler to generate byte code
or intermediate code
.
The byte code
then executed by the Python Virtual Machine. The Python Virtual Machine has an interpreter than converts the byte code
into machine code which can be understood by a processor.
Extensible: Source codes written in other programming languages such as C++
or C
can be integrated into Python the executed using PVM(Python Vitual Machine)
This can also be seen in other flavours of pythos such as:
Embeddable: This on the other hand, involves integrating Python
code into a program written in C
, C++
,Delphi
or Java
.
Scalable: A program written in Python can be transfered to another platform, system or infrastructure and take full control of that system or infrastructure.
Large library and useful modules: Python has a large number of pre-build modules which are available for developers to take advantage of such as:
Computer understands machine code instructions comprised on 0’s and 1’s, for that case we are bound to convert our source code written to whatever programming language into machine code(0’s and 1’s) for execution. In order to convert our source code into machine code we need a compiler.
However, the Python compiler converts the source code into byte code
first before being converted into machine code.
byte code
?A byte code is a set of instructions created by Python developers to represent all types of computer instructions, each byte code instruction has a size of 1 byte(8 binary digits).
These code instructions can be viewed in .pyc
file.
What is the purpose of PVM(Python Virtual Machine) ? The purpose of PVM is to convert the byte code instructions into machine code.
After software developers design, create, test and supply a software to the end user, there are various ways on which the end user executes the software.
.pyc
file, then he/she installs the PVM then run the byte code inside the .pyc
file..pyc
file, PVM and the required Python Library. Here the PVM, .pyc and the Python Library are converted into a single executable file where the user can easily execute the program by clicking it.
The technique of converting Python software into is called frozen binaries
. In programming languages such as C
and C++
programmers have to allocate and de-allocate memory dynamically in run-time. They often use functions such as malloc()
and free()
to allocate and de-allocate memory respectively.
In Python, memory allocation and de-allocation are done during run-time automatically by the Python Virtual Machine. Therefore the programmer doesn’t have to allocate memory when creating an object or de-allocate memory when deleting an object.
Quick Links