0% found this document useful (0 votes)
5 views25 pages

2ndWeekMondayLectureNotes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views25 pages

2ndWeekMondayLectureNotes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

2nd Week Lecture

Notes

MIS 131
by
Ziya N. Perdahçı
Programming Paradigms

• A programming paradigm is a set of programming concepts.


• The style and capability of any programming language is defined
by its paradigm.
• Some programming languages, for example JavaScript, only follow
one paradigm; others, for example
• Python, support multiple paradigms. Most programming
languages are multi-paradigm.
• Will consider four programming paradigms: low-level, imperative,
object-oriented and declarative.
Low-level programming

• Low-level programming uses instructions from the computer’s


basic instruction set.
• Assembly language and machine code both use low-level
instructions.
• This type of programming is used when the program needs to
make use of specific addresses and registers in a computer,
➢E.g., when writing a printer driver.
Imperative programming

• In imperative programming, the steps required to execute a


program are set out in the order they need to be carried out.
• This programming paradigm is often used in the early stages of
teaching programming.
• Imperative programming is often developed into structured
programming, which has a more logical structure and makes use
of procedures and functions, together with local and global
variables.
• Imperative programming is also known as procedural
programming.
Object-oriented programming (OOP)

• Object-oriented programming (OOP) is a programming


methodology that uses self-contained objects, which contain
programming statements (methods) and data, and which
communicate with each other.
• This programming paradigm is often used to solve more complex
problems as it enables programmers to work with real life things.
• Many procedural programming languages have been developed to
support OOP. For example, Java, Python and Visual Basic all allow
programmers to use either procedural programming or OOP.
OOP Terminology: Class
• A class is a template defining the methods and data of a certain
type of object.
• The attributes are the data items in a class.
• A method is a programmed procedure that is defined as part of a
class.
• Putting the data and methods together as a single unit, a class, is
called encapsulation. To ensure that only the methods declared
can be used to access the data within a class, attributes need to
be declared as private, and the methods need to be declared as
public.
OOP Terminology: Class Example
OOP Terminology: Object
• When writing a program, an object needs to be declared using a
class type that has already been defined.
• An object is an instance of a class that is self-contained and
includes data and methods.
• Properties of an object are the data and methods within an object
that perform named actions.
• An occurrence of an object during the execution of a program is
called an instance.
OOP Terminology: Object Example
OOP Terminology: Data hiding
• Data hiding protects the integrity of an object by restricting
access to the data and methods within that object.
• One way of achieving data hiding in OOP is to use encapsulation.
• Data hiding reduces the complexity of programming and increases
data protection and the security of data.
OOP Terminology: Data hiding example
OOP Terminology: Inheritance
• Inheritance is the process by which the methods and data from
one class, a superclass or base class, are copied to another
class, a derived class
• A new class of objects can be created conveniently
by inheritance
• The new class (called the subclass) starts with the characteristics
of an existing class (called the superclass), possibly customizing
them and adding unique characteristics of its own
Inheritance diagram – single inheritance
Inheritance diagram – multiple inheritance
OOP Terminology:
Inheritance
example:

➢ A base class employee and


the derived classes
partTime and fullTime are
defined.
➢ The objects
permanentStaff and
temporaryStaff are
instanced in these
examples and use the
method showDetails.
Compilers convert high-level-language
source code into machine language

High-Level
High-level languages look almost like
Languages everyday English and contain commonly
used mathematical notations
and
Compilers Python is among the world’s most widely
used high-level programming languages
Interpreters
• Interpreter programs execute high-level language programs directly
and avoid the delay of compilation
• Interpreted programs run slower than compiled programs
• The complete script of Python is written in the C Programming
Language. When we write a Python program, the program is executed
by the Python interpreter.
• Most widely used Python implementation—CPython—uses a clever
mixture of compilation and interpretation to run programs
Python
• Python is an object-oriented scripting language
• Released publicly in 1991
• Developed by Guido van Rossum of the National Research Institute
for Mathematics and Computer Science in Amsterdam.
• Has rapidly become one of the world’s most popular programming
languages
• Particularly popular for educational and scientific computing
• Recently surpassed the programming language R as the most popular
data-science programming language
• Source: Most used
languages among software
developers globally 2024 |
Statista
Some reasons why Python is popular:
• Open source, free and widely available with a massive open-source
community
• Easier to learn than many other languages, enabling novices and
professional developers to get up to speed quickly
• Easier to read than many other popular programming languages
• Widely used in education.
• Enhances developer productivity with extensive standard libraries and
third-party open-source libraries
• Programmers can write code faster and perform complex tasks
with minimal code
Some reasons why Python is popular:
• Massive numbers of free open-source Python applications
• Popular in web development (e.g., Django, Flask)
• Supports popular procedural, functional-style and object-oriented
programming
• Build anything from simple scripts to complex apps with massive
numbers of users, such as Dropbox, YouTube, Reddit, Instagram and
Quora
• Popular in artificial intelligence, which is enjoying explosive growth, in
part because of its special relationship with data science
Some reasons why Python is popular:
• Widely used in the financial community
• Extensive job market for Python programmers across many
disciplines, especially in data-science-oriented positions, and Python
jobs are among the highest paid of all programming jobs
CPython
• CPython is the reference implementation of the Python
programming language.
• Written in C and Python, CPython is the default and most widely
used implementation of the Python language.
• CPython can be defined as both an interpreter and a compiler as
it compiles Python code into bytecode before interpreting it.
• Anaconda is a Python distribution. It bundles CPython with
several packages, especially ones that are useful for scientific
computing, and some additional tools like Conda to manage
packages and environments.
•Python source code: We create in human-readable form to represent the logic and
functionality of our program
•Compilation: Our Python source code goes through a compilation process when we
run or execute it. The Python compiler, which is a component of the CPython
interpreter, converts our source code into CPython bytecode at this stage. This
bytecode is a set of lower-level, cross-platform instructions. It is a translator that
translates your source code into bytecode.
•CPython bytecode: After the compilation stage, the resultant Python bytecode is
produced. It is made up of a series of commands that the CPython interpreter can
comprehend and carry out. Each bytecode instruction represents a specific action or
operation that the interpreter needs to perform.
•Execution of the interpreter: The CPython interpreter now reads and runs the CPython
bytecode line by line. It executes the desired operations and produces the output or
behavior described by the source code by following the instructions given in the
bytecode.

You might also like