Re: The Elements of Informix-4gl Style?
Posted in 1992
Path: emory!wupost!think.com!rpi!usenet.coe.montana.edu!news.u.washington.edu!sumax!ole!thebes!camco!soundex.Celestial.COM!stephsf.com!wengland From: wengland@stephsf.com (Bill England) Newsgroups: comp.databases.informix,alt.sources Keywords: 4gl style Message-ID: <1992Mar11.231037.10890@stephsf.com> Date: 11 Mar 92 23:10:37 GMT References: <1992Mar5.021035.18374@StarConn.com> Organization: Stephen Software Systems Inc., Tacoma/Seattle, +1 800 829 1684 In article <1992Mar5.021035.18374@StarConn.com> pmahler@StarConn.com (Paul Mahler) writes: > > SAMPLE ONE > >DATABASE test > > >DEFINE w_record RECORD LIKE $TABNAME.* # working record >DEFINE n_record RECORD LIKE $TABNAME.* # null record >DEFINE q_cnt INTEGER # current size of list >DEFINE q_cur INTEGER # index position in list >DEFINE q_off CHAR(10) # offset to jump 'n' rows >DEFINE scrline SMALLINT # line number in browse > Ych! > > SAMPLE TWO > >Here is much the same program with various stylistic changes. > > >database test >define > w_record record like tabname.*, # working record > n_record record like tabname.*, # null record > q_cnt integer, # current size of list > q_cur integer, # index position in list Ych! Ych! > >So what do you folks think? What makes for an attractive, >legible, practical 4gl style? >-- >-------------------------------------------------------------- >Paul Mahler internet: pmahler@StarConn.com This discussion probally belongs in alt.religion.informix ;-) However, IMHO both of the above examples are rather difficult to read. But, then I've not written straight 4gl code for several years. The following style is designed to be used when extending the 4GL language by using M4. ----- include(`include/standard.m4')dnl # # SSS-GLCORE Version 3.0 # # (c) Copyright 1991, Stephen Software Systems, Inc. # All Rights Reserved. # -- More copyright stuff deleted, permission to distribute -- these examples is granted to anyone who can read this. [...] ## # ## Function entity( entity_account ) Define entity_account Integer, where_part char(400), query_text char(SIZE_QUERY_TEXT), b_queryactive Integer, entity_rec Record T_ALL DEF ENTITY_DEF End Record, answer char, contact_key Like entity.contact_key, address_key Like entity.address_key Call clear_menu() W_ENTITY O_WINDOW Menu "Entity" Command "Query" "Look up matching entities." Call clear_menu() Clear Form Display "Press ESC to query, DEL discards query." At 1,1 Let Int_Flag = FALSE Let status = 0 Let SQL_ERROR = 0 Whenever Error Continue Construct where_part On T_ALL F_KEYS LIST_TABLE ENTITY_DEF From LIST_DISPLAY ENTITY_DEF Attribute(REVERSE) Whenever Error Stop If status Or SQL_ERROR Then Error "Your Query is too complex; Please make the request shorter. ", status Call display_entity() Continue Menu End If If Int_Flag Then Call display_entity() MESS(`Query aborted.') Continue Menu End If Let query_text = "Select F_ALL RECNAME LIST_TABLE T_KEYS T_ENTITY ENTITY_DEF,", "F_ALL T_CONTACT T_ADDRESS ENTITY_DEF", " From entity, address, contact ", " Where entity.address_key = address.address_key ", " and entity.contact_key = contact.contact_key ", " and ", where_part Clipped, " Order by entity.fl_name " Call regen_entity_curs(query_text) Returning b_queryactive, entity_rec.* Call display_entity() If Not b_queryactive Then Continue Menu End If Fetch First entity_curs into entity_rec.* Command "Prev" "Go to previous entity selected by Query." If Not b_queryactive Then MESS(`Please query a entity first.') Continue Menu End If ------ Not to be outdone I'm also including a perl program that can convert your 4gl applications to use more of a 4gm style. It's far from perfect but it does convert key words that are all uppercase to leading letter uppercase. With slight modifications it could be used to "correct" code to any other style you might prefer. --- Cut here --- #! perl # # $Id: adj,v 1.1 1992/03/11 23:00:48 wengland Exp wengland $ # # $Log: adj,v $ # Revision 1.1 1992/03/11 23:00:48 wengland # Initial revision # ## Infomix 4gl to 4gm Key word converter. ## ## # (c) Copyright 1991, Stephen Software Systems, Inc. # # This software is furnished under the terms of the GNU # public license and is freely distributable. # # This software is supplied FREE of charge and comes with # no warrenties expressed or implied. The author is not # responsible for any damages, monetary or otherwise. # # USE AT YOUR OWN RISK. ## eval "exec perl -S -i~ $0 $*" if $running_under_some_shell; %reserved_word= split(/( )/, 'ABSOLUTE AFTER AND ARRAY ASCII AT ATTRIBUTE ATTRIBUTES BEFORE '. 'BORDER BOTTOM BY CALL CHAR CLEAR CLIPPED CLOSE COLUMN COLUMNS '. 'COMMAND CONSTRUCT CONTINUE CREATE CURRENT CURSOR CYAN DATABASE DATE '. 'DECIMAL DECLARE DEFAULTS DEFER DEFINE DELETE DESC DISPLAY DISTINCT '. 'DROP ELSE END ERROR EVERY EXIT EXTERNAL FALSE FETCH FIELD FINISH '. 'FIRST FOR FOREACH FORM FORMAT FROM FUNCTION GLOBALS GROUP HEADER '. 'IF INDEX INITIALIZE INPUT INSERT INTEGER INTERRUPT INTO IS KEY LAST '. 'LEFT LENGTH LET LIKE LINE LINES MAIN MARGIN MATCHES MAX MENU MESS '. 'MESSAGE MOD MONEY MROW NAME NEED NEXT NO NOT NOTFOUND NULL OF '. 'ON OPEN OPTIONS OR ORDER OUTPUT PAGE PAGENO PREPARE PREVIOUS '. 'PRINT PRINTER PROMPT PUT RECORD RED REPORT RETURN RETURNING '. 'REVERSE RIGHT ROW ROWS SCREEN SCROLL SELECT SET SKIP '. 'SLEEP SMALLINT START STATUS STOP SUM TABLE TEMP THEN TO '. 'TODAY TOP TRAILER TRUE UNIQUE UPDATE USING VALUES WHENEVER '. 'WHERE WHILE WINDOW WITH WITHOUT WRAP'); while (($key,$value) = each %reserved_word){ local($v2); $value = $key; ($v2,$value) = unpack("AA*", $key ); $value =~ tr/[A-Z]/[a-z]/; $reserved_word{$key} = $v2.$value; } ## Extra translations not covered above. # $reserved_word{'order'}= 'Order'; $reserved_word{'database'}= 'Database'; $reserved_word{'Genledg'}= 'genledg'; $reserved_word{'GenLedg'}= 'genledg'; $reserved_word{'SMALLINT'}= 'Integer'; $reserved_word{'Smallint'}= 'Intege