Date post: | 21-Jan-2016 |
Category: |
Documents |
Upload: | penelope-welch |
View: | 214 times |
Download: | 0 times |
22 Nov
1. Comments on HW32. Java I/O – Exception handling
3. Inversion4. JSD
Pascal identifier
Errors in Pascal Identifier
A compiler for INTEGERsWhat do you think about it?
INTEGER
Possible errors
1. Integer does not start with a sign or digit
2. Sign followed by non-digit
3. At least one digit does not follow the sign of a signed INTEGER
4. Non-digit follows 1st digit of an INTEGER
Errors in INTEGER
Design for Human Error
Base data structure that allows for human errors on correct data structure – Allows intelligible messages to explain error in terms of
a deviation from the known structure– Data structure to accommodate errors should contain
all possible errors
Cognitive principle:– We make sense of the unknown / unrecognizable in
reference to what we know / recognize
A note on Java Text I/O
• HelloFileRead2• HelloFileRead2a
If a checked (задержанный) exception throws an exception, you must either catch it or else declare in the method header that the exception is thrown.
Scanner methods catch an exception generated for an empty file
Structure Clashes:Modified Net Movement Problem
Report
Title line Report body End line
Report line*
Report file
Daily transaction
file
Block*
Record count Block body
*
Input file
Transaction record
Suppose the input file is blocked, with each block containing a record count followed by a number of records.
Modified Net Movement Problem:The essence of the difficulty
The program must have an operation that is executed once per block and an operation that is executed once per group
So there must be both a block component and a group component
But we cannot have a single program structure with process block and process group components.
We have a boundary clash--the boundaries of blocks are not synchronized with the boundaries of groups.
Solution to Boundary Clash:Decomposition
Daily Net Movement Report
Input file PA
Inter- mediate
filePB
Input, intermediate and report files, together with their correspondences
Daily transaction
file
Block *
Record count
Block body
*
Daily transaction
file
Transaction record
Transaction record
Input file Intermediate Intermediate Report file
*
Daily transaction
file
*
*Transaction
record
Part group
Daily net movement
report
Title lineReport body End line
Total line *
Program PA Program PB
file file
Comments on JSP Solution
• Correctness– PA and PB can be designed using JSP. The programs we obtain
are distinct. – A serial file forms a boundary between any pair of programs.
We don't have to think "dynamically". • For example, we don't need to ask, "What if a group extends over
several blocks?" or • "What if a group has no data records?“
– We know our programs are correct, because we can think in terms of static data structures
• Inefficient– By introducing an intermediate file, we have roughly doubled the
execution time (in comparison with a program that produced a report without an intermediate file).
– We will learn a little later how to optimize our design by a simple program transformation, program inversion.
General Solution for Structural Clashes
The resolution of the structure clash is effected by decomposing the program P into two programs, PA and PB as shown below:
A PA I PB X
Correspondences between A, I, XThe data structures of the serial input file, A, the
intermediate file, I, and the output file, X are shown below:
* *
*
*
*
A
B
C Z
Y
X
C
I
•There is no structure clash between A and I, so the structure of PA can be constructed without difficulty; the same is true of I and X and PB. • Whereas in general, the description of a file as an iteration of records is rarely sufficient--though always true--in designing a program, in the case of resolving a structure clash, this description is invaluable. •The intermediate file, I, contains the largest component common to both A and X--an idea analogous to the "greatest common divisor" of two integers.
Analysis of PA and PB
Program decomposition allows us to focus on a correct analysis of PA and PB.
The processing for the system diagram
IPA PB
can be accomplished in a number of ways:
1. Batch processing2. Parallel processing (co-routines)3. Inversion (quasi-parallel)
Processing of PA and PB using (a) batch processing, (b) parallel
processing and (c,d) program inversion
IPA PB
A PA
X
PA produces a record and invokes the subroutine PBI which uses it to produce X.
PBI
We say that PBI is inverted with respect to its input file.
PB produces X, invoking the subroutine PAI to obtain the next record.
PAI
PB
A
X
We say that PAI is inverted with respect to its output file.
(a) (b)
(c)
(d)
call PA get
PA:
put call PB
put call PB
put call PB
PB
get(process)
call PA get
(process)
(process)
Program Inversion (инверсия программ)
• Program inversion is a purely mechanical transformation of the independent programs, PA and PB, into a main program and subroutine
• The subroutine has a single ENTRY point and stores its return address within its state vector so that it is resumable.
– 3 states of the subroutine: (i) open the file for rading/writing; (ii) process a record; (iii) close file
Concept of state vector (вектор состояния)
A program consists of:
1. the program text
2. local variables
3. text pointer to next instruction to be executed
state vector
Program Inversion
Significance of Inversion
Uses of inversion
The roots of Object-based analysis in Jackson’s entities
When item transactions are sorted by item # into groups, we recognize each item as an entity (or object). To produce a report showing net movement of each item, weMust process each item group as an iteration of transaction records. It is wrong toProcess the file as a selection of records as below:
Jackson System Development (JSD)
Ideas underlying JSD1. The real-world as modeled: a simulation (analogical model)2. Each entity is JSD is object. JSD is object based3. System is modeled as a network of communicating sequential processes4. JSD specification is in principle executable, and can be transformed into
executable code (using inversion).
JSD method consists of 6 steps: (Student Loan System)1. Entity / Actions 2. Entity Structure3 Initial Model and System Diagram4 Function5. System Timing6 Implementation
Student Loan System(Ñèñòåì äëÿ обработка студенческéõ заемîâ)
• A university gives loans to students. Before getting a loan, there is an evaluation process after which agreement is always reached. A TE transaction records each step of the evaluation process, and a TA transaction records the overall loan agreement. A student can take any number of loans, but only one can be active at any time. Each loan is initiated by a TI transaction. Then, the student repays the loan with a series of repayments. Each repayment transaction is recorded by a TR transaction. Finally, a loan is terminated by a TT transaction.
• Two output functions are desired: (1) an inquiry function that prints out the loan balance for any student, and (2) a repayment acknowledgment
sent to each student after payment is received by the university.
Entity/action step
• Characteristics of entities and actions
• Make candidate list of entities and actions
• Finalize list of entities and actions
Student Loan SystemConsider the following description of a student loan system:
A university gives loans to students. Before getting a loan, there is an evaluation process after which agreement is always reached. A TE transaction records each step of the evaluation process, and a TA transaction records the overall loan agreement. A student can take any number of loans, but only one can be active at any time. Each loan is initiated by a TI transaction. Then, the student repays the loan with a series of repayments. Each repayment transaction is recorded by a TR transaction. Finally, a loan is terminated by a TT transaction.
Two output functions are desired: (1) an inquiry function that prints out the loan balance for any student, and (2) a repayment acknowledgment sent to each student after the university receives payment.
Entity Structure Diagram
Modeling real-world entity as process stream
System diagramNetwork of communicating sequential processes
Using JSP to Implement Functions
System Implementation using Inversion
Implementation of Scheduler using JSP