Advanced Programming Techniques

Post on 21-May-2015

650 views 3 download

Tags:

Transcript of Advanced Programming Techniques

Advanced Programming Advanced Programming TechniquesTechniques

In CA-Clipper 5.3In CA-Clipper 5.3

TechniCon at CA-World’97Session: TM103SR

TechniCon at CA-World’97Session: TM103SR

Always an easier way? Improves programmer productivity Improves application usability Improves application robustness

Why Advanced Programming Techniques?

Application performance Development efficiency

Need for control

Understand the language Understand the environment Suggest realistic options

Know your tools

Think about your task Not just "the usual way" Look for the best way

How to implement?

LOCAL lTest := .t.

...

If lTest

lTest := .f.

Else

lTest := .t.

End

Good

LOCAL lTest := .t.

...

lTest := If( lTest, .f., .t. )

Better

LOCAL lTest := .t.

...

lTest := !lTest

Best

Think about your task Take one good technique Ask yourself if you could use this

in another way?

How to implement?

MyAlias->( dbSeek( cSomeKey ) )

MyAlias->( dbAppend() )

MyAlias->( dbSkip() )

Small sub-functions Modular Re-useable components

Break up your code

Combine smaller sub-functions into larger useable units

Mix and Match

FUNCTION InOrder( nNewOrder )

LOCAL nOldOrder := IndexOrder()

DbSetOrder( nNewOrder )

RETURN nOldOrder

FUNCTION OrdNSearch( nOrder, cKey )

LOCAL nOldOrder := InOrder( nOrder )

LOCAL lRetVal := DbSeek( cKey )

InOrder( nOldOrder )

RETURN lRetVal

@ Row++, Col Get OneVar Valid;

Code->( OrdnSearch( 2, OneVar ) )

@ Row++, Col Get SomeVar Valid;

Code->( OrdnSearch( 3, SomeVar ) )

Read

If this works here, why not elsewhere? Try it out Experiment Think about your task Examine different ways

Exploit yourself

Function ExceptKey( nKey, oBrowse )Local lRetVal := .f.

Do Case Case nKey == K_INS lRetVal := .t.

Case nKey == K_F10 lRetVal := .t.

End

Return lRetVal

Local oBrowse := tBrowseDb( t, l, b, r )Local bExceptBlock := { | nKey, oBrowse | , ; ExceptKey( nKey, oBrowse ) }

...

oBrowse:ForceStable()While lBrowsing lBrowsing := MyKeyHandler(oBrowse, bExceptBlock)End

Function MyKeyHandler( oBrowse, bExceptions ) Local nKey := InKey( 0 ) Local lRetVal := .t.

If Eval( bExceptions, nKey, oBrowse ) Else Do Case // Process normal keystrokes here End End

RETURN lRetVal

Summary data at start of report Multiple reports from same source Same report, varying layouts

Report Problems

Memory efficient Powerful Flexible

Use Arrays

Report = array Page = array element Output line = Sub-array element

Arrays In Reports

Any Questions?

Gary Stark

Internet gstark@dfwmm.net

CIS ID 100033,2324