Programming Note - 101331
Programming Note - 101331
Computer Program
A computer program is a collection of instructions that performs a specific task when executed by a
computer. A computer requires programs to function, and typically executes the program's instructions in
a central processing unit.
A part of a computer program that performs a well-defined task is known as an algorithm. A collection of
computer programs, libraries and related data are referred to as software. Computer programs may be
categorized along functional lines, such as application software or system software.
Programming is the process of taking an algorithm and encoding it into a notation, a programming
language, so that it can be executed by a computer. Although many programming languages and many
different types of computers exist, the important first step is the need to have the solution. Without an
algorithm, there can be no program.
Algorithm is the step by step procedures of solving problems. Algorithms describe the solution to a
problem in terms of the data needed to represent the problem instance and the set of steps necessary to
produce the intended result.
1
computational efficiency needs to be sacrificed for better readability, it is advisable to use a more
user-friendly approach, unless the processing of an application is of utmost importance.
Efficiency: Every program requires certain processing time and memory to process the
instructions and data. As the processing power and memory are the most precious resources of a
computer, a program should be laid out in such a manner that it utilizes the least amount of
memory and processing time.
Structural: To develop a program, the task must be broken down into a number of subtasks.
These subtasks are developed independently, and each subtask is able to perform the assigned job
without the help of any other subtask. If a program is developed structurally, it becomes more
readable, and the testing and documentation process also gets easier.
Flexibility: A program should be flexible enough to handle most of the changes without having to
rewrite the entire program. Most of the programs are developed for a certain period and they
require modifications from time to time. For example, in case of payroll management, as the time
progresses, some employees may leave the company while some others may join. Hence, the
payroll application should be flexible enough to incorporate all the changes without having to
reconstruct the entire application.
Generality: Apart from flexibility, the program should also be general. Generality means that if a
program is developed for a particular task, then it should also be used for all similar tasks of the
same domain. For example, if a program is developed for a particular organization, then it should
suit all the other similar organizations.
Documentation: Documentation is one of the most important components of an application
development. Even if a program is developed following the best programming practices, it will be
rendered useless if the end user is not able to fully utilize the functionality of the application. A
well-documented application is also useful for other programmers because even in the absence of
the author, they can understand it.
Simplicity: A good programming language must be simple and easy to learn and use. It should
provide a programmer with a clear, simple and unified set of concepts, which can be easily
grasped. The overall simplicity of a programming language strongly affects the readability of the
programs written in that language, and programs, which are easier to read and understand, are also
easier to maintain. It is also easy to develop and implement a compiler or an interpreter for a
programming language, which is simple. However, the power needed for the language should not
be sacrificed for simplicity.
2
Naturalness:- A good language should be natural for the application area, for which it has been
designed. That is, it should provide appropriate operators, data structures, control structures, and a
natural syntax to facilitate the users to code their problem easily and efficiently.
Abstraction:- Abstraction means the ability to define and then use complicated structures or
operations in ways that allow many of the details to be ignored. The degree of abstraction allowed
by a programming language directly effects its writ ability. Object oriented language support high
degree of abstraction. Hence, writing programs in object oriented language is much easier. Object
oriented language also support re usability of program segments due to this features.
Locality:- A good programming language should be such that while writing a programmer
concentrate almost solely on the part of the program around the statement currently being worked
with.
Algorithm is a step by step procedure, which defines a set of instructions to be executed in certain order
to get the desired output.
Note:
An algorithm can be implemented in more than one programming language.
From data structure point of view, following are some important categories of algorithms −
3
Characteristic Features of an Algorithm
Not all procedures can be called an algorithm. An algorithm should have the below mentioned
characteristics −
Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their
input/outputs should be clear and must lead to only one meaning.
Output − An algorithm should have 1 or more well defined outputs, and should match the desired
output.
There are no well-defined standards for writing algorithms. Rather, it is problem and resource dependent.
Algorithms are never written to support a particular programming code.
As we know that all programming languages share basic code constructs like loops (do, for, while), flow-
control (if-else) etc. These common constructs can be used to write an algorithm.
We write algorithms in step by step manner, but it is not always the case. Algorithm writing is a process
and is executed after the problem domain is well-defined. That is, we should know the problem domain,
for which we are designing a solution.
Example:
step 3 − c ← a + b
4
step 4 − display c
step 5 − STOP
pseudo-code: also avoids most issues of ambiguity; vaguely resembles common elements of programming
languages; no particular agreement on syntax programming language: tend to require expressing low-
level details that are not necessary for a high-level understanding
5
Decision Table
Decision tables are used to model complicated programming logic. They can make it easy to see that all
possible combinations of conditions have been considered; when conditions are missed, it is easy to see
this. The tables are composed of 4 parts: conditions, actions, condition alternatives (each column is a
rule), and actions for the rules.
The process used to create a decision table is the following:
1. Identify conditions and their alternative values.
There are 3 conditions: gender, city dweller, and age group. Put these into table as 3 rows
in upper left side.
Gender’s alternative values are: F and M.
City dweller’s alternative values are: Y and N
Age group’s alternative values are: A, B, and C
2. Compute max. number of rules.
Determine the product of number of alternative values for each condition.
2 x 2 x 3 = 12.
Fill table on upper right side with one column for each unique combination of these
alternative values. Label each column using increasing numbers 1-12 corresponding to the
12 rules. For example, the first column (rule 1) corresponds to F, Y, and A. Rule 2
corresponds to M, Y, and A. Rule 3 corresponds to F, N, and A. Rule 4 corresponds to M,
N, and A. Rule 5 corresponds to F, Y, and B. Rule 6 corresponds to M, Y, and B and so
on.
3. Identify possible actions
Market product W, X, Y, or Z. Put these into table as 4 rows in lower left side.
4. Define each of the actions to take given each rule.
For example, for rule 1 where it is F, Y, and A; we see from the above example scenario
that products W, X, and Z will appeal. Therefore, we put an ‘X’ into the table’s
6
intersection of column 1 and the rows that correspond to the actions: market product W,
market product X, and market product Z.
1 2 3 4 5 6 7 8 9 10 11 12
Gender F M F M F M F M F M F M
City Y Y N N Y Y N N Y Y N N
Age A A A A B B B B C C C C
MarketW X X X
MarketX X X
MarketY X
MarketZ X X X X X X X X X X
7
PROGRAMMING LANGUAGE
The description of a programming language is usually split into the two components of syntax (form) and
semantics (meaning).
Machine Language
Machine code or machine language is a set of instructions executed directly by a computer's central
processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an ALU
operation on a unit of data in a CPU register or memory. Every program directly executed by a CPU is
made up of a series of such instructions.
Machine code is the only language a computer can process directly without a previous transformation.
Currently, programmers almost never write programs directly in machine code, because it requires
attention to numerous details that a high-level language handles automatically. Furthermore, it requires
memorizing or looking up numerical codes for every instruction, and is extremely difficult to modify.
True machine code is a stream of raw, usually binary, data. A programmer coding in "machine code"
normally codes instructions and data in a more readable form such as decimal, octal, or hexadecimal
which is translated to internal format by a program called a loader or toggled into the computer's memory
from a front panel.
A low-level programming language is a programming language that provides little or no abstraction from
a computer's instruction set architecture—commands or functions in the language map closely to
processor instructions. Generally this refers to either machine code or assembly language. The word "low"
refers to the small or nonexistent amount of abstraction between the language and machine language;
because of this, low-level languages are sometimes described as being "close to the hardware". Programs
written in low-level languages tend to be relatively non-portable, mainly because of the close relationship
between the language and the hardware architecture.
Low-level languages can convert to machine code without a compiler or interpreter— second-generation
programming languages use a simpler processor called an assembler— and the resulting code runs
directly on the processor. A program written in a low-level language can be made to run very quickly,
with a small memory footprint. An equivalent program in a high-level language can be less efficient and
use more memory. Low-level languages are simple, but considered difficult to use, due to numerous
technical details that the programmer must remember. By comparison, a high-level programming
language isolates execution semantics of a computer architecture from the specification of the program,
which simplifies development.
8
High Level Language
A high-level language is a programming language such as C, FORTRAN, Pascal, JAVA, Python… that
enables a programmer to write programs that are more or less independent of a particular type of
computer. Such languages are considered high-level because they are closer to human languages and
further from machine languages. In contrast, assembly languages are considered low-level because they
are very close to machine languages.
The main advantage of high-level languages over low-level languages is that they are easier to read, write,
and maintain. Ultimately, programs written in a high-level language must be translated into machine
language by a compiler or interpreter.
The first high-level programming languages were designed in the 1950s. Now there are dozens of
different languages, including Ada, Algol, BASIC, COBOL, C, C++, FORTRAN, LISP, Pascal, and
Prolog.
Many of the most widely used programming languages (such as C++, Delphi, Java, Python etc.) are multi-
paradigm programming languages that support object-oriented programming to a greater or lesser degree,
typically in combination with imperative, procedural programming. Significant object-oriented languages
include Java, C++, C#, Python, PHP, Ruby, Perl, Object Pascal, Objective-C, Dart, Swift, Scala, Common
Lisp, and Smalltalk.
Object-oriented Programming uses objects, but not all of the associated techniques and structures are
supported directly in languages that claim to support OOP. The features listed below are, however,
common among languages considered strongly class- and object-oriented (or multi-paradigm with OOP
support), with notable exceptions mentioned.
OOP TERMINOLOGIES
Languages that support object-oriented programming typically use inheritance for code reuse and
extensibility in the form of either classes or prototypes. Those that use classes support two main concepts:
9
Classes – the definitions for the data format and available procedures for a given type or class of object;
may also contain data and procedures (known as class methods) themselves, i.e. classes contains the data
members and member functions
Objects sometimes correspond to things found in the real world. For example, a graphics program may
have objects such as "circle", "square", "menu". An online shopping system might have objects such as
"shopping cart", "customer", and "product". Sometimes objects represent more abstract entities, like an
object that represents an open file, or an object that provides the service of translating measurements from
U.S. customary to metric.
Encapsulation
Encapsulation is an Object Oriented Programming concept that binds together the data and functions that
manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led
to the important OOP concept of data hiding.Data encapsulation is a mechanism of bundling the data, and
the functions that use them.
Data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details
from the user.
Languages that support classes almost always support inheritance. This allows classes to be arranged in a
hierarchy that represents "is-a-type-of" relationships. For example, class Employee might inherit from
class Person. All the data and methods available to the parent class also appear in the child class with the
same names. For example, class Person might define variables "first_name" and "last_name" with method
"make_full_name()". These will also be available in class Employee, which might add the variables
"position" and "salary". This technique allows easy re-use of the same procedures and data definitions, in
addition to potentially mirroring real-world relationships in an intuitive way. Rather than utilizing
database tables and programming subroutines, the developer utilizes objects the user may be more
familiar with: objects from their application domain.
Delegation is another language feature that can be used as an alternative to inheritance. It refers generally
to one entity passing something to another entity, and narrowly to various specific forms of relationships.
Polymorphism
The ability to appear in many forms. In object-oriented programming, polymorphism refers to a
programming language's ability to process objects differently depending on their data type or class. More
specifically, it is the ability to redefine methods for derived classes. For example, given a base class
shape, polymorphism enables the programmer to define different area methods for any number of derived
10
classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area
method to it will return the correct results.
Hierarchical
Fruit
References/Further Reading
https://classes.soe.ucsc.edu/cmps115/Spring05/supplements/DecisionTables.htm
https://en.wikipedia.org/wiki/Computer_program
https://www.lynda.com/Programming-Foundations...programming/.../90430-4.html
whatis.techtarget.com › Topics › AppDev › Programming
https://www.smartdraw.com/data-flow-diagram/
searchsoftwarequality.techtarget.com › Mobile Testing › Programming
11