ser_ch8
TRANSCRIPT
-
8/12/2019 ser_ch8
1/38
2005 IAS, Universitt Stuttgart 1
SERSoftware Engineering for Real-Time Systems
8 Implementation
8.1 Basic Principles of Implementation
8.2 Structured Programming
8.3 Programming Languages
8.4 Building Programs
8.5 Programming Style
8.6 Summary
-
8/12/2019 ser_ch8
2/38
2005 IAS, Universitt Stuttgart 2
SER
Aims of Implementation
starting point: design specification (system architecture and components)
transformation of the design results into programs that can be executed ona specified target platform
executable programs and their source code
8.1 Basic Principles of Implementation
-
8/12/2019 ser_ch8
3/38
2005 IAS, Universitt Stuttgart 3
SER
Overall view
8.1 Basic Principles of Implementation
Requirementsengineering
Systemanalysis
System andsoftware design
Implementation
Test
Requirementsspecification
Problem
Xxx
Legend:
Development phase
Development resultYyy
System
model
Designspecification
Realizedsystem
Testdocumentation
Maintenance,enhancements
Systemready for use
-
8/12/2019 ser_ch8
4/38
2005 IAS, Universitt Stuttgart 4
SER
the implementation reflects the system architecture, data structures andidentifier defined in the system design
the abstraction levels (tiers) of the design are present in theimplementation, too
the interfaces between the components of a software system areexplicitly commented in the implementation
the consistency of objects and operations can already be checked by acompiler
8.1 Basic Principles of Implementation
Characteristics of a good implementation
The accomplishment of these characteristics depends on
the programming principle (structured, object-oriented, component-based) the programming language
the programming environment
the programming style
consistency design vs. implementation
-
8/12/2019 ser_ch8
5/38
2005 IAS, Universitt Stuttgart 5
SERSoftware Engineering for Real-Time Systems
8 Implementation
8.1 Basic Principles of Implementation
8.2 Structured Programming
8.3 Programming Languages
8.4 Building Programs
8.5 Programming Style
8.6 Summary
-
8/12/2019 ser_ch8
6/38
2005 IAS, Universitt Stuttgart 6
SER
Definition - structured programmierung
the aim of structured programming is to represent algorithms so that theircontrol flow is easy to oversee and to modify.
only 3 basic concepts are used: s equence , selection a nd iteration
structured programming is a principle that does not depend on aprogramming language, e.g. C, Pascal, Basic, FORTRAN, ...
also object-oriented programming languages support structuredprogramming
8.2 Structured Programming
Major issues of structured programming
limited use of GOTO statements
distinction between useful (z.B. error handling) and useless GOTO statements
limited use of global variables
-
8/12/2019 ser_ch8
7/38
2005 IAS, Universitt Stuttgart 7
SER
Concepts of structured programming (structure blocks)
8.2 Structured Programming
successive statements (sequence)
B
A
A B
condition
conditional statement (selection)
condition
A
A
condition
conditional repetition (iteration)
example in C
statementA;
statementB;
example in C
if (conditon)
statementA;elsestatementB;
example in C
do{
statementA;} while (condition);
example in C
while (condition){
statementA;}
-
8/12/2019 ser_ch8
8/38
2005 IAS, Universitt Stuttgart 8
SER
Transformations
If the whole program can be reduced to one single structure block then it isfree of GOTOs.
8.2 Structured Programming
structure block=
exactly 1 entryand 1 exit
-
8/12/2019 ser_ch8
9/38
2005 IAS, Universitt Stuttgart 9
SER
Methods of avoiding GOTOs
duplicating statements
introducing procedures
using additional variables
using additional boolean variables
8.2 Structured Programming
Guiding principle:
short code sequences, that are used at a few locations only, can betransformed by code duplication
long and often used code sequences should rather be transformed into
procedures
-
8/12/2019 ser_ch8
10/38
2005 IAS, Universitt Stuttgart 10
SER
Useful GOTOs
realization of non-existing control structures
single level exit out of iterations and procedures
multi level exit in case of errors or alarms
hand-made optimization of structured programs
8.2 Structured Programming
for (i = 1;i < 10;i++) {
if (func(i)== 5)
goto exit;
}
exit:
statementA;
...
for (i = 1;i < 10;i++) {
for (y = 1;y < 20;y++) {
if (func(i,y) == 5)
goto exit;
}}
exit:
statementA;
...
Single level exit Multi level exit
-
8/12/2019 ser_ch8
11/38
2005 IAS, Universitt Stuttgart 11
SERSoftware Engineering for Real-Time Systems
8 Implementation
8.1 Basic Principles of Implementation
8.2 Structured Programming
8.3 Programming Languages
8.4 Building Programs
8.5 Programming Style
8.6 Summary
-
8/12/2019 ser_ch8
12/38
2005 IAS, Universitt Stuttgart 12
SER
Programming Languages
Quality criteria for programming languages:
data structures
control flow
efficiency
safety
portability
degree of self-documentation
special language elements
8.3 Programming Languages
-
8/12/2019 ser_ch8
13/38
2005 IAS, Universitt Stuttgart 13
SER
the availability of data structures in programming languages is an importantissue
data structures of older programs (fields, pointer on data structures) arerisky, because they allow unlimited access and can be modified in terms of size and structure at runtime
a language with its own elements for data structures is saver and betterreadable
expandable abstract data types in object-oriented programminglanguages enable flexible and expandable solutions
8.3 Programming Languages
Data structures
-
8/12/2019 ser_ch8
14/38
2005 IAS, Universitt Stuttgart 14
SER8.3 Programming Languages
Control flow
the support of GOTO statements (BASIC, C, FORTRAN) allows unlimitedcontrol flows that are hard to understand
restrictions of GOTO statements (PASCAL)
the absence of GOTO statements (Modula-2, Smalltalk) enables a betterprogram structure
exception and interrupt handling in technical applications (Ada)
support of parallel processes and synchronization (Ada)
-
8/12/2019 ser_ch8
15/38
2005 IAS, Universitt Stuttgart 15
SER
Efficiency
due to its machine-orientation, C supports the realization of very efficientprograms
object-oriented languages allow merely less efficient programs
the efficiency can be strongly influenced by using compilers incorporatingadvanced code optimizers
8.3 Programming Languages
-
8/12/2019 ser_ch8
16/38
2005 IAS, Universitt Stuttgart 16
SER
Safety
the safety of a programming language depends on the readability and themechanisms for the type checking
static typing is preferable the compiler is able to determine the type of each expression at
compile time
safety risks automatic type conversion arithmetic operations with pointers
runtime checking increases safety (Ada)
exception handling mechanisms increase safety (Ada, C++, Java)
8.3 Programming Languages
-
8/12/2019 ser_ch8
17/38
2005 IAS, Universitt Stuttgart 17
SER
Degree of self-documentation
prerequisite for readability and maintainability
important for programs with long life cycles
explicit interface description (ADA, Modula-2)
use of keywords instead of special characterse.g.: BEGIN ... END instead of { ... }
programs are only written once, but often read
powerful languages with many special functions are harder tounderstand
8.3 Programming Languages
-
8/12/2019 ser_ch8
18/38
2005 IAS, Universitt Stuttgart 18
SER
Portability
standardized language (Ada, C) with standardized module libraries
availability of compilers for different target platforms
8.3 Programming Languages
Special language elements
support of complex numbers (FORTRAN)
wide range fixed point numbers (COBOL)
matrix operations (APL)
interrupt service routines (micro-controllers)
bit operations (micro-controllers)
-
8/12/2019 ser_ch8
19/38
2005 IAS, Universitt Stuttgart 19
SER
Criteria for selecting a programming language
quality of the compiler efficiency of generated code support of error checking integration with development environments user-friendliness
availability of libraries libraries with mathematical functions class libraries for graphical user interfaces libraries for real time features
company policies company-wide standards language writs (e.g. telecommunications: Chill) education of the staff
customer requirements
8.3 Programming Languages
-
8/12/2019 ser_ch8
20/38
2005 IAS, Universitt Stuttgart 20
SER
Generations of programming languages (1)
1st generation: machine languages (1GL): direct use of the instruction set, the processor provides
binary representation
specification of absolute memory addresses
programs hard to read and error-prone
2nd generation: assembly languages (2GL): mnemonic abbreviations for operation codes (e.g. L for LOAD )
instruction set according to machine architecture symbols for operands and jump destinations (e.g. L R2, SUM )
translator (assembler) performs a 1:1 transformation into a machineprogram
one needs to be aware of the processor architectureway of programming is determined by the structure of the machine
programs error-prone and not portable
8.3 Programming Languages
-
8/12/2019 ser_ch8
21/38
2005 IAS, Universitt Stuttgart 21
SER
Generations of programming languages (2)
3rd generation: high level programming languages (3GL) elements of the programming language not dominated by the machine architecture
but by the problems to be expressed
data abstraction
abstraction of control flow (instead of jump instructions)
expressions in mathematical notation
translation (1:n, loss of efficiency)
examples: C, FORTRAN, C++, Java
8.3 Programming Languages
4th generation (4GL)
advanced abstraction, i.e. even more far away from the machine and closer to theproblem
mainly destined for specific domains, e.g. database queries (SQL)
examples: visual composers fr GUIs, SQL
abstraction ofmachine languages
very high level languages
-
8/12/2019 ser_ch8
22/38
2005 IAS, Universitt Stuttgart 22
SER
Evolution of programming languages
Reference: Ludewig, J.: Sprachen fr das Software-EngineeringInformatik-Spektrum, volume 16 magazine 5, 1993, p. 288 (reduced version)
8.3 Programming Languages
1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000
Assembler
FORTRAN
ALGOL 60
LISP
COBOL
BASIC
PL/1
SIMULA
ALGOL 68
BCPL
PROLOG
PASCAL
C
FORTRAN 77
MODULA-2
ADA
SMALLTALK
C + +
EIFFEL
FORTRAN 90
ADA 9X
-
8/12/2019 ser_ch8
23/38
2005 IAS, Universitt Stuttgart 23
SERSoftware Engineering for Real-Time Systems
8 Implementation
8.1 Basic Principles of Implementation
8.2 Structured Programming
8.3 Programming Languages
8.4 Building Programs8.5 Programming Style
8.6 Summary
-
8/12/2019 ser_ch8
24/38
2005 IAS, Universitt Stuttgart 24
SER
Building programs (1)
for one target platform development platform = target platform
building of executable program with a native compiler example: developing a Windows program under Windows
development platform target platform building of executable program with a cross-compiler example: developing a micro-controller program unter Windows
drawback: every target platform requires a specific compiler
8.4 Building Programs
-
8/12/2019 ser_ch8
25/38
2005 IAS, Universitt Stuttgart 25
SER
Building programs (2)
drawback: still limited to one programming language
8.4 Building Programs
for n target platforms
programming language
platform-independentintermediate language
platform 1
runtimeenvironment
platform n
runtimeenvironment...
Java
Java byte code
Windows
Javavirtual machine
Linux
Javavirtual machine...
-
8/12/2019 ser_ch8
26/38
2005 IAS, Universitt Stuttgart 26
SER
Building programs (3)
with n programming languages for n target platforms
8.4 Building Programs
programminglanguage n
UNCOLUniversal Computer Oriented Language
platform 1
runtime
environmentplatform n
runtime
environment...
programminglanguage 1
... C#
MSILMS Intermediate Language
Windows
CLRCommonLanguage
Runtime...
Visual Basic ...
Linux
CLRCommonLanguage
Runtime
example: Microsoft .NET
-
8/12/2019 ser_ch8
27/38
2005 IAS, Universitt Stuttgart 27
SER
The building process in detail
8.4 Building Programs
source code
syntactical correctsource code
object code
target codegeneration
object code
target codegeneration ...
source code
syntactical correctsource code
Compiler
Linker
Interpreter
programinterpretation
effects and resultsof processing
executable file(e.g. *.exe)
syntactic andsemantic analysis
syntactic andsemantic analysis
-
8/12/2019 ser_ch8
28/38
2005 IAS, Universitt Stuttgart 28
SER
Particulars concerning micro-controllers
loadable file has to be transferred from the development platform onto thetarget platform (e.g. via serial link or Ethernet)
this can be achieved by means of a so-called programming utility or flashtool
8.4 Building Programs
machine codewith relocatable addresses
machine codewith absolute addresses
locator specification
ROM/RAM size and addresses regions for code, stack, constant data, variables,
dynamic variables, interrupt vector table start address of the program ...
Locator
loadable file (e.g. *.hex)
Linker
allocation to availablememory areas
-
8/12/2019 ser_ch8
29/38
2005 IAS, Universitt Stuttgart 29
SERSoftware Engineering for Real-Time Systems
8 Implementation
8.1 Basic Principles of Implementation
8.2 Structured Programming
8.3 Programming Languages
8.4 Building Programs8.5 Programming Style
8.6 Summary
-
8/12/2019 ser_ch8
30/38
2005 IAS, Universitt Stuttgart 30
SER
Programming Style
The readability of a program depends on:
the programming language
the programming style of the person implementing the program
Elements of a good programming style:
structuring
expressiveness
appearance
efficiency
8.5 Programming Style
Programs are modified and extended programs must be understandable
-
8/12/2019 ser_ch8
31/38
2005 IAS, Universitt Stuttgart 31
SER
Structuring
adequate selection of program modules and their sizes
reduction of complexity by avoidance of branch instructions(structured programming)
8.5 Programming Style
Appearance separation of declaration and implementation parts
common structure for all declaration parts(constants, data types, variables, classes, modules, methods,procedures)
division of interface descriptions (parameter lists) into input, output andinput/output parameters
separation of comments and program text
indentation for outlining the program structure
-
8/12/2019 ser_ch8
32/38
2005 IAS, Universitt Stuttgart 32
SER
Example: coordinates of a map
8.5 Programming Style
Nested if statements (1)
MAPSQUARE
1
MAPSQUARE
2
150120 18090
Longitude
90
30
Latitude 60
if (latitude > 30 && longitude > 120) if (latitude
-
8/12/2019 ser_ch8
33/38
2005 IAS, Universitt Stuttgart 33
SER
Nested if statements (2)
8.5 Programming Style
well-formatted nested if if (latitude > 30 && longitude > 120){
if (latitude
-
8/12/2019 ser_ch8
34/38
2005 IAS, Universitt Stuttgart 34
SER
Expressiveness
Selection of names for objects and operations meaningful, consistent names, even if the names might turn out
to be very long
generally accepted abbreviationse.g.: max = maximum
offs = offset ptr = pointer
dont mix different languages (e.g. English and German names)
use small and capital letterse.g.: capital letters for data types, classes and operations
small letters for constants and variables use nouns for values, verbs for activities and adjectives for
conditionse.g.: width, readKey, isActive
8.5 Programming Style
-
8/12/2019 ser_ch8
35/38
2005 IAS, Universitt Stuttgart 35
SER
Use of comments
short and precise description of the purpose of a statement or statementsequence
every system module has to begin with a detailed comment about the purpose of the module the methods, procedures, ... being used
who is the person having created/modified the module when the creation/modifications were carried out
every procedure should be preceded by a comment describing the task,the essentials about how the task is carried out and the input/output
parameters handed over
explain the meaning of variables explain the purpose of coherent program parts (program blocks)
explain statements that happen to be hard to understand
keep the comments consistent when doing modifications
8.5 Programming Style
-
8/12/2019 ser_ch8
36/38
2005 IAS, Universitt Stuttgart 36
SERSoftware Engineering for Real-Time Systems
8 Implementation
8.1 Basic Principles of Implementation
8.2 Structured Programming
8.3 Programming Languages
8.4 Building Programs8.5 Programming Style
8.6 Summary
-
8/12/2019 ser_ch8
37/38
2005 IAS, Universitt Stuttgart 37
SER8.6 Summary
Tips and tricks (1)
avoid tricky programming not an indicator of intelligence does not increase the security of your workplace
avoid global variables global variables can be manipulated at from location of a program high risk of side effects when a modification of global variables
becomes necessary
first of all programs should be a mean of communication amongprogrammers, and only in a second way they are also a mean for thecommunication with computers
correctness is more important than efficiency
a program without comments is worthless
a program without documentation is not worth a lot
-
8/12/2019 ser_ch8
38/38
2005 IAS, Universitt Stuttgart 38
SER
Tips and tricks (2)
think before compiling check your code in mind before invoking the compiler make sure that you understand your code code inspection, explain your code to other persons
avoid deeply nested control structures (if, while, for, ...) around 3 levels max.
good programmers are good, independent of the programming languagethey are using
bad programmers are bad, independent of the degree of assistance a
programming language is able offer
8.6 Summary