The Elements of Informix-4gl Style?
Posted in 1992
Path: emory!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!infopiz!lupine!motcsd!starnet!pmahler From: pmahler@StarConn.com (Paul Mahler) Newsgroups: comp.databases.informix Keywords: 4gl style Message-ID: <1992Mar5.021035.18374@StarConn.com> Date: 5 Mar 92 02:10:35 GMT Organization: Starnet-Public Access UNIX--Los Altos, CA 415-949-3133 Looking at most informix programs makes me want to puke. They all look like they were written at terminals with organ pedals instead of a shift key. Of course, this is only a small part of the problem. Most C programs I have seen don't have this problem. If they were written by generally competent programmers they are generally well structured, well styled and easy to read. Most 4gl programs look like they were written by stupid BASIC programmers. This seems to be an artifact of the very first examples that came out of Informix where all the key words were in upper case and lots of extra blank lines were inserted. There doesn't seem to be a pleasant style to most of the 4gl programs out there. There also doesn't seem to be a beautifier that would allow existing programs to be codified to the same style. This is perhaps because the grammer is large. Writing a YACC grammer would be a big deal and anything probably wouldn't work very well. The only grousing I have heard about a beautifier was from Tony Heskett who was trying to figure out how to capitalize the key words, which is, of course, backwards and stupid to boot. So now that I've pissed off all the 4gl programmers out there and you have your flame throwers on, what about this style question? Here is a fragment of code I stole from dbgen by David Snyder. This is a wonderful program written by a superb 4gl programmer. I have changed it a bit for the purposes of discussion. 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 {******************************************************************************* * This program drives the $TABNAME screen. *******************************************************************************} MAIN DEFER INTERRUPT CALL menu_$TABNAME() CLEAR SCREEN END MAIN {******************************************************************************* * This function handles the main ring menu. * *******************************************************************************} FUNCTION menu_$TABNAME() CALL init_$TABNAME() OPEN FORM $PRGNAME FROM "$PRGNAME" DISPLAY FORM $PRGNAME MENU "OPTIONS" COMMAND "Query" "Searches the active database table." HELP 1 CALL qry_$TABNAME() IF q_cnt > 0 THEN IF repo_$TABNAME("C", "Q") THEN # R4GL requires return values LET q_cnt = q_cnt # to be used whether they are END IF # needed or not. ELSE LET w_record.* = n_record.* # Faster than INITIALIZE END IF CALL disp_$TABNAME() COMMAND "Browse" "Browse through rows in the Current List." HELP 1 IF repo_$TABNAME("C", "B") THEN CALL brw_$TABNAME() CALL disp_$TABNAME() END IF COMMAND "Next" "Shows the next row in the Current List." HELP 1 IF repo_$TABNAME("N", "N") THEN CALL disp_$TABNAME() END IF COMMAND "Previous" "Shows the previous row in the Current List." HELP 1 IF repo_$TABNAME("P", "P") THEN CALL disp_$TABNAME() END IF COMMAND "Add" "Adds a row to the active database table." HELP 1 CALL add_$TABNAME() CALL disp_$TABNAME() COMMAND "Update" "Changes a row in the active database table." HELP 1 IF repo_$TABNAME("C", "U") THEN CALL upd_$TABNAME() CALL disp_$TABNAME() END IF COMMAND "Remove" "Deletes a row in the active database table." HELP 1 IF repo_$TABNAME("C", "R") THEN CALL del_$TABNAME() CALL disp_$TABNAME() END IF COMMAND "Current" "Displays the current row of the current table." HELP 1 IF repo_$TABNAME("C", "C") THEN CALL disp_$TABNAME() END IF COMMAND "Output" "Output selected rows in report format." HELP 1 IF repo_$TABNAME("C", "O") THEN CALL out_$TABNAME() END IF COMMAND "Exit" "Returns to the INFORMIX-SQL menu." HELP 1 EXIT MENU COMMAND KEY (CONTROL-G) CALL fgl_prtscr() COMMAND KEY ("0") WHENEVER ERROR CONTINUE LET q_off = q_off CLIPPED, "0" WHENEVER ERROR STOP COMMAND KEY ("1") WHENEVER ERROR CONTINUE LET q_off = q_off CLIPPED, "1" WHENEVER ERROR STOP COMMAND KEY ("2") WHENEVER ERROR CONTINUE LET q_off = q_off CLIPPED, "2" WHENEVER ERROR STOP COMMAND KEY ("3") WHENEVER ERROR CONTINUE LET q_off = q_off CLIPPED, "3" WHENEVER ERROR STOP COMMAND KEY ("4") WHENEVER ERROR CONTINUE LET q_off = q_off CLIPPED, "4" WHENEVER ERROR STOP COMMAND KEY ("5") WHENEVER ERROR CONTINUE LET q_off = q_off CLIPPED, "5" WHENEVER ERROR STOP END MENU CLOSE FORM $PRGNAME END FUNCTION 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 q_off char(10), # offset to jump 'n' rows scrline smallint # line number in browse # This program drives the tabname screen. main defer interrupt call menu_tabname() clear screen end main # This function handles the main ring menu. function menu_tabname() call init_tabname() open f