Unit 1
Unit 1
Unit 1
Unit-I
By:
Mani Butwall,
Asst. Prof. (CSE)
Contents
• Introduction to Programming Fundamentals
• Programming Environment
• Principles of Programming
• What is Debugging ?
• Text editors and Debuggers
• Introduction to Flow-Chart
• Algorithm
What is Computer Programming?
• Program is a collection of instructions that can be executed by
a computer to perform a specific task.
• COMPUTER PROGRAMMING is a step by step process of
designing and developing various sets of computer programs
to accomplish a specific computing outcome.
• The process comprises several tasks like analysis, coding,
algorithm generation, checking accuracy and resource
consumption of algorithms, etc.
• The purpose of computer programming is to find a sequence
of instructions that solve a specific problem on a computer.
• Computer Programming is very easy if it is appropriately
managed. There are many computer programming languages
available so finalizing the right programming language is not
an easy task.
Basic of programming
• English is the most popular and well-known Human Language.
The English language has its own set of grammar rules, which
has to be followed to write in the English language correctly.
• Likewise, any other Human Languages (German, Spanish,
Russian, etc.) are made of several elements like nouns,
adjective, adverbs, propositions, and conjunctions, etc. So,
just like English, Spanish or other human languages,
programming languages are also made of different elements.
• Just like human languages, programming languages also follow
grammar called syntax. There are certain basic program code
elements which are common for all the programming
languages.
• Most important basic elements for programming languages
are:
1. Programming Environment
2. Data Types
3. Variables
4. Keywords
5. Logical and Arithmetical Operators
6. If else conditions
7. Loops
8. Numbers, Characters and Arrays
9. Functions
10. Input and Output Operations
Applications of computer programming languages
Java Mostly used for developing Android apps, web apps, and Big data.
R Data Science projects, Statistical computing, Machine learning
Javascript JavaScript usage include web/mobile app development, game
development, and desktop app development.
• def evenOrOdd(number)
• {
//Determine if the number is even
if(number % 2 == 0):
• {
return number
}
//If the number is odd, this will add 5 and return
else:
• {
return number + 5
}
• }
• leaving comments is a little more work while you're coding,
and you understand your code pretty well right?
• Leave comments anyway!
• Try writing a program, leaving it alone for six months, and
come back to modify it. You'll be glad you documented your
program instead of having to pour over every function to
remember how it works. Work on a coding team? Don't
frustrate your fellow developers by forcing them to decipher
your syntax.
8. Refactor
• It's hard to accept, but your code isn't going to be perfect the
first time. Refactoring code means reviewing your code and
looking for ways to optimize it. Make it more efficient while
keeping the results exactly the same.
• Codebases are constantly evolving. It's completely normal to
revisit, rewrite, or even redesign entire chunks of code. It
doesn't mean you didn't succeed the first time you wrote your
program.
• You're going to get more familiar with a project over time. Use
that knowledge to adjust your existing code to be DRY, or
following the KIS principle.
9. Clean Code At All Costs
• Don't try to pack a ton of logic into one line. Leave clear
instructions in comments and documentation. If your code is
easy to read it will be easy to maintain.
• Good programmers and readable code go hand-in-hand. Leave
comments when necessary. Adhere to style guides, whether
dictated by a language or your company.
What is Debugging?
• Software programs undergo heavy testing, updating,
troubleshooting, and maintenance during the development
process. Usually, the software contains errors and bugs, which
are routinely removed. Debugging is the process of fixing a
bug in the software.
• It refers to identifying, analyzing and removing errors. This
process begins after the software fails to execute properly and
concludes by solving the problem and successfully testing the
software. But, it is considered to be an
extremely complex and tedious task because errors need to
be resolved at all stages of debugging.
Why do we need Debugging?
• The process of debugging begins as soon as the code of
the software is written. Then, it continues in successive stages
as code is combined with other units of programming to form
a software product. Debugging has many benefits such as:
• It reports an error condition immediately. This allows earlier
detection of an error and makes the process of software
development stress-free and unproblematic.
• It also provides maximum useful information of data
structures and allows easy interpretation.
• Debugging assists the developer in reducing
useless and distracting information.
• Through debugging the developer can avoid complex one-use
testing code to save time and energy in software
development.
Steps involved in Debugging
• The different steps involved in the process of debugging are:
•
• 1. Identify the Error: A bad identification of an error can lead
to wasted developing time. It is usual that production errors
reported by users are hard to interpret and sometimes the
information we receive is misleading. It is import to identify
the actual error.
• 2. Find the Error Location: After identifying the error
correctly, you need to go through the code to find the exact
spot where the error is located. In this stage, you need to
focus on finding the error instead of understanding it.
• 3. Analyze the Error: In the third step, you need to use a
bottom-up approach from the error location and analyze the
code. This helps you in understanding the error. Analyzing a
bug has two main goals, such as checking around the error for
other errors to be found, and to make sure about the risks of
entering any collateral damage in the fix.
• 4. Prove the Analysis: Once you are done analyzing the
original bug, you need to find a few more errors that may
appear on the application. This step is about writing
automated tests for these areas with the help of a test
framework.
• 5. Cover Lateral Damage: In this stage, you need to create or
gather all the unit tests for the code where you are going to
make changes. Now, if you run these unit tests, they all should
pass.
• 6. Fix & Validate: The final stage is the fix all the errors and
run all the test scripts to check if they all pass.
Debugging Tools
• Debugging tool is a computer program that is used to test and
debug other programs. A lot of public domain software like
gdb and dbx are available for debugging. They offer console-
based command line interfaces. Examples of automated
debugging tools include code based tracers, profilers,
interpreters, etc.
Some of the widely used debuggers are:
1. Radare2
2. WinDbg
3. Valgrind
Language Processors
• Assembly language is machine dependent yet mnemonics that are
being used to represent instructions in it are not directly
understandable by machine and high Level language is machine
independent.
• A computer understands instructions in machine code, i.e. in the
form of 0s and 1s. It is a tedious task to write a computer program
directly in machine code.
• The programs are written mostly in high level languages like Java,
C++, Python etc. and are called source code. These source code
cannot be executed directly by the computer and must be converted
into machine language to be executed.
• Hence, a special translator system software is used to translate the
program written in high-level language into machine code is
called Language Processor and the program after translated into
machine code (object program / object code).
• The language processors can be any of the following three
types:
• 1. Compiler
• The language processor that reads the complete source
program written in high level language as a whole in one go
and translates it into an equivalent program in machine
language is called as a Compiler.
Example: C, C++, C#, Java In a compiler, the source code is
translated to object code successfully if it is free of errors. The
compiler specifies the errors at the end of compilation with
line numbers when there are any errors in the source code.
The errors must be removed before the compiler can
successfully recompile the source code again.>
• Assembler
The Assembler is used to translate the program written in
Assembly language into machine code. The source program is
a input of assembler that contains assembly language
instructions. The output generated by assembler is the object
code or machine code understandable by the computer.
Interpreter
The translation of single statement of source program into
machine code is done by language processor and executes it
immediately before moving on to the next line is called an
interpreter.
• If there is an error in the statement, the interpreter
terminates its translating process at that statement and
displays an error message.
• The interpreter moves on to the next line for execution only
after removal of the error. An Interpreter directly executes
instructions written in a programming or scripting language
without previously converting them to an object code or
machine code.
Example: Perl, Python and Matlab.
Difference between Compiler and Interpreter
COMPILER INTERPRETER
1. START
2. Declare 3 integer variables num1, num2 and num3.
3. Take the three numbers, to be added, as inputs in variables
num1, num2, and num3 respectively.
4. Declare an integer variable sum to store the resultant sum
of the 3 numbers.
5. Add the 3 numbers and store the result in the variable sum.
6. Print the value of variable sum
7. END
Algorithm for Simple Interest
• 1. Start
• 2. Declare 3 floating point variables p,r,t
• 3. Declare SI as floating point variable
• 4. SI=(p*r*t)/100
• 5. Print and store the result in SI
• 6.Stop
Algorithm Complexity
What is Algorithm Complexity and How to find it?
• An algorithm is defined as complex based on the amount of
Space and Time it consumes. Hence the Complexity of an
algorithm refers to the measure of the Time that it will need
to execute and get the expected output, and the Space it will
need to store all the data (input, temporary data and output).
Hence these two factors define the efficiency of an
algorithm.
The two factors of Algorithm Complexity are:
1. Time Factor: Time is measured by counting the number of
key operations such as comparisons in the sorting algorithm.
2. Space Factor: Space is measured by counting the maximum
memory space required by the algorithm.
• Therefore the complexity of an algorithm can be divided into
two types:
1. Space Complexity: Space complexity of an algorithm refers to
the amount of memory that this algorithm requires to