You are on page 1of 23

UNIT X

Programming concepts
Programming concepts

 Computer programs :collections of instructions that tell a computer how to


interact with the user

 The first programmable computers required the programmers to write explicit


instructions to directly manipulate the hardware of the computer.

 This “machine language” was very tedious to write by hand since even simple
tasks such as printing some output on the screen require 10 or 20 machine
language commands.
There are two different models of programming-

 Structured programming–
• code is executed one after another.
• Control statements change which blocks of code are executed next.
• It is aimed at improving the clarity, quality, and development time of a computer program by making
extensive use of subroutines, block structures, for and while loops
 Object oriented programming-
• It is based on the concept of “objects”, which may contain data, in the form of fields, often known as
attributes; and code, in the form of procedures, often known as methods.
• A feature of objects is that an object’s procedures can access and often modify the data fields of the object
with which they are associated.
• There is no single “flow” of the program as objects can freely interact with one another by passing
messages.
1. Program Structure

 a well-structured program the division into components follows some recognized principle such as
information hiding, and the interfaces between components are explicit and simple.
 By contrast, with a poorly structured program the division into components is largely arbitrary (or even
non-existent), and interfaces are implicit and complex.
 Virtually all structured programs share a similar overall pattern:
 Statements to establish the start of the program
 Variable declaration
 Program statements (blocks of code)
2. Variable Declaration

 The variable name is the usual way to reference the stored value.
 Variables are the backbone of any program, and thus the backbone of any programming language.
 in simple terms, a variable is simply a way to store some sort of information for later use, and we can retrieve this
information by referring to a “word” that will describe this information.
 Different types of variables include:
 Integer – to store integer or “whole” numbers
 Real – to store real or fractional numbers (also called float to indicate a floating point number)
 Character – A single character such as a letter of the alphabet or punctuation.
 String – A collection of characters
3. Looping structures

 Loop structures allow you to run one or more lines of code repetitively.
 repeat the statements in a loop structure until a condition is True, until a condition is False, a specified
number of times, or once for each element in a collection.
4. Control structures

 A control structure is a block of programming that analyses variables and chooses a


direction in which to go based on given parameters.
 The term flow control details the direction the program takes (which way program
control “flows”).
 Hence it is the basic decision-making process in computing; flow control determines
how a computer will respond when given certain conditions and parameters.
5. Syntax

 the syntax of a programming language is the set of rules that define the combinations of
symbols that are considered to be correctly structured programs in that language.
 Documents that are syntactically invalid are said to have a syntax error.
 The concept of syntax in programming language is similar to the concepts of grammar
and spelling in spoken language.
 When a sentence in English has very poor grammar and spelling, it becomes difficult or
even impossible to understand.
 Similarly, when code has syntax errors, the program will not execute.
HIGH-LEVEL LANGUAGE CHARACTERISTICS

Easy to learn
 The high Level Languages are close to human languages.
 The instructions written in high level languages are similar to English like words and
Statements. This makes the high level languages easy to learn and use.

Easy to detect errors


 The logic of the program written in high level languages is very simple and easy.
 The instructions of program are like English language statements. In case of errors, it is
very easy to detect (or find) and remove errors in the Program
 . It is also easy to modify the Program.
 Machine Independent
• The program written in High Level Language is machine independent.
• It means that a program written or compiled on one type of Computer can be executed (run) on another different
type of Computer that has different architecture.

 Availability of Liberty Functions


• Every High Level Language provides a large number of Built in functions (or library functions) that can be used to
perform specific tasks during designing of new Programs.
• For Example: To computer the square root of a number
 Shorter Program
 The Program written in high level language is shorter than the program written in low level language.
 A single instruction of the program written in High Level Language may be equivalent to many instructions of low level
programming language.

 Well defined Syntax and standard


• Every high level language has a standard syntax.
• The standard is approved (or established) by international organization. The most popular organization is ANSI
(American National Standard Institute).
• The translator programs are written according to the standard syntax of the language.
• Therefore, high level languages describe a well defined way of writing programs.
HIGH-LEVEL LANGUAGE PROGRAMMING

 A high-level language is any programming language that enables development of a program in a much
more user-friendly programming context a
 generally independent of the computer's hardware architecture.
 A high-level language has a higher level of abstraction from the computer, and focuses more on the
programming logic rather than the underlying hardware

1. C++ 7. Objective C

2. C# 8. Pascal

3. Cobol 9. Perl

4. Fortran 10. PHP

5. Java 11. Python

6. JavaScript 12. Swift


PROGRAMMING FEATURES
1. C programming

 Undefined behavior
The idea that a language specification would explicitly specify certain constructs as having undefined
behavior is interesting.

 Objects are the primary unit of composition


• There are no standalone functions.
• Design Patterns can be used to describe high level object coordination patterns.
• However sometimes the community’s focus on objects can be a bit extreme.
 Checked exceptions
• Great when used sparingly, as it forces the caller to handle expected error conditions.
 Unicode strings
 Tons of other languages use “bytestrings” as the main string type which causes all kinds of problems
when working with international characters.
 Documentation focus
 Every library is expected to have JavaDoc documentation, which is generated from documentation comments in
the source
 Compatibility focus
 I have never seen a community so focused on maintaining backward
 Garbage Collection
 Being freed from the confines of manual memory management makes it a ton easier to focus on more important
things.
2. C#

Very similar to Java.

 Assemblies
 This is a level of encapsulation above the typical namespaces or modules in most languages. Assemblies
are similar to the idea of static/dynamic libraries in C or JAR files in Java.
 Cross-language compatibility is first-class (not just for C)
 C# runs in the Common Language Runtime, which was designed from the beginning to support
interoperability between languages.
 Properties are first-class No longer need to write explicit getter and (optional) setter methods.
 Listeners are first-class Classes can declare an event Foo with addFooListener and removeFooListener
functionality built in. o Unfortunately the implementation has some annoyances.
 Foreign Methods5 are first-class C# calls these extension methods.
 Partial Classes Allows a class’s members to be defined in multiple files.
 Useful to add functionality to a generated class
3.Python

 Indentation is significant o Everyone notices this pretty fast


 Interactive interpreter (REPL) o Amazingly useful for prototyping quickly,
running experiments, and learning the language.
 HashMap<Integer>(...), or new HashSet<Integer>(...).
 Generators and Coroutines o Generators enable straightforward pulling of
values from a complex data source (like a parsed data structure).
4.JavaScript

 No blocking I/O o All I/O is non-blocking and asynchronous. This results in


heavy use of continuation passing style.
 Successful despite huge flaws o Ease of deployment and ubiquity (i.e. business
considerations) trump ease of use. (PHP also wins for the same reason.)
 JSON (JavaScript Object Notation) o A fantastically compact, readable, and
portable notation for representing all kinds of data structures. Great for data
interchange.
5.Haskell

 Lazy evaluation
 o Expressions are only evaluated when some primitive operation (like print or add) requires
the value of the expression.
 o Allows you to glue programs together in new ways.
 In particular, execution of multiple functions can be interleaved trivially and termination
conditions can be separated from looped computation.
 Side effects banned by default o Mutation of data structures and I/O, both of which have
order-sensitive side effects, are not allowed except within the confines of monad.
 null banned by default.
 Unlike many languages, there is no special null value in Haskell that can be substituted anywhere.
6.Lisp (Common Lisp, Scheme, Clojure)

 Homoiconic o When you write a Lisp program, the notation you use (the
grammar) is equivalent to what a compiler would see (an abstract syntax tree or
AST).
 o Furthermore this Lisp code is represented as a nested structure of lists,
symbols, and literals, all of which can be directly generated and manipulated in
Lisp itself!
 Macros o A function that transforms the AST of its operands at compile
time to new code.
Macros can be used to generate arbitrary new statements and
control structures.
 Lisp Conditions and Restarts o Allows bidirectional communication between different parts of the
call stack.
 More powerful than exceptions, since conditions can not only unwind the stack but also wind it back
again via a restart.
 Call-with-current-continuation o Allows you to save the current execution state of the program in
a variable and jump back to it later. Multiple times, even. It’s like a friggin' time machine.
TRANSLATION SOFTWARE

 It is the process by which computer software is used to translate a text from one natural language (such as English) to
another (such as Spanish).
 To process any translation, human or automated, the meaning of a text in the original (source) language must be fully
restored in the target language, i.e. the translation.
I. No Compiler Interpreter

1 Performs the translation of a program as a whole. Performs statement by statement translation.

2 Execution is faster. Execution is slower.

3 Requires more memory as linking is needed for the Memory usage is efficient as no intermediate object
generated intermediate object code. code is generated.

4 Debugging is hard as the error messages are generated It stops translation when the first error is met.
after scanning the entire program only. Hence, debugging is easy.

5 Programming languages like C, C++ uses compilers. Programming languages like Python, BASIC, and Ruby
uses interpreters.

You might also like