Gordon morrison temporalengineering-delphi-v3

54
Temporal Engineering with Delphi A New Technology Changing the Game By Gordon Morrison, Author Breaking the Time Barrier

description

Webinar given during the 2010 Delphi Code Rage 5.

Transcript of Gordon morrison temporalengineering-delphi-v3

Page 1: Gordon morrison temporalengineering-delphi-v3

Temporal Engineeringwith Delphi

A New Technology Changing the GameBy

Gordon Morrison, AuthorBreaking the Time Barrier

Page 2: Gordon morrison temporalengineering-delphi-v3

Agenda1. Open Software2. The Challenge3. Traditional Approaches4. The Bread Crumb Problem5. My Solution6. Implementation7. Quantification8. Why Time is Important9. Questions

www.vsmerlot.com2

Page 3: Gordon morrison temporalengineering-delphi-v3

1. Open Software• This presentation is based on technology in

my patent– I have made this patented work freely available– Anyone can use this technology, go for it!– The patent is U.S. Patent #6,345,387

• Issued Feb 2002• Download from the patent office

– This technology is described in my book• Reads easier and better than my patent• Title: Breaking the Time Barrier

www.vsmerlot.com3

Page 4: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

2. The Challenge• Using your traditional spatial If-Then-Else

(ITE) approach– Produce a five-function calculator

– add, subtract, multiply, divide, and percent• The specification is at: www.vsmerlot.com• Count the number of ITE and Case/Default

Statements– Count every logic decision point– Don’t use my temporal approach

4

Page 5: Gordon morrison temporalengineering-delphi-v3

The Challenge Test

• Conform to the specification• Successfully complete the test matrix• Final Test is:

– Enter ‘-3.14159 - -2.14159=‘– There are eighteen entries– How many logic test will your code make?

www.vsmerlot.com5

Page 6: Gordon morrison temporalengineering-delphi-v3

3. Traditional Approaches

• Using the traditional state machine– Expect ninety plus logic tests

• If – then – else• Switch – case – default • Case – value

• How well will you do?

www.vsmerlot.com6

Page 7: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Proper State Machine(1)

• In a proper state machine, the state transitions are all complete and orthogonal.– Complete Transitions: a transition is defined for every

possible situation.– Orthogonal Transitions: none of the transitions have

overlapping conditions.

• With a proper state machine– a next state is defined for every possible condition– the designated next state is unique

• My comment:– The proper state machine is spatial using If-Then-Else (ITE)– The proper state machine doesn’t know where it’s working

(1)- © 2005 Carnegie Mellon University – PSP II Designing and Verifying State Machines- page 41

7

Page 8: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Spatial Calculator Statechart• The author’s

implementation:– 112 ITE / Case– 1,000+ LOC

• Arrows are ambiguous– -> Transitions– -> Events– -> States

• Minus is an ambiguous transition

• Begin to negate1• subtract• opEntered to negated2

“Practical Statecharts in C/C++, © CMP Books, Miro Samek, Ph.D.8

Page 9: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Spatial Calculator Call Diagram

• This diagram has no calls to trace display

• It’s very complex

9

Page 10: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Spatial With Debugging

• Spatial trace– Red lines …

• Trace debug– Each function– Embedded– Side effects

10

Page 11: Gordon morrison temporalengineering-delphi-v3

4. The Bread Crumb Problem• Edsger Dijkstra once asked, "Why has elegance

found so little following?"• Imagine a CPU without a program counter (PC)

– The hardware would need to save states continually• Dropping bread crumbs

– After an interrupt determine where it was executing• Look for the trail of bread crumbs

– Massive amounts of logic as administrative overhead• Bread crumb support built in

– This is spatial logic

www.vsmerlot.com11

Page 12: Gordon morrison temporalengineering-delphi-v3

PC -> Pointer

• The program counter is a temporal pointer– Hardware is temporal (mostly)

• Spatial application software does not have an equivalent PC

• Traditional state machines were created to treat the symptom of no software PC– Solution drop bread crumbs– We call these ‘state machines’

www.vsmerlot.com12

Page 13: Gordon morrison temporalengineering-delphi-v3

5. My Solution

• Create an application pointer (temporal)– One ‘time pointer’ for every Engine/Table– The time pointer keeps track of application

logic– The time pointer is always available for

progressive protocol based application– The time pointer eliminates most bread

crumb logic

www.vsmerlot.com13

Page 14: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Temporal State Machine (TSM)• Event or non-event driven applications• States are true or false

– Transitions are next true or next false

• Three fundamental parts– Engine (time, logic test, trace, and control)– Logic-Flow / Rule Table (class)– Data-Flow / Reusable Members

• Logic-flow is orthogonal to data-flow– No control flow in data manipulation– No data manipulation in control flow

14

Page 15: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

TSM Structure• Engine/Table relationship

– iTime is the pointer into array of rule/step– Table contains 1 or more rules– Each rule has a single entry point

• Rules are like basic blocks

• Array of rules consist of steps– Every step is a binary state

• Each step has a test condition• Each step has a True Behavior• Each step has a Next Rule/Step (iTime pointer)• Each step has a False Behavior • Each step has a Next Rule/Step (iTime pointer)• Each step has a Trace (tied to the specification)

15

Page 16: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

TSM Pattern

Data-Flow

…On…

…Off…

…On…

…Off…

Logic-FlowEngineT-Trace

F-Trace

temporal• iTime pointer• Dynamically

binds• Tracing

– True Trace– False Trace

16

Table

Page 17: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Temporal vs. Spatial ITE

• Temporal domain– Time Indexed

• Reduces complexity– State diagrams– Call diagrams– Models

• Reduces code size• Increases reuse• Includes trace• Preemptable

• Spatial domain– Test bread crumbs

• Increases complexity– State diagrams– Call diagrams– Models

• Increases code size• Decreases reuse• Manual trace• ~Not Preemptable

17

Page 18: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Engine / Table RelationshipEngine• Engine is temporal (iTime)• Preemption control (while)

– Test condition (if – state)• Dynamic bind True Behavior

– Next True Rule/Step iTime– True Trace

• Dynamic bind False Behavior– Next False Rule/Step iTime– False Trace

– End if – logic– End while – control loop

Table• Each row is a temporal

sequence– Rule/Step (name)– Test condition (state)

• True Behavior– Next True Rule/Step

• False Behavior– Next False Rule/Step

– Trace (unique to app)

18

Page 19: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

6. Implementationprocedure TCOSAFrame.Run(intState integer);beginbEngineLocal := TRUE;iState := intState;while bEngineLocal AND bEngineGlobal dobegin

if iState = rRule[iTime].iState thenbegin

rRule[iTime].pTrueRule;True_Trace(iTime);iTime := rRule[iTime].iTrueRule;

end elsebegin

rRule[iTime].pFalseRule;False_Trace(iTime);iTime := rRule[iTime].iFalseRule;

end;end;

end;

iTime is temporal

Determined by logic19

Dynamically Bind-True

Dynamically Bind-False

Page 20: Gordon morrison temporalengineering-delphi-v3

Delphi Structure Setup// ************** Temporal Rules Definition ******************

pProcedureType = procedure of Object; // Dynamic Bind DefinitionTCOSARules = classpublic // the logic test can also be defined as a Boolean functionprivate

iTime : integer;iState : integer; // logic test // Static State DefinitionpTrueRule : pProcedureType; // Dynamic Bind TrueiTrueRule : integer;pFalseRule : pProcedureType; // Dynamic Bind FalseiFalseRule : integer;iTrace : integer;

end;

www.vsmerlot.com20

Page 21: Gordon morrison temporalengineering-delphi-v3

Delphi Logic Table Setup

rRule : Array [0..24] of TCOSARules; // logic table allocation

procedure pBRT(iTime : integer; iState : integer;pTrueRule : pProcedureType; iTrueRule : integer;pFalseRule : pProcedureType; iFalseRule : integer;iTrace : integer); // prototype fill logic array

www.vsmerlot.com21

Page 22: Gordon morrison temporalengineering-delphi-v3

Implementation Logicprocedure TCOSAcalc.pBRT(iTime : integer; iState : integer;

pTrueRule : pProcedureType; iTrueRule : integer;pFalseRule : pProcedureType; iFalseRule : integer; iTrace : integer);

beginrRule[iTime] := TCOSARules.Create; // create rowrRule[iTime].iTime := iTime; // fill in rowrRule[iTime].iState := iState; rRule[iTime].pTrueRule := pTrueRule;rRule[iTime].iTrueRule := iTrueRule;rRule[iTime].pFalseRule := pFalseRule;rRule[iTime].iFalseRule := iFalseRule;rRule[iTime].iTrace := iTrace;

end;

www.vsmerlot.com22

Page 23: Gordon morrison temporalengineering-delphi-v3

Dynamic Calls Build Logic

// Next Next// Rules Static True True False False// Steps State Behavior Rule Behavior Rule TracepBRT(rOpr1, iNeg44, Negate, rOpr1+1,Clr_Buf, rOpr1+1,100);pBRT(rOpr1+1,iDigit, Any_Number,rOpr1+1,Ignore, rOpr1+2,101);pBRT(rOpr1+2,iDot59, One_Period,rOpr1+3,Ignore, rOpr1+4,102);pBRT(rOpr1+3,iDigit, Any_Number,rOpr1+3,Ignore, rOpr1+4,103);

www.vsmerlot.com23

Page 24: Gordon morrison temporalengineering-delphi-v3

23-Steps of Calculator Logic

www.vsmerlot.com24

Page 25: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

The User Perspective(tends to be temporal)

• Calculator– Enter Operand 1 (optional sign)– Enter Operation ( + - * / )– Enter Operand 2 (optional sign)– Select Result Type ( = % ( + - * / ))

• The user perspective is generally temporal• Let’s look at entering

– ‘-’ ‘3’ ‘.’ ‘1’ ‘4’ ‘1’ ‘5’ ‘9’– Followed by the Subtract Operation

25

Page 26: Gordon morrison temporalengineering-delphi-v3

Entered -

temporal

Page 27: Gordon morrison temporalengineering-delphi-v3

True BehaviorEntered 3

temporal

Page 28: Gordon morrison temporalengineering-delphi-v3

False BehaviorEntered .

temporal

Page 29: Gordon morrison temporalengineering-delphi-v3

Entered 1

temporal

Page 30: Gordon morrison temporalengineering-delphi-v3

Entered 4

temporal

Page 31: Gordon morrison temporalengineering-delphi-v3

Entered 1

temporal

Page 32: Gordon morrison temporalengineering-delphi-v3

Entered 5

temporal

Page 33: Gordon morrison temporalengineering-delphi-v3

Entered 9Count Step Trace Eng Static Dynamic Behavior Value 1 +T= 0; 100 Off; 44; 44; Negate; N= - 2 +T= 1; 101 Off; 1; 1; Any_Number N= -3 3 ĞF= 1; 101 On; 1; 59; Ignore; N= 4 +T= 2; 102 Off; 59; 59; One_Period; N= -3. 5 +T= 3; 103 Off; 1; 1; Any_Number N= -3.1 6 +T= 3; 103 Off; 1; 1; Any_Number N= -3.14 7 +T= 3; 103 Off; 1; 1; Any_Number N= -3.141 8 +T= 3; 103 Off; 1; 1; Any_Number N= -3.1415 9 +T= 3; 103 Off; 1; 1; Any_Number N= -3.14159

Trace

temporal

Page 34: Gordon morrison temporalengineering-delphi-v3

Enter Operation (‘-’)

temporal

Page 35: Gordon morrison temporalengineering-delphi-v3

Not a Number

temporal

Page 36: Gordon morrison temporalengineering-delphi-v3

Not CE or C

temporal

Page 37: Gordon morrison temporalengineering-delphi-v3

Not Addition

temporal

Page 38: Gordon morrison temporalengineering-delphi-v3

10 ĞF= 3; 103 On; 1; 44; Ignore; N= 11 ĞF= 4; 104 On; 12; 44; Ignore; N= 12 ĞF= 5; 105 On; 11; 44; Ignore; N= 13 ĞF= 6; 106 On; 1; 44; Push_Disp; N= 14 ĞF= 7; 500 On; 43; 44; Ignore; N= 15 +T= 8; 501 On; 44; 1; Subtraction; N= -3.14159

TraceMatch Subtraction

temporal

Page 39: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Understanding the Time IndexENTER Rule State True Action Next True False Action Next False

‘-’ rOper1 = <iNeg44>? Negate rOper1+1 Ignore rOper1+1

‘3’ +1 = <iDigit>* Any_Number rOper1+1 Ignore rOper1+2

‘.’ +2 = <iDot59>? One_Period rOper1+3 Ignore rOper1+4

‘14159’ +3 = <iDigit>* Any_Number rOper1+3 Ignore rOper1+4

Time +4

39

• I know where I am• I know where I came from• I know where I am going• At iTime + 4 ‘-’ is “not a number” from iTime+3

Time

Page 40: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

7. Quantification

T TR DS Behavior Value1 100 44; Negate; N= -2 101 1; Any_Number; N= -33 101 59; Ignore; N=4 102 59; One_Period; N= -3.5 103 1; Any_Number; N= -3.16 103 1; Any_Number; N= -3.147 103 1; Any_Number; N= -3.1418 103 1; Any_Number; N= -3.14159 103 1; Any_Number; N= -3.1415910 103 44; Ignore; N=

Compare Temporal Trace

40

Page 41: Gordon morrison temporalengineering-delphi-v3

To Spatial Trace

www.vsmerlot.com41

T Behavior e->sig ValueO O O19, g-negated1, 2, 020, negated121, g-negated1, 1, -022, g-negated1, 1010, -0O O O31, int132, g-int1, 1, -333, g-int1, 1101, -334, g-frac1, 0, -3.O O O37, g-frac1, 2, -3.

38, frac139, g-frac1, 1, -3.40, g-frac1, 1010, -3.O O O45, g-frac1, 1107, -3.1415946, g-Oper1, 1107, -3.1415947, g-frac1, 3, -3.1415948, g-opEntered, 0, -3.1415949, g-Oper1, 0, -3.1415950, g-Oper1, 3, -3.1415951, g-opEntered, 2, -3.1415952, opEntered53, g-opEntered, 1, -3.1415954, g-opEntered, 1107, -3.14159

Page 42: Gordon morrison temporalengineering-delphi-v3

Temporal-Logic Counts

www.vsmerlot.com42

• -3.14159 – ten steps to enter nine actions– 90% efficient– 10% of cost is overhead

• -3.14159 - - 2.14195 = thirty steps for eighteen actions– 60% efficient– 40% of cost is overhead

Page 43: Gordon morrison temporalengineering-delphi-v3

Spatial-Logic Counts• -3.14159 – fifty-four steps for nine actions

– 16.67 % efficient– 83.34% of cost is overhead

• -3.14159 - - 2.14195 = ninety-six steps for eighteen actions– 18.75 % efficient– 81.25% of cost is overhead

www.vsmerlot.com43

Page 44: Gordon morrison temporalengineering-delphi-v3

Spatial Enter “-” OnlyTrc= 1, g-calc, sig= 0 ; Operand= , Trc= 2, g-calc, sig= 0 ; Operand= , Trc= 3, g-calc, sig= 1 ; Operand= , Trc= 4, g-clear; Operand= , Trc= 5, g-ready, sig= 0 ; Operand= 0, Trc= 6, g-ready, sig= 2 ; Operand= 0, Trc= 7, g-ready, sig= 1 ; Operand= 0, Trc= 8, g-begin, sig= 0 ; Operand= 0, Trc= 9, g-begin, sig= 2 ; Operand= 0, Trc= 10, g-begin, sig= 1 ; Operand= 0, Trc= 11, g-begin, sig= 1107 ; Operand= 0, Trc= 12, g-negated1, sig= 0 ; Operand= 0, Trc= 13, g-begin, sig= 0 ; Operand= 0, Trc= 14, g-calc, sig= 0 ; Operand= 0, Trc= 15, g-begin, sig= 3 ; Operand= 0,

www.vsmerlot.com44

Trc= 16, g-ready, sig= 3 ; Operand= 0, Trc= 17, g-ready, sig= 0 ; Operand= 0, Trc= 18, g-negated1, sig= 2 ; Operand= 0, Trc= 19, g-negated1, sig= 1 ; Operand= -0, Trc= 20, g-negated1, sig= 100 ; Operand= -0, Trc= 21, g-calc, sig= 100 ; Operand= -0, Trc= 22, g-negated1, sig= 3 ; Operand= -0, Trc= 23, g-final, sig= 0 ; Operand= -0, - End of Analysis

Trc= 24, g-calc, sig= 0 ; Operand= -0, Trc= 25, g-calc, sig= 3 ; Operand= -0, Trc= 26, g-final, sig= 2 ; Operand= -0, Trc= 27, g-final, sig= 1 ; Operand= -0, - End of Analysis

Page 45: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

A Temporal State Diagram

• Simple state view• True Behavior

– One green arrow• False Behavior

– One red arrow• Temporal

– Trace– Specification

• Compliance

45

Page 46: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Statechart ComparisonTemporal Spatial

46

Page 47: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

Call Diagram ComplexityTemporal Spatial

47

Page 48: Gordon morrison temporalengineering-delphi-v3

Summary

Temporal Actions Logic Steps Efficiency Overhead‐pi 9 10 90.0% 10.0%

‐pi‐(‐pi‐1) 18 30 60.0% 40.0%

Spatial‐pi 9 54 16.67% 83.34%

‐pi‐(‐pi‐1) 18 96 18.75% 81.25%

www.vsmerlot.com48

Page 49: Gordon morrison temporalengineering-delphi-v3

www.vsmerlot.com

8. Why Time is Important• Understanding “Time” in software means not having to do

an “if” to test where the program is executing and what has happened.– 23 Logic points-Temporal calculator example– 112 Logic points-Spatial calculator example– Sampling of spatial logic tests

• 3 tests for IDC_PLUS• 4 tests IDC_MINUS• 2 tests IDC_MULT• 2 tests IDC_DIVIDE• 9 tests for IDC_0• 11 tests for IDC_1_9

49

Page 50: Gordon morrison temporalengineering-delphi-v3

Spatial Software• Must leave a trail of “bread crumb” states

– This is pure overhead• Must track down where it was

– This is pure overhead• Difficult to maintain

– Keeping the overhead straight• Difficult to modify

– Keeping the overhead straight

www.vsmerlot.com50

Page 51: Gordon morrison temporalengineering-delphi-v3

Temporal Software

• Keeps a temporal pointer• Reduces complexity• Eliminates much of the overhead• Easier to maintain• Easier to modify

– Add new rule– Change the logic

www.vsmerlot.com51

Page 52: Gordon morrison temporalengineering-delphi-v3

Software Quality

• Testing doesn’t improve quality– Testing fixes quality problems– Quality is still poor

• Temporal engineering– Improves quality– Reduces overhead logic– Fewer things to go wrong

www.vsmerlot.com52

Page 53: Gordon morrison temporalengineering-delphi-v3

Where I’ve Used Temporal• Disk driver analysis (Symbios Logic)• Data migration (US West / HP)• Data filtering• Lexer/Parser – Data analyzer• Radar control system• Robotic arm control• Embedded applications• Code generator

www.vsmerlot.com53

Page 54: Gordon morrison temporalengineering-delphi-v3

The End – Definitions• COSA – Coherent Object System Architecture

– U.S. Patent #6,345,387 abandoned by inventor– Available to the public in book: Breaking the Time Barrier– NOT associated with www.rebelscience.org

• BNF – Backus-Naur Format– Diagramming the logic of syntax– Basis for temporal engineering

• ITE – If-Then-Else logic – commonly referred to as ‘spaghetti code’

• CMU – Carnegie Mellon University• SEI – Software Engineering Institute at CMU• CPU – Central Processing Unit• UML – Unified Modeling Language

www.vsmerlot.com54