Sunday, August 6, 2017

Modular Programming

What is Modular Programming?

Modular programming is the process of breaking down a problem into smaller tasks. These tasks can then be broken down into sub-tasks.

Modular programming is an important and beneficial approach to programming problems.

Example

Following diagram is showing how we can divide a task into sub-tasks.

Benefits of modular programming

Distributed development

Modular programming allows distributed development. By breaking down the problem into multiple tasks, different developers can work in parallel. And this will shorten the development time.

Code re-usability

A program modules can be reused in the programs. This is a convenient feature because it reduces redundant code. Modules can also be reused in future projects. It is much easier to reuse a module than recreate program logic from scratch.

Program readability

Modular programming leads to more readable programs. Modules can be implemented as user defined functions. A programs with a plenty of functions is straightforward. But a program with no functions can be very long and hard to follow.

Manageable task

Breaking down a programming project into modules makes it more manageable. These individual modules are easier to design, implement and test. Then you can use these modules to construct the overall program.

Procedural Programming (Procedure Oriented Programming)

What is Procedural Programming?


Conventional programming, using high level languages such as COBOL, FORTRAN and C, is commonly known as procedural programming. In this programming approach, the problem is viewed as a sequence of things to be done such as reading, calculating and printing. A number of functions are written to accomplish this task. The primary focus is on functions.
A program in a procedural language is a list of instruction where each statement tells the computer to do something. It focuses on procedure (function) & algorithm is needed to perform the derived computation.When program become larger, it is divided into function & each function has clearly defined purpose.
The first major procedural programming languages first appeared circa 1960, including Fortran, ALGOL, COBOL and BASIC. Pascal and C were published closer to the 1970s.


Characteristics of Procedural Programming:-

  1. It focuses on process rather than data.
  2. It takes a problem as a sequence of things to be done such as reading, calculating and printing. Hence, a number of functions are written to solve a problem.
  3. A program is divided into a number of functions and each function has clearly defined purpose.
  4. Most of the functions share global data.
  5. Data moves openly around the system from function to function.

Drawback of Procedural Programming:-

  1. It emphasis on doing things. Data is given a second class status even through data is the reason for the existence of the program.
  1. Since every function has complete access to the global variables, the new programmer can corrupt the data accidentally by creating function. Similarly, if new data is to be added, all the function needed to be modified to access the data.
  1. It is often difficult to design because the components function and data structure do not model the real world.

Imperative programming

Procedural programming languages are also imperative languages, because they make explicit references to the state of the execution environment. This could be anything from variables (which may correspond to processor registers) to something like the position of the "turtle" in the Logo programming language.
Often, the terms "procedural programming" and "imperative programming" are used synonymously. However, procedural programming relies heavily on blocks and scope, whereas imperative programming as a whole may or may not have such features. As such, procedural languages generally use reserved words that act on blocks, such as if, while, and for, to implement control flow, whereas non-structured imperative languages use goto statements and branch tables for the same purpose.

Tuesday, August 1, 2017

Flowchart

What is a flowchart?

A flowchart is a pictorial representation of an algorithm. A flowchart is a visual representation of the sequence of steps and decisions needed to perform a process. Each step in the sequence is noted within a diagram shape. Steps are linked by connecting lines and directional arrows. This allows anyone to view the flowchart and logically follow the process from beginning to end. Flowcharts are used in designing and documenting simple processes or programs. Like other types of diagrams, they help visualize what is going on and thereby help understand a process, and perhaps also find flaws, bottlenecks, and other less-obvious features within it. 

The main advantage of flowcharts in programming is that, while drawing a flowchart, a programmer need not pay attention to the details of the elements of any programming language. Hence, he/she can fully concentrate on the logic of the solution to problem at hand.

Flowchart Symbols

Image result

Sample Flowchart

Image result for flowchart examples











Difference Between Compiler and Interpreter

Interpreter

Compiler

Translates program one statement at a time.Scans the entire program and translates it as a whole into machine code.
It takes less amount of time to analyze the source code but the overall execution time is slower.It takes large amount of time to analyze the source code but the overall execution time is comparatively faster.
No intermediate object code is generated, hence are memory efficient.Generates intermediate object code which further requires linking, hence requires more memory.
Continues translating the program until the first error is met, in which case it stops. Hence debugging is easy.It generates the error message only after scanning the whole program. Hence debugging is comparatively hard.
Programming language like Python, Ruby use interpreters.Programming language like C, C++ use compilers.












Monday, July 31, 2017

Translators (Programming Language Translators)

What is a Translator?

A translator is a utility software which converts a source code written in programming language, by a programmer, into executable machine code. Translator takes source code as input and convert it into target language (i.e. machine language) as output. A translator is also known as programming language processor.

Source code

A source code is a set of instructions and commands written by a programmer using a programming language. Basically, source code is the set of instructions written in a programming language to give commands to computer, which is converted by a translator into executable machine code for processing.

Object code

The executable machine code, that has been translated from a programming language, with the help of a translator, is called object code.

Types of Translators

There are three types of Translators:
  • Assembler
  • Interpreter
  • Compiler

Assembler

An assembler is a utility software which converts source code written in assembly language into executable machine code, i.e., object code. An assembler serves as a bridge between symbolically coded instructions written in assembly language and the computer system.

Interpreter

An interpreter is a utility software which converts source code written in high level language into low level language, i.e., machine language. It converts source code into executable machine code line by line and directly executes the code. This means that it does not create object code, but, instead, it directly executes the code while converting it. This makes the execution of the programs faster, but only if program is small. It can be time-consuming if the program is long. So, interpreters are sometimes used to quickly test small sections of a program.
Some of the programming languages that use interpreter are BASIC and LISP.

Compiler

A compiler is a utility software that converts source code written in high level language into low level language, i.e., machine language. It converts source code into object code, at once (not line by line), which is then executed. This process takes some time, which makes the compiler's working slow, but, this is only true for small programs. If program is long then compiler executes it much faster than interpreter. Most of the high level languages use compilers. Some of them are, C, C++, etc.



Saturday, July 29, 2017

Evolution of Programming Languages

Ernest Tello, a well known writer in the field of artificial intelligence, compared the evolution of software technology to the growth of a tree. Like a tree, the software evolution has had distinct phases or "layers" of growth. These layers were built up one by one the last five decades, as shown in the figure, with each layer representing an improvement over the previous one. However, the analogy fails if we consider the life of these layers. In software systems, each of the layers continues to be functional, whereas in the cases of trees, only  the uppermost layer is functional.

 Since the invention of the computer, many programming approaches have been tried. These include techniques such as modular programming, top-down programming, bottom-up programming and structured programming. The primary motivation in each case has been the concern to handle the increasing complexity of programs that are reliable and maintainable. These techniques have become popular among the programmers over the last two decades.

With the advent of languages such as C, structured programming became very popular and was the main technique of the 1980s. Structured programming was a powerful tool that enabled programmers to write moderately complex programs fairly easily. However, as the programs grew larger, even the structured approach failed to show the desired results in terms of bug-free, easy-to-maintain, and reusable programs.

Object-Oriented Programming (OOP) is an approach to program organization and development that attempts to eliminate some of the pitfalls of the conventional programming methods by incorporating the best structured programming features with several powerful new concepts. Its a new way of organizing and developing programs and has nothing to do with any particular language. However, not all languages are suitable to implement the OOP concepts easily.

EVOLUTION


First Generation 

The first generation programming language is machine language, that is just ones and zeros. Programmers had to design their code by hand then transfer it to a computer by using a punch card, punch tape or flicking switches. There is no need to translate the code and it will run straight away. This may sound old fashioned and time taking but it has some advantages, they are:
  • Fast execution of codes.
  • No need of translators.
  • Codes can make use of special features of the processors such as special registers.

And the language had some disadvantages too, they are:

  • Code is machine dependent.
  • Time consuming.
  • Difficult to find error.
  • Difficult to modify.
  • Code cannot be ported to other system, hence, needs to be rewritten for every machine.

Second Generation

The second generation programming language is Assembly language. This language was developed by David J. Wheeler in early decades of 20th century. This language uses alphanumeric mnemonic codes, such as LDA for load and STA for store, therefore, code becomes easier to read, write and understand. Assembly language is also machine dependent, i.e., specific to a particular computer architecture. Assembly language requires a utility software called Assembler to convert the code into executable machine code.

Advantages
  • Fast execution of codes (but, slower than machine code).
  • Codes can make use of special features of the processors such as special registers.
  • Close to English, so, easier to read, write and understand.
  • Easy to modify.
  • Easy to find errors.

Disadvantages

  • Code is machine dependent.
  • Code cannot be ported to other system, hence, needs to be rewritten for every machine.


Third Generation

Although assembly language codes are close to English and are easy to understand, they are can be very slow for writing large programs and also very difficult to find errors in large code. Performing loops and conditionals are also not a straight forward task in assembly language. The third generation programming languages, or the High Level Languages, brought new programmer-friendly features for performing loops, conditionals, etc., and are easier to understand than the assembly language. These languages enable the programmers to write the codes using simple English words and familiar arithmetic symbols. The first high level language developed was FORTRAN, in 1954 by John Backus and a team of IBM software programmers.
Fortran is a general-purpose, imperative programming language that is mostly used for numeric computation and scientific computing. It is a popular language for high performance computing and is also used for the programs that benchmark and rank the world fastest supercomputers.
Some other third generation programming languages are C, C++, JAVA,C#,BASIC,etc.


Advantages

  • Machine independent, i.e., can be ported to other systems.
  • Easy to understand.
  • Easy to modify.
  • Easy to remove errors.
  • Time efficient.
Disadvantages
  • Slow in execution.
  • Requires translator.
  • Might be able to take the best use of the special features of the processor, unlike first or second generation.

Fourth Generation (4GL)

The fourth generation programming languages are also known as very high level languages. These languages are developed to make programming easier and also to develop softwares in less time, hence, reducing development cost of the software. The term 4GL was first used formally by James Martin in 1981, to refer to non-procedural high level languages.
Some fourth generation programming languages are RAMIS, Perl, PHP, SQL, Oracle reports, XUL.

Advantages
  • More programmer friendly.
Disadvantages
  • Sometimes code become inelegant and hard to maintain.

Fifth Generation (5GL)

The fifth generation programming languages are mainly used in artificial intelligence. These language use constraints rather than algorithms, given by programmer, to solve a problem. These languages are designed to make a computer solve a given problem without the programmer. In this way, users can concentrate upon the problems needed to solve and the conditions required to be met, without worrying about the algorithm to solve them.
Some fifth generation programming languages are Prolog,OPS5 and Mercury.











VigLink badge