[M3devel] globals vs. instance variables

Jay K jay.krell at cornell.edu
Mon Sep 21 06:21:09 CEST 2015


We have:


cm3/MODULE M3Backend; ...  VAR   obj_file : M3ObjFile.T := NIL;  obj_wr   : Wr.T        := NIL;  obj_name : TEXT        := NIL;  log      : Wr.T        := NIL;  log_name : TEXT        := NIL;
...PROCEDURE Close (<*UNUSED*> cg: M3CG.T) =  BEGIN    IF obj_file # NIL THEN      TRY        NTObjFile.Dump (obj_file, obj_wr);      EXCEPT Wr.Failure, Thread.Alerted =>        Msg.FatalError (NIL, "problem writing object file: ", obj_name);      END;      Utils.CloseWriter (log, log_name);      obj_file := NIL;      obj_wr   := NIL;      obj_name := NIL;      log      := NIL;      log_name := NIL;    END;  END Close;


Surely we should add those variables to M3CG_Ops in orderto get them to Close for this specific M3CG?

i.e. prefer "instance variables" over "module variables" aka globals.
Perhaps in a record called M3Backend to give an appearance of opacityor perhaps in an actual opaque type, though I hate to pay for theextra heap allocation just to achieve opacity.
 (Larger point is the cm3 is written an old unfortunate thread-unsafe style with many globals.)

And this is a good reason then to smush M3CG.T and M3CG_Ops.T together,in order for M3Backend.New() result to be passed back to Close.

 - Jay 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20150921/63f199d9/attachment-0001.html>


More information about the M3devel mailing list