Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Lesson 1 Programming Concepts

The document outlines fundamental programming concepts, including definitions of constants, literals, variables, comments, and programs. It discusses the characteristics and considerations for choosing programming languages, types of programming errors, and the differences between machine, assembly, and high-level languages. Additionally, it covers programming language translators, the program development life cycle, and various testing methods to ensure software quality.

Uploaded by

kneshibrian
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lesson 1 Programming Concepts

The document outlines fundamental programming concepts, including definitions of constants, literals, variables, comments, and programs. It discusses the characteristics and considerations for choosing programming languages, types of programming errors, and the differences between machine, assembly, and high-level languages. Additionally, it covers programming language translators, the program development life cycle, and various testing methods to ensure software quality.

Uploaded by

kneshibrian
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Programming concepts terms

i. Constant
it is a variable once declared cannot change
ii. Literal
it is a value that is written into the code of a program
iii. Variable
It is a named storage location in the computer’s memory
When naming a variable in programming, there are several important rules to follow to ensure
your code is clear and error-free:
1. Start with a Letter or Underscore: Variable names must begin with a letter (A-Z or a-z)
or an underscore (_). They cannot start with a digit.
2. Use Alphanumeric Characters and Underscores: After the first character, variable
names can include letters, digits (0-9), and underscores. Special characters like @, #, %,
etc., are not allowed.
3. Case Sensitivity: Variable names are case-sensitive. For example, myVariable and
myvariable would be considered different variables.
4. No Spaces or Special Characters: Spaces and special characters (except underscores)
are not permitted in variable names.
5. Avoid Reserved Keywords: Do not use reserved words or keywords of the programming
language (like int, class, if, etc.) as variable names.
6. Descriptive Names: Use meaningful names that describe the purpose of the variable,
such as totalAmount or userName, to make your code more readable. iv. comment

Are short non executable statements that are included in the source code of a
program to make it more readable or to explain the purpose of the program
There are two types of comment

1. Line comment //……….


2. Block comment /*______*/
v. Program
Are sets of instruction to guide computer to accomplish a certain task

LECTURER PAUL MAINA ALL THE BEST


vi. Programming
This is the process of creating computer program vii.
Programming language
Is language/s used by a programmer when writing computer instruction viii.
Source code
Computer instruction that are written in human readable format ix.
Object code
Computer instruction that are written in machine readable format
Factors to consider when choosing programming language

i. Execution time:- Applications that require quick response are best programmed in
machine code or assembly language. High-level languages are not suitable for such
application because, they take long to be translated & executed.
ii. Development time: - Development time is the time a programmer takes to write and run
a program. High-level languages are easy to read, understand and develop; hence, they
require less development time. Machine code & Assembly languages are relatively
difficult to read, understand and develop; hence, they are time-consuming.
iii. Popularity:- The language selected should be suitable and/or successful in the market
with respect to the problems to be solved.
iv. Documentation:- It should have accompanying documentation (descriptions) on how to
use the language or maintain the programs written in the language.
v. Maintenance:- Programs are developed to solve specific problems, and the problems
keep on changing; hence, the programs are also changed to perform the new functions.
vi. Program maintenance is the activity of incorporating more routines onto the
program, modifying the existing routines or removing the obsolete routines to make the
program adapt to functionally enhanced environment. The maintenance is made easier if
the language used is easy to read and understand.
vii. Availability of skilled programmers: - The language selected should have a pool of
readily available programmers to ease the programming activity, and reduce development
time.

LECTURER PAUL MAINA ALL THE BEST


Types of programming errors. Error in a program is called a bug and the process of
removing program error is called debugging
Syntax error : refers to the grammatical rules, which govern how words, symbols,
expressions and statements may be formed & combined.
Semantics error :These are rules, which govern the meaning of syntax. They dictate what
happens (takes place) when a program is run or executed.
Logical (arithmetic) errors. These are errors in the program logic.
Run-time (Execution) errors. These errors occur during program execution

Categories of programming language

1. Machine language
In machine language instruction are written in zeros and ones (0’s and 1’s) Machine
language has several notable disadvantages:

Complexity: Machine language is difficult to understand and memorize because it


consists of binary code (0s and 1s) which is not intuitive for humans1.
Time-Consuming: Writing programs in machine language is very time-consuming.
Each instruction must be written in binary, which is a slow and meticulous process1.
Error-Prone: Programs written in machine language are more prone to errors.
Debugging and resolving these errors can be extremely challenging1.
Lack of Portability: Machine language is platform-specific, meaning code written for
one type of machine may not work on another without significant modification2.
Maintenance Difficulty: Modifying and maintaining machine language code is difficult
due to its low-level nature and lack of abstraction1.
Limited Functionality: Machine language lacks the advanced features and
functionalities provided by higher-level programming languages2.
2. Assembly language
In assembly language instruction are written in symbolic formats (mnemonics) Example
MOV TOTAL, 48; Transfer the value 48 into the memory variable TOTAL

ADD AX, BX ; Add the values in AX and BX, result in AX


3. High level language
In high level language instruction are written in pure English statement

LECTURER PAUL MAINA ALL THE BEST


Advantages and disadvantages of high level programming language.

1. They are easily portable, i.e., they can be transferred between computers of different
families and run with little or no modification.
2. High-level language programs are short, and take shorter time to be translated.
3. They are easy to lean, understand and use.
4. They are easy to debug (correct/remove errors), & maintain.
5. High level language programs are easy to modify, and also to incorporate additional features
thus enhancing its functional capabilities.
6. They are ‘user-friendly’ & problem-oriented; hence, can be used to solve problems arising
from the real world.
7. They enable programmers to adapt easily to new hardware. This is because; they don’t have
to worry about the hardware design of the computer.
8. High-level language programs are self-documenting, i.e., the program statements displays the
transparency of purpose making the verification of the program easy.
9. High level languages are more flexible; hence, they enhance the creativity of the programmer
and increase his/her productivity in the workplace.

Disadvantages of using High-level languages

1. High-level languages are not machine-oriented; hence, they do not use of the CPU and
hardware facilities efficiently.
2. The languages are machine-independent, and cannot be used in programming the hardware
directly.
3. Each high-level language statement converts into several machine code instructions. This
means that, they use more storage space, and it also takes more time to run the program.
4. Their program statements are too general; hence, they execute slowly than their machine
code program equivalents.
5. They have to be interpreted or compiled to machine-readable form before the computer can
execute them.

LECTURER PAUL MAINA ALL THE BEST


6. The languages cannot be used on very small computers.
The source program written in a high-level language needs a Compiler, which is loaded into
the main memory of the computer, and thus occupies much of memory space.

PROGRAMMING LANGUAGE TRANSLATORS


Are tools/utilities that are used to translate programming language from one level to another
They are as follows
 Compiler
• Interpreter
• assembler
Compiler is a special program that processes statements written in a particular programming
language and turns them into machine language or "code" that a computer's processor uses.
Typically, a programmer writes language statements in a language such as Pascal or C one line
at a time using an editor. It is a program translator that translates the instruction of a higher level
language to machine language. It is called compiler because it compiles machine language
instructions for every program instructions of higher level language.

Interpreter, Computer language processor that translates a program line-by-line


(statementby-statement) and carries out the specified actions in sequence. In contrast, an
assembler or compiler completely translates a program written in a high-level language (the
source program) into a machine-language program (the object program) for later execution.
Whereas a compiled-program executes much faster than an interpreted-program, an
interpreter allows examination and modification of the program while it is running
(executing).

An Assembler is a program that takes basic computer instructions and converts them into a
pattern of bits that the computer's processor can use to perform its basic operations. Some
people call these instructions assembler language and others use the term assembly language.

A virtual machine (VM) is a software program or operating system that not only exhibits
the behavior of a separate computer, but is also capable of performing tasks such as running

LECTURER PAUL MAINA ALL THE BEST


applications and programs like a separate computer. A virtual machine, usually known as a
guest is created within another computing environment referred as a "host." Multiple virtual
machines can exist within a single host at one time

COMPILERS
Compiler is a special program that processes statements written in a particular programming
language and turns them into machine language or "code" that a computer's processor uses.
Typically, a programmer writes language statements in a language such as Pascal or C one line
at a time using an editor. It is a program translator that translates the instruction of a higher level
language to machine language. It is called compiler because it compiles machine language
instructions for every program instructions of higher level language.
The programs written by the programmer in higher level language is called source program.
After this program is converted to machine languages by the compiler it is called object
program.
Higher Level Language --> (Compile) ---> Program --> Machine Language Program A
compiler can translate only those source programs, which have been written, in that language
for which the compiler is meant for. For example FORTRAN compiler will not compile
source code written in COBOL language.
Object program generated by compiler is machine dependent. It means programs compiled
for one type of machine will not run in another type. Therefore every type of machine must
have its personal compiler for a particular language. Machine independence is achieved by
using one higher level language in different machines.
A compiler takes a program written in high-level language and converts it into an equivalent
program in machine language (translation).
Source program comp iler execution results of the programming

high-level lang. object code in machine lang.

Compilation of a source program.

LECTURER PAUL MAINA ALL THE BEST


Phases of the compiler:
Source analysis synthesis language
target language

Basic steps of compilation

Interpreters
Interpreter, Computer language processor that translates a program line-by-line
(statementby-statement) and carries out the specified actions in sequence. It directly executes
the statements of a high-level language, just as if those statements were part of the instruction
set of the machine.

interpreter
Program statements result of the statement

Input and output of an interpreter


It takes longer to run a program under an interpreter than to run the compiled code but it can take
less time to interpret it than the total required to compile and run it. This is especially important
when prototyping and testing code when an edit-interpret-debug cycle can often be much shorter
than an edit-compile-run-debug cycle.
Interpreting code is slower than running the compiled code because the interpreter must analyses
each statement in the program each time it is executed and then perform the desired action
whereas the compiled code just performs the action. This run-time analysis is known as
"interpretive overhead". Access to variables is also slower in an interpreter because the mapping
of identifiers to storage locations must be done repeatedly at run-time rather than at compile
time.

LECTURER PAUL MAINA ALL THE BEST


Assemblers
An Assembler is a program that takes basic computer instructions and converts them into a
pattern of bits that the computer's processor can use to perform its basic operations. Some people
call these instructions assembler language and others use the term assembly language.

DIFFERENCE BETWEEN COMPILERS AND INTERPRETERS

Interpreter Compiler

Translates program one statement at a Scans the entire program and translates it as
time. a whole into machine code.

It takes less amount of time to analyze the It takes large amount of time to analyze the
source code but the overall execution time source code but the overall execution time is
is slower. comparatively faster.

No intermediate object code is generated, Generates intermediate object code which


hence are memory efficient. further requires linking, hence requires more
memory.

Continues translating the program until the It generates the error message only after
first error is met, in which case it stops. scanning the whole program. Hence
debugging is comparatively hard.
Hence debugging is easy.

Programming language like Python, Ruby Programming language like C, C++ use
use interpreters. compilers.

LECTURER PAUL MAINA ALL THE BEST


Study questions
1. Why is it important to translate high-level languages into machine language?
2. Explain why it’s important to use programming tool like compilers.
3. Between a compiler and an interpreter which one do you think is faster and why

Program development life cycle (PDLC)


Are steps that program takes from problem statement to program maintenance and review,
the steps are:
1: Define the Program Objectives /define problem statement

Naturally enough, you should start with a clear idea of what you want the program to do.

Think in terms of the information your program needs, the feats of calculation and

manipulation the program needs to do, and the information the program should report back to

you. At this level of planning, you should be thinking in general terms, not in terms of some

specific computer language.

Step 2: problem analysis

In problem analysis the programmer identifies the input, process and program output

Step 3: Design the Program

After you have a conceptual picture of what your program ought to do, you should decide

how the program will go about it. What should the user interface be like? How should the

program be organized? Who will the target user be? How much time do you have to

complete the program?

You also need to decide how to represent the data in the program and, possibly, in auxiliary

files, as well as which methods to use to process the data.

LECTURER PAUL MAINA ALL THE BEST


After language design and implementation. They different times bindings that can take place

In a program

• Language design time — bind operator symbols to operations

• Language implementation time– bind floating point type to a representation

• Compile time — bind a variable to a type in C or Java

• Load time — bind a C or C++ static variable to a memory cell)

• Runtime — bind a non-static local variable to a memory cell

Design methodology

Flowchart: explain how to solve a problem using short statement and special symbols

Pseudocode: explain how to solve a problem using English like statement

Step 3: Write the program Code

Now that you have a clear design for your program, you can begin to implement it by writing

the code. That is, you translate your program design into the C language. Here is where you

really have to put your knowledge of C to work. You can sketch your ideas on paper, but

eventually you have to get your code into the computer. The mechanics of this process

depend on your programming environment. We'll present the details for some common

environments soon. In general, you use a text editor to create what is called a source code

file. This file contains the C rendition of your program

LECTURER PAUL MAINA ALL THE BEST


Step 4: Test and Debug the Program

The fact that your program runs is a good sign, but it's possible that it could run incorrectly.

Consequently, you should check to see that your program does what it is supposed to do.

There are several types of program testing, each serving a specific purpose to ensure the
quality and functionality of software. Here are some of the main types:

Unit Testing: Tests individual components or functions of a program to ensure they work
correctly in isolation1.

Integration Testing: Verifies that different modules or services within an application work
together as expected1.

Functional Testing: Focuses on testing the business requirements of an application, ensuring


that each function performs as specified1.

System Testing: Tests the complete and integrated software to evaluate the system’s
compliance with its specified requirements2.

Acceptance Testing: Determines whether the overall system meets the business
requirements and is ready for deployment3.

Performance Testing: Assesses the speed, responsiveness, and stability of a system under a
particular workload.

Security Testing: Identifies vulnerabilities and ensures that the system protects data and
maintains functionality as intended4.

Usability Testing: Evaluates how user-friendly and intuitive the software is for end-users4.

Regression Testing: Ensures that new code changes do not adversely affect the existing
functionality of the software1.

Smoke Testing: A preliminary test to check the basic functionality of the application before
proceeding to more detailed testing2.

Step 5: program implementation

LECTURER PAUL MAINA ALL THE BEST


The process of putting the program into use: using either of the following implementation

method

1. Direct implementation
2. Parallel implementation
3. Pilot implementation
4. Phased implementation

Step 6: Maintenance and review

When you create a program for yourself or for someone else, that program could see

extensive use. If it does, you'll probably find reasons to make changes in it. Perhaps there is a

minor bug that shows up only when someone enters a name beginning with Zz, or you might

think of a better way to do something in the program. You could add a clever new feature.

You might adapt the program so that it runs on a different computer system. All these tasks

are greatly simplified if you document the program clearly and if you follow sound design

practices.

N/b documentation should be done at each and every step

LECTURER PAUL MAINA ALL THE BEST

You might also like