Computer Software Programming - School of Civil Engineering USM
Download
Report
Transcript Computer Software Programming - School of Civil Engineering USM
Programming and Software
Engineering
1
Software Development
We can define two main classes of software:
User-written software
solve a particular problem, access information,
automate routine tasks
this has been a traditional approach for engineers
availability of powerful applications software has
greatly reduced the need for users to write
programs
Commercial software
software written for commercial distribution, or for
the use of other people within an organization
2
Software Complexity and
Software Engineering
Comparing simple user-written
programs to commercial applications is
like comparing a birdhouse to the
Skydome
For example, software for the space
shuttle consists of over 40 million lines
of code!
3
The State of the Software
Industry
Software is one of the most important
industries in the world
Although the applications are high tech,
software companies are still run like
cottage industries
Software is manufactured today the
same way the first automobiles were
manufactured 100 years ago!
4
Software Manufacturing
Methods
Each program is built from scratch by
skilled craftspeople
The components must be carefully
adjusted for the whole thing to work
Parts or components are not
interchangeable between programs (or
cars in 1900)
There are few standards
5
Critical Problems
Software takes too long to develop
Productivity is low
There are many bugs that are difficult
to fix
Much effort is directed to reinventing
the wheel (e.g., creating user
interfaces)
Programmers must be highly skilled
6
Software Engineering
Designing a software system is as complex as
designing a rocket, a large building, or a car.
Designing software systems requires a sound
engineering methodology
Currently, most programmers are not trained
or certified as engineers
Software engineering has become an
important discipline
7
Critical Labour Shortage
There is a critical shortage of
programmers and other information
technology professionals
Very few engineering schools offer
programs in software engineering
PPKA will have one of the first software
engineering programs in MALAYSIA
8
Software Life Cycle
The software life cycle consists of
several phases, starting with
identification of a need, and ending only
when the software is no longer in use
The software life cycle is similar to the
life cycle of any manufactured or
engineered product
9
Software Life Cycle (summary)
Identify and describe an application
Analyse the application in detail
Preliminary design
Detailed design
Coding
Testing and debugging
Documentation and maintenance
10
Software Life Cycle
Identify and describe an application
market and user surveys
brainstorming
conceptual design
Analyse the application in detail
identify the functional modules
11
Software Life Cycle
Preliminary design
Detailed design
describe the general software structure using
flowcharts or pseudocode
design alternatives can be explored at this stage
completely specify the program logic
Coding
implement the design using a programming
language
coding from a detailed design is like building a
house from a blueprint
12
Software Life Cycle
Test and debug
errors can be due to syntax (ie, incorrect
grammar), or logic
logic errors are very difficult to detect
Documentation and maintenance
software may remain in use for years
someone must continue to fix bugs, add features,
and help users
the cost of maintenance can be much higher than
the cost of development
13
Programming Languages
Assembly language
High-level languages
FORTRAN, C, Pascal
Fourth-generation languages (4GLs)
Very high-level languages
application generators
natural language
14
Assembly Language
Much software is still written in assembly
language
Advantages
Disadvantages
speed, compactness, efficiency
not portable
difficult to implement and debug
every function must be programmed at
machine level
Thousands of programs written in Intel
80x86 assembly language will not run on
any other processor
15
High-level Languages
Most software is written in high level
languages
Fortran, Pascal, Basic and C are popular
C has become a de facto standard for
several reasons
standards exist, so the code is portable
it has much of the power and flexibility of
assembly language
16
Problems with these
Languages
Difficult to learn and use
The only built-in I/O support is characterbased read and write
Not suitable for occasional “quick and dirty”
programming
Development of Graphical User Interface is
difficult
Much of the code is a reinvention of the
wheel
17
Fourth Generation Languages
(4GLs)
4GLs and Rapid Application
Development (RAD) tools are used to
develop applications with little or no
programming
Typically use a graphical, drag-and-drop
approach
Corresponding source code is generated
automatically
18
Examples of RAD Tools
Microsoft Visual Basic
Borland Delphi
Powersoft PowerBuilder
Topspeed Clarion
19
Structured Programming
An important methodology for dealing with
complexity is structured programming
Complex tasks need to be broken down into
simpler subtasks
Structured programming reduces complex
problems to collections of simple,
interconnected modules
It is up to the programmer to implement
structured programming
20
Programming for DOS
DOS provides few system services to the
programmer
It is up to the programmer to implement
the following modules for each application
from scratch
user interface
printer drivers
video drivers
etc.
As a result, every application looks and
works differently
21
Programming for Windows
Windows provides many standard services
to the programmer
It also specifies a common look and feel
for all applications
Now the programmer does not need to
worry about low level drivers, GUI
programming, etc.
The programs call Windows Application
Program Interface (API) functions
Unfortunately, the programmer needs to
be knowledgeable about hundreds of API
functions
22
Graphical User Interfaces
In most applications, the majority of
code is associated with the user
interface
The Windows API provides hundreds of
functions to create menus, dialog
boxes, etc.
Developing the GUI is difficult
23
Procedural Vs. Interactive,
Event-driven Programs
Traditional programs are procedural,
with limited user interaction
Most Windows applications are event-
driven
The program responds to user events,
like menu selections, keyboard input
and mouse clicks
24
Hello, World!
A classical C programming example simply
prints the message “Hello, world” on the
screen.
In standard C, the entire program is shown
below.
#include <stdio.h>
main()
{
printf(“Hello, world\n”);
}
25
Hello, World!
The equivalent program in Windows requires
two pages of cryptic code
The program creates a window, and writes
“Hello, Windows” in the centre
This is the simplest Windows program
possible
This example demonstrates the shift from
text-based applications to event-driven
graphical applications
26
Hellowin.c Page 1
/*-------------------------------------------------------HELLOWIN.C -- Displays "Hello, Windows" in client area
(c) Charles Petzold, 1992
--------------------------------------------------------*/
#include <windows.h>
long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ;
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
static char szAppName[] = "HelloWin" ;
HWND
hwnd ;
MSG
msg ;
WNDCLASS wndclass ;
27
Hellowin.c Page 2
if (!hPrevInstance)
{
wndclass.style
= CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon
= LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor
= LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
RegisterClass (&wndclass) ;
}
28
Hellowin.c Page 3
hwnd = CreateWindow (szAppName,
// window class name
"The Hello Program", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT,
// initial x position
CW_USEDEFAULT,
// initial y position
CW_USEDEFAULT,
// initial x size
CW_USEDEFAULT,
// initial y size
NULL,
// parent window handle
NULL,
// window menu handle
hInstance,
// program instance handle
NULL) ;
// creation parameters
29
Hellowin.c Page 4
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam,
LONG lParam)
{
HDC
hdc ;
PAINTSTRUCT ps ;
RECT rect ;
30
Hellowin.c Page 5
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, "Hello, Windows!", -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
31
GUI Development Tools
Interactive tools have appeared to allow
the programmer to design and test the
GUI graphically
The code is automatically generated to
implement the GUI
This saves much time, especially for
inexperienced programmers
32
Object-Oriented Programming
(OOP)
Traditional languages treat data and
procedures as separate entities
The programmer designs procedures
(instructions) to manipulate data
(variables, files, etc.)
33
Object-Oriented Programming
(OOP)
Object-Oriented languages treat
programs as a collection of objects
An object is a combination of data and
procedures that are stored together as
a reusable unit
Objects communicate by sending
messages to each other
34
Object-Oriented Programming
(OOP)
A powerful feature of OOP is inheritance
New objects can be based on existing
objects, with just minor changes
Groups of similar objects can be
grouped into classes
35
Object-Oriented Programming
(OOP)
Each member or instance of a class
contains shared code, plus code specific
to the instance
For example, each open window in
Windows is an instance of a class of
window objects
Methods for opening, closing, moving,
resizing, etc. are shared by all instances
36
Advantages of OOP
Generic objects can be reused in many
applications
This reuse of software encourages a
building block approach to software
development, using standardized parts
Software development is much faster
Software is easier to understand, debug
and maintain
37
Disadvantages of OOP
Difficult to learn for programmers used
to procedural languages
A new way of thinking is required
Objects reduce portability of code
38
Object-Oriented Languages
The major OOP language is C++
C++ is standard C with object-oriented
extensions
Another OOP language is Smalltalk
A brand-new alternative is Java
39
Component Software
Software reuse can be accomplished
using component software
Example: Microsoft Component Object
Model (COM) and ActiveX
Existing ActiveX components can be
incorporated into new applications,
saving much development time
40
Java
Announced by Sun Microsystems in
1995
Greatly hyped!
Seen as a way to compete with the
Wintel duopoly
Issues have been political, as well as
technical
41
The Java Promise...
Embedded applications like set-top
boxes and cellular phones
Internet applications
Network computers
Platform-independent software
development
42
What is Java?
A new language, similar to C++ but
without the drawbacks
built-in garbage collection
no pointers
bounds checking
Object oriented from ground up
The language improvements eliminate
many sources of bugs
43
Write Once, Run Anywhere
Java includes standard libraries for graphical
interfaces, etc.
Java programs run inside a Virtual Machine
(VM)
VM is an abstract computer that runs
compiled Java programs. The JVM is
"virtual" because it is generally
implemented in software on top of a "real"
hardware platform and operating system.
They are independent of processor or
operating system
44
Applets and Network Software
Java can be used to write normal
programs, or “applets” that run inside a
Web browser
Applets are downloaded from a server
before running
The Network Computers being
promoted by Sun, Oracle and others will
run Java
45
Java Applets
Virtual
Machine
Browser
Applet
Server
46
The Hype and the Reality
Sun is trying to enforce “100% Pure” Java
that will run on any certified VM
Microsoft and others are extending and
modifying Java
Visual J++ makes use of Windows capabilities
not portable
Microsoft, Netscape and others have
developed their own flavours of the VM
The Java specification continues to change
47
The Trade-offs
Pure Java
Runs on any
platform
Lowest common
denominator
Limited development
tools
Performance not
optimized
Proprietary Java
May be platformspecific
Makes use of features
of underlying operating
system
Good development tools
Optimized performance
48
User-Oriented Languages
Easy to use programming applications have
emerged to meet the need of end-user
programming
A good example is Microsoft Visual Basic
Users with limited programming experience
can quickly develop powerful, professionallooking applications with full graphical
interfaces.
49
Macros and Application
Customization
Many useful applications can be created by
building on existing software
Word and Excel can be extensively
programmed using Visual Basic for
Applications
For example, you could create a program to
accept data using an input form, analyze the
results, and plot a graph, all in Excel
50
Computer Aided Software
Engineering (CASE)
CASE is a set of productivity tools for
programmers and software developers
The tools are analogous to word
processors and spreadsheets for
business people
CASE is still immature, but will become
increasingly important in the future
51
Computer Aided Software
Engineering (CASE)
The CASE toolkit includes:
Design tools
Prototype tools
flow diagrams, structure charts, etc.
user interface, screen generators, report
generators
Information repository tools
database for the software development project
52
Computer Aided Software
Engineering (CASE)
Program development tools
organize, generate and test code
Methodology tools
support standard development
methodology
53
THE END !
54