Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Include Files ? Handy Helpers or The Root of All Evil? Abstract: Back in the day include files were a significant tool for promoting code re-use and.

Similar presentations


Presentation on theme: "1 Include Files ? Handy Helpers or The Root of All Evil? Abstract: Back in the day include files were a significant tool for promoting code re-use and."— Presentation transcript:

1 1 Include Files ? Handy Helpers or The Root of All Evil? Abstract: Back in the day include files were a significant tool for promoting code re-use and building frameworks. Like any tool they were also sometimes abused and as new capabilities were added to the 4gl the old and familiar may have out-lived its welcome. In this session we will explore some of the more "exotic" uses of include files (for you kids that have never seen one) and talk about the pros and cons of different views on their appropriate use in today's coding world.

2 Include Files! Handy Helpers? Or The Root of All Evil? Tom Bascom, White Star Software tom@wss.com

3 A Few Words about the Speaker Tom Bascom; Progress user & roaming DBA since 1987 Partner, White Star Software, LLC – Expert consulting services related to all aspects of Progress and OpenEdge. – tom@wss.com Partner, DBAppraise, LLC – Remote database management service for OpenEdge. – Simplifying the job of managing and monitoring the world’s best business applications. – tom@dbappraise.com 3

4 The oldest and most respected independent OpenEdge DBA consulting firm in the world! Four of the world’s top independent OpenEdge DBAs! Author of ProTop, the #1 FREE OpenEdge Database Monitoring Tool: http://dbappraise.com/protop.html Who is White Star Software?

5 {disclaimer.i} The content of this session is heavily laced with opinion! 5

6 Audience Survey! What version of Progress do you have now? What version of Progress did you start coding with? What version of Progress was your application first written in? 6

7 What is an “Include File”? That seems like a silly question… But there are an amazing number of posts online that make it clear that lots of people do not know what they are. 7

8 What is an “Include File”? Source code which is stored in a distinct source file, but “included” into the main routine at compile time. Referenced in Progress 4gl code as {fileName} – Complicated by possible arguments. De-facto standard file extension is “.i” – But that is not a requirement –.f,.v … – Or no extension at all! 8

9 example.p 9 /* example.p */ {variables.i} find customer no-lock where cust-num = 999 no-error. if not available customer then {msg.i 3} else display name.

10 {variables.i} 10 /* variables.i */ define variable msgtext as character no-undo extent 5 initial [ “no such customer”, “try again”, “what?”, “good work!”, “huh? I’m confused” ].

11 {msg.i} 11 /* msg.i */ do: message msgtext[ {1} ]. pause. end.

12 compile example.p listing “example.list” 12 {} Line Blk -- ---- --- 1 /* example.p */ 2 {variables.i} 1 1 /* variables.i */ 1 2 1 3 define variable msgtext as character no-undo extent 5 initial [ 1 4 "no such customer", 1 5 "try again", 1 6 "what?", 1 7 "good work!", 1 8 "huh? I’m confused" 1 9 ]. 1 10 3 find customer no-lock where cust-num = 999 no-error. 4 if not available customer then 5 {msg.i 3} 1 1 /* msg.i */ 1 2 1 3 1 do: 1 4 1 message msgtext[{1}3]. 1 5 1 pause. 1 6 end. 6 else 7 display name.

13 compile example.p debug-list “example.dbg” 13 1 /* example.p */ 2 /* variables.i */ 3 4 define variable msgtext as character no-undo extent 5 initial [ 5 "no such customer", 6 "try again", 7 "what?", 8 "good work!", 9 "huh? I’m confused" 10 ]. 11 12 find customer no-lock where cust-num = 999 no-error. 13 if not available customer then 14 15 /* msg.i */ 16 17 do: 18 message msgtext[3]. 19 pause. 20 end. 21 else 32 display name.

14 Back in 1985… There were no “objects” in “abl”. There were not even internal procedures nor parameters to external procedures  But we did have include files: – Code reuse! – Standardization! – Productivity! 14

15 15

16 Programmers Progress, 1991 The advanced programmer can take advantage of Progress’ excellent facilities using includes, run-time arguments and parameters. The more a programmer uses these capabilities, the more flexible his code becomes, approaches the structure of “C” and the modularity of “object-oriented” thinking. 16

17 How are Include Files Used? Uniform Data Definitions – To define variables common to many routines. – Similar to a C “header file” i.e. #include Repetitive Code Snippets – An improvement over “cut & paste” – “in-line function” Frameworks and “Skeleton” Procedures – “pick routine” – CRUD maintenance To extend the language 17

18 Uniform data definitions Shared variables – Shame on you! – Conflict in extent, datatype or undo status for global xyzzy. (390) – Shared variable pflugh has not yet been created. (392) Temp-tables and ProDatasets – One of the 4gl’s best features! Magic used by frameworks 18

19 Repetitive Code Snippets 19 /* fixtime.i * * keep the clock updated... * * march 6, 1989 */ put screen row 1 column 1 substring( string( time, "hh:mm am" ), ( if substring( string( time, "hh:mm am" ), 1, 1 ) = " ” then 2 else 1 ) ) + " ". (TRIM() came along in v5…)

20 Repetitive Code Snippets 20 /* lib/upd-xrec.i */ {1}[3] = {2} {1}[4] = {1}[3] - {1}[1] {1}[5] = {1}[3] - {1}[2] {1}[2] = {1}[3] /* and used like this… */ assign {lib/upd-xrec.i tt_table.tbl-cre _TableStat-create} {lib/upd-xrec.i tt_table.tbl-rd _TableStat-read} {lib/upd-xrec.i tt_table.tbl-upd _TableStat-update} {lib/upd-xrec.i tt_table.tbl-del _TableStat-delete}. /* [1] = base * [2] = last (previous current) * [3] = this * [4] = current * [5] = interval */

21 Frameworks 21... enterdata: do while true with frame queries: {inc/fixtime.i} find person no-lock where recid( person ) = p_recid no-error. display person.person-name person.active person.phone-num. if ( q = 1 ) then {inc/query.i person person-name} else if ( q = 2 ) then {inc/query.i person active} else if ( q = 3 ) then {inc/query.i person phone-num} {inc/basename.i ""{0}"" scrname} {inc/switch.i} end. (The CASE statement came along in v7…)

22 Extending the Language Fill in gaps and smooth over rough edges Modernize legacy 4gl with modern approaches (OO) Provide missing 4gl functionality Emulate features from other languages 22

23 Mike Fechner, Director, Consultingwerk Ltd. mike.fechner@consultingwerk.de Lists, Generics, Enumerators, Enumerations, Serialization DIY: Closing the OO Gap http://confluence.consultingwerkcloud.com/wiki/pages/viewpage.action?pageId=6881319

24 foreach.i 24 {3} not used, only used to fill up syntax and match c#

25 Named Arguments Named Arguments are position independent. And optional. There is no equivalent for parameters to procedures, functions and methods. 25

26 26 The Other Side Speaks!

27 Programmers Progress, 1991 … since the contents of an include file cannot be seen by the reader, you should be VERY parsimonious in using include files... As often as not, using an include file to make code more readable can have the opposite effect. 27

28 Bad Things About Includes Code Bloat Side Effects Hidden Dependencies Ugly Syntax Bad Code 28

29 Code Bloat Each reference to an include file is copied into the source routines The listing files show that the expanded source can be much larger that it appears This results in larger r-code 29

30 Side Effects Includes can impact flow of control, record locks and transaction scope and everything else Code in an include is not “protected” in any way – At best you get “security through obscurity” – Someone who knows what the include does can easily extract information … – … or arrange for pre-conditions to be met – … or do funky things with arguments to inject their own code snippets. 30

31 Hidden Dependencies Within the code Between modules (what code needs to be recompiled?) 31

32 Side Effects & Dependencies 32... enterdata: do while true with frame queries: {inc/fixtime.i} find person no-lock where recid( person ) = p_recid no-error. display person.person-name person.active person.phone-num. if ( q = 1 ) then {inc/query.i person person-name} else if ( q = 2 ) then {inc/query.i person active} else if ( q = 3 ) then {inc/query.i person phone-num} {inc/basename.i ""{0}"" scrname} {inc/switch.i} end. (The CASE statement came along in v7…)

33 Spaghetti! 33

34 Ugly Syntax “{“ and “&” – need I say more? 34

35 Ugly Syntax “{“ and “&” – need I say more? Unpacking nested quotes… 35

36 Bad Code “Include files let you hide bad code…” Technology is a tool. The quality of results depends on the person using the tool. 36

37 Bad Coding… Who here thinks they are “better than average”? Who has looked at some code and said “that’s really awful, the person who wrote that should be fired!”? … and then realized it is their own code from X years ago? Do you know someone who writes better code than you do? Can you explain what is “better” about it? Does that person work in your company? Is it your boss? Is your boss in the room? 37

38 Hiding Bad Code Yes. When done right – that’s sort of the point. 38

39 39 Conclusion!

40 Handy Helper? 40

41 Root of All Evil? 41

42 Undecided? 42

43 Questions? 43

44 Suggested Additions? 44

45 Exotica Using an argument as the name of an include to include Use the contents of an include as the arguments to another include Using {*} and providing defaults for optional args Same include, different behaviors controlled by pre-processor (positional args vs named args) Recursive includes The /* conditional compile example 45

46 Thank You! 46


Download ppt "1 Include Files ? Handy Helpers or The Root of All Evil? Abstract: Back in the day include files were a significant tool for promoting code re-use and."

Similar presentations


Ads by Google