Re: avoiding huge globals files
Posted in 1996
In article <I74V1KAgzFuyEwzu@smooth1.demon.co.uk>, David Williams <djw@smooth1.demon.co.uk> wrote: >... > I also agree with use of globals but only in a very limited sense. > > E.g. one on my library functions is cursor handling > > open_cursor(select statement,...) returning cursor_id > close_cursor(cursor_id) etc (there are quite a few functions...). > > The way to implement this is have an array which tracks info about > each cursor:- > > Arrays Cursors[20] of > record > status char(1) "A"vailable /"U"sed > select_statement char(1000) > ..... > end record > > The main cursor handling functions (used by programs) each contain > case statements calling functions to actual do the work since cursor > names are not dynamic:- > > function close_cursor(cursor_id) = > > case > when cursor_id = 01 > call close_cursor_01() > > when cursor_id = 02 > call close_cursor_02() > > otherwise > <call error handler> > end case > end function > > Now each cursor has a unique name (MY_CUR_NN) where NN is the cursor > id and quite a few functions associated with it so exists in a > separate module :- > > Module cursor01 > function close_cursor_01 > CLOSE MY_CUR_01 > end function > I don't quite follow why it is better to put each cursor name in a separate module. Is it realistic to be so concerned about the module size? I would have just done: function close_cursor(cursor_id) = case when cursor_id = 01 close my_cur_01 when cursor_id = 02 close my_cur_02 .... This technique is used extensively in the Power-4gl toolkit (see signature below) e.g. for controlling window handling, but the functions are kept in one module to keep from having to use globals. Otherwise, I certainly agree that globals should be used in a limited and easy to control manner, and your method of using a global file for a "family" of modules adheres to that philosophy. > Who said 4GL is not object orientated :->. Exactly. Well, let's not get too carried away. ---------------------------------------------------------------------- John H. Frantz Power-4gl: Extending Informix-4gl frantz@centrum.is http://www.rl.is/~john/pow4gl.html ^^^^^^^^^^^ is now up and running again -------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet