COS 102
Introduction to Programming
DEPARTMENT OF COMPUTER SCIENCE
UNIVERSITY OF IBADAN
What is Programming?
vA program is a sequence of instructions that can be executed by a computer to
solve a problem or perform a specified task.
vProgramming is the process of writing, testing, debugging/ troubleshooting and
maintaining the instructions for solving a problem with the computer.
vThe purpose of programming is to create a program that exhibits a certain
described behavior (Solve a Problem).
vThe process of writing source code requires expertise in many different subjects,
including knowledge of the application domain.
vProgramming is the craft of transforming problem requirements into something
that a computer can execute.
2
Features of a Good Computer Program
vRobustness: How well a program anticipates situations of data type conflict and other
incompatibilities that result in run time errors and program halts. The focus is mainly on
user interaction and handling of
vUsability: The textual and graphical elements that makes a program should be easy and
comfortable to use.
vReliability: A developed program for a particular application should be depended upon
to do what it is supposed to accomplish. The results of a program should be correct at all
times.
vMaintainability: A good program design will always be easy to change or modify when
the need arises. The structure, coding and documentation of the program should allow
another programmer to understand the logic of the program and to make a changes.
3
Features of a Good Computer Program
vPortable: A good program design will be transferable to a different computer having a
language translator for that language without substantial changes or modification
vReadability: The program codes will be easy for a programmer to read and understand
the logic involved in the programming.
vStorage Saving: A good program design is not to be verbous, that is, it will not be allowed
to be unnecessary long, thereby consuming much storage that will be required for
processing data and storage of information produced from processing.
vEfficiency: The amount of system resources a program consumes (processor time,
memory space, slow devices, network bandwidth and to some extent even user
interaction), the less the better.
4
What is a Programming Language?
vA programming language is an artificial language designed to
automate the task of organizing and manipulating information to
express problem solutions precisely.
vA programming language is concern with the set of words, rules
and tools that are used to explain (or define) what you are trying to
accomplish.
vThere are many different programming languages just as there are
many different "spoken" languages.
vExamples include - Java, C, C++, PHP, Python, C#, VisualBasic,
Objective-C, Perl, Ruby
5
Categories of Programming Language
vHigh Level Languages (HLL)- are programming languages
that are designed to make it easier for humans to
understand and write.
vIt is closer to natural language and uses commands and
instructions that are more abstract from the underlying
computer hardware.
vHLL uses natural language elements and requires compiler
or interpreter.
vExamples: Python, Java, C#
6
Categories of Programming Language …cont.
vLow Level Languages (LLL)- are programming languages that are close to machine
hardware instruction set architecture.
vBecause they are written with minimal abstraction, they provides direct control
over hardware.
vThey are efficient but complex to read and write.
vExample: Assembly language
vMachine Languages - The lowest-level language, consisting of binary code directly
executed by a computer.
vNot human-readable but is directly understood by computers
vExample: 01101000 01100101 (binary representation)
7
Interpreted vs Compiled Languages
vInterpreted Languages are programming languages whose source
code is executed line-by-line by an interpreter program without prior
compilation.
vThe interpreter translates source code directly to machine code
during execution
vThey are easy to debug but slower execution than compiled
languages
vExample: Python, Ruby, JavaScript
8
Interpreted vs Compiled Languages
vCompiled Languages are programming languages whose source
code is translated into Object code before execution.
vThe Compiler converts source code to an intermediate, machine-
readable form(object code) before it is converted to machine code.
vExample: C, C++, Java
vPrograms written in an interpreted language can be run
immediately but those written in compiled languages must first be
compiled before they can be run.
9
Programming Language Paradigm
vProcedural Programming Languages: are programming
paradigm that organizes code as procedures (functions/
subroutines) that must be executed sequentially to perform
tasks.
üE.g C, Pascal, BASIC
vO b j e c t O r i e n t e d P r o g r a m m i n g L a n g u a g e s : a r e
programming paradigm that organizes code into classes and
objects and is focused on real-world modeling.
üExamples: Java, C++, Python
10
Programming Language Paradigm
vFunctional Programming Languages: Languages that
treats computation as evaluation of mathematical functions
with immutable data and no side effects.
üExamples: Haskell, Lisp, Erlang, Scala
vLogical Programming Language: Languages are based on
formal logic, programs are sets of facts and rules;
computation is done via logical inference.
üExamples: Prolog
11
Programming Concepts
vSyntax: Syntax refers to the structure of a program and the
rules about that structure.
vSemantics: The meaning or behavior of code that is
syntactically correct.
vAbstraction: Hiding complex details to simplify interaction
with a system.
vBugs: An error in a program.
vDebugging: The process of finding and removing any kind of
programming errors
12
Programming Errors
vSyntax Errors: Errors caused by breaking structural rules of a language. They
are detected during compilation or interpretation and can keep your program
from executing. E.g Typo in keywords, missing brackets,
vSemantic Errors: Code executes but produces incorrect or unintended
results. They are tricky and hard to detect automatically. E.g Incorrect
formula or wrong calculation
vLogical Errors: Flaw in program logic causing wrong output. Program runs
without crashing but results are incorrect.
vRuntime Errors: Errors that occurs during program execution that causes it
to crash or stop. E.g division by zero, file not found, stack overflow
13
The Ten Commandments of Computer
Ethics
The ten commandments of computer ethics are a code of conduct for responsible computer use, created by the Computer Ethics Institute:
1. Thou shalt not use a computer to harm other people.
2. Thou shalt not interfere with other people's computer work.
3. Thou shalt not snoop around in other people's computer files.
4. Thou shalt not use a computer to steal.
5. Thou shalt not use a computer to bear false witness.
6. Thou shalt not copy or use proprietary software for which you have not paid.
7. Thou shalt not use other people's computer resources without authorization or proper compensation.
8. Thou shalt not appropriate other people's intellectual output.
9. Thou shalt think about the social consequences of the program you are writing or the system you are designing.
10. Thou shalt always use a computer in ways that ensure consideration and respect for your fellow humans
14
Thank You
15