0% found this document useful (0 votes)
40 views

COMPUTATIONAL PHYSICS PROGRAMMING SHAHBAZ BHATTI Lecture 01

The document discusses an introductory programming course for physicists. It covers what programming is, why it is important, and the skills needed. It also outlines the basic recipe for writing programs and key points to remember. The document then discusses software categories, system software, application software, and the history and development of the C/C++ language.

Uploaded by

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

COMPUTATIONAL PHYSICS PROGRAMMING SHAHBAZ BHATTI Lecture 01

The document discusses an introductory programming course for physicists. It covers what programming is, why it is important, and the skills needed. It also outlines the basic recipe for writing programs and key points to remember. The document then discusses software categories, system software, application software, and the history and development of the C/C++ language.

Uploaded by

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

Course Title: Introduction to Programming for

Physicists Course
Code: PHY-306
Lecture 01

We’ll discuss today


What is programming?
Why programming is important?
What skills are needed?
Develop a basic recipe for writing programs
Points to remember.
What is programming?
Let us first see a widely known definition of programming.
Definition: "A program is a precise sequence of steps to solve a particular problem.”
It means that when we say that we have a program,
it actually means that we know about a complete set activities to be performed in a particular
order.
The purpose of these activities is to solve a given problem.
Alan Perlis, a professor at Yale University, says:
"It goes against the grain of modern education to teach children to program. What fun is there
in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and
learning to be self-critical? "
When we talk about computer programming then as Mr. Steve Summit puts it:
“At its most basic level, programming a computer simply means telling it what to do, and this
vapid-sounding definition is not even a joke.
The first hard thing about programming is to learn, become comfortable with, and accept these
artificial mechanisms, whether they make ``sense'' to you or not. “
Why Programming is important?
Why should we learn to program when
there are so many application software and code generators available to do the task for us.
Well the answer is as give by the Matthias Felleisen in the book ‘How to design programs’:
The answer consists of two parts.

First, it is indeed true that traditional forms of programming are useful for just a few people. But,
programming as we the authors understand it is useful for everyone: the administrative secretary
who uses spreadsheets as well as the high-tech programmer. In other words, we have a broader
concept of programming in mind than the traditional one. We explain our idea in a moment.
Second, we teach our idea of programming with a technology that is based on the principle of
minimal intrusion (burden). Hence, our concept of programming teaches problem-analysis and
problem-solving skills without imposing the overhead of traditional programming notations and
tools.”
By designing programs, we learn many skills that are important for all professions. These skills
can be summarized as:
Critical reading
Analytical thinking
Creative synthesis
What skills are needed?
Programming is an important activity as people life and living depends on the programs one
make. Hence while programming one should
Paying attention to detail.
Think about the reusability.
Think about user interface.
Understand the fact the computers are stupid.
Comment the code liberally (freely).
Program design recipe
‘How to design programs’ by Matthias Felleisen and the co-worker, the idea of design recipe
has been stated very smartly as

“Learning to design programs is like learning to play soccer. A player must learn to trap a ball, to
dribble with a ball, to pass, and to shoot a ball. Once the player knows those basic skills, the
next goals are to learn to play a position, to play certain strategies, to choose among feasible
strategies, and, on occasion, to create variations of a strategy because none fits. “
The author then continue to say that:

“A programmer is also very much like an architect, a composers, or a writer. They are creative
people who start with ideas in their heads and blank pieces of paper. They conceive of an idea,
form a mental outline, and refine it on paper until their writings reflect their mental image as
much as possible. As they bring their ideas to paper, they employ basic drawing, writing, and
playing music to express certain style elements of a building, to describe a person's character, or
to formulate portions of a melody. They can practice their trade because they have honed their
basic skills for a long time and can use them on an instinctive level.
To design a program properly, we must:
◦ Analyze a problem statement, typically expressed as a word problem.

◦ Express its essence, abstractly and with examples.

◦ Formulate statements and comments in a precise language.

◦ Evaluate and revise the activities in light of checks and tests and

◦ Pay attention to detail.


Points to remember

The major points to keep in mind are:


Don’t assume on the part of the users

User Interface should be friendly

Don’t forget to comment the code

PAY ATTENTION TO DETAIL

Program, program and program, not just writing code, but the whole process of design and
development.
Lecture 02
We’ll discuss today
Software Categories
System Software
Application Software
History of C/C++ language
Development Environment of ‘C/C++’
Software Categories
Software is categorized into two main categories
System Software
Application Software
System Software
The system software controls the computer. It communicates with computer’s hardware (key
board, mouse, modem, sound card etc) and controls different aspects of operations. Sub
categories of system software are:
Operating system
Device drivers
Utilities
Application Software
A program or group of programs designed for end users. For example a program for accounting,

payroll, inventory control system and guided system for planes, GPS (global positioning system)

anther application software is being used in vehicles which through satellite determines the

geographical position of the vehicles.


History of C language
The C language was developed in late 60’s and early 70’s, in Bell Laboratories. In those days BCPL
and B languages were developed there. The BCPL language was developed in 1967 by Martin
Richards as a language for writing operating systems software and compilers. In 1970 Ken
Thompson used B language to create early versions of the UNIX operating system at Bell
Laboratories. Thus both the languages were being used to develop various system software even
compilers. Both BCPL and B were ‘type less’ languages, every data item occupied one ‘word’ in
memory and the burden of treating a data item as a whole number or real number, for example
was the responsibility of the programmer.
Dennis Ritchie developed a general purpose language, called C language, by using different
features of BCPL and B languages. C uses many important concepts of BCPL and B while adding
data typing and other features. In the start C became widely known as the development language
of the UNIX operating system, and the UNIX operating system was written by using this C language.
The C language is so powerful that the compiler of C and other various operating systems are
written in C. C language has almost unlimited powers to do with computers. You can program to
turn on or off any device of computer. You can do a lot to hard disk and other peripherals. It is very
easy to write a program in C/C++ that stops the running of computer. So be careful while
programming in C/C++.
Tools of the trade
As programmer we need different tools to develop a program. These tools are needed for the
life cycle of programs.
Editors
Compilers and Interpreters
Debugger
Linker
Loader
Editors
First of all we need a tool for writing the code of a program. For this purpose we used Editors in
which we write our code. We can use word processor too for this, but word processors have
many other features like bold the text, italic, coloring the text etc, so when we save a file written
in a word processor, lot of other information including the text is saved on the disk. For
programming purposes we don’t need these things we only need simple text. Text editors are
such editors which save only the text which we type. So for programming we will be using a text
editor.
Compiler and Interpreter
There are two kinds of translators which are known as Interpreter and Compilers.
These translators translate our program which is written in C/C++ language into machine
language.
Interpreters translate the program line by line meaning it reads one line of program and
translates it, then it reads second line, translate it and so on.
The benefit of it is that we get the errors as we go along and it is very easy to correct the errors.
The drawback of the interpreters is that the program executes slowly as the interpreter
translates the program line by line.
Another drawback is that as interpreters are reading the program line by line so they cannot get
the overall picture of the program hence cannot optimize the program making it efficient.
Compilers also translate the English like language (Code written in C) into a language (Machine
language) which computers can understand.

The Compiler read the whole program and translates it into machine language completely.

The difference between interpreter and compiler is that compiler will stop translating if it finds an
error and there will be no executable code generated whereas Interpreter will execute all the lines
before error and will stop at the line which contains the error.

So Compiler needs syntactically correct program to produce an executable code. We will be using
compiler in our course.
Debugger
Another important tool is Debugger.
Every programmer should be familiar with it.
Debugger is used to debug the program i.e. to correct the logical errors.
Using debugger we can control our program while it is running.
We can stop the execution of our program at some point and can check the values in different
variables, can change these values etc.
In this way we can trace the logical errors in our program and can see whether our program is
producing the correct results.
This tool is very powerful, so it is complex too.
Thank You to bear 
Linker
Most of the time our program is using different routines and functions that are located in
different files, hence it needs the executable code of those routines/functions.

Linker is a tool which performs this job, it checks our program and includes all those routines or
functions which we are using in our program to make a standalone executable code and this
process is called Linking.
Loader
After an executable program is linked and saved on the disk and it is ready for execution.

We need another process which loads the program into memory and then instruct the
processor to start the execution of the program from the first instruction (the starting point of
every C program is from the main function).

This processor is known as loader. Linker and loaders are the part of development environment.

These are part of system software. The following figure represents a graphical explanation of all
the steps involved in writing and executing a program.

You might also like