Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcnc!unc!steele From: steele@unc.cs.unc.edu (Oliver Steele) Newsgroups: comp.lang.c Subject: Re: portability and standards Message-ID: <783@unc.cs.unc.edu> Date: Fri, 10-Jul-87 10:37:54 EDT Article-I.D.: unc.783 Posted: Fri Jul 10 10:37:54 1987 Date-Received: Sun, 12-Jul-87 11:03:16 EDT References: <2290@calmasd.GE.COM> <4715@columbia.UUCP> <107@snark.UUCP> <1103@killer.UUCP> <6095@brl-smoke.ARPA> Reply-To: steele@unc.UUCP (Oliver Steele) Organization: University of North Carolina, Chapel Hill Lines: 54 John Haugh (jfh@killer.UUCP) writes: ]What do you do with a simple status variable like errno that is ]modified by all of the system calls? Doug Gwyn (VLD/VMB)(gwyn@brl.arpa) writes: >A botch. Consider what happens in multi-threaded applications, >such a signal handler that has to do system calls. Of course >there are ways around this misfeature, but they shouldn't have >been necessary. Agreed. There are other examples that aren't (see below). >Don't knock ADT or other structured software design methodologies >until you've learned to use them. A lot of very smart people have >worked very hard over the past few decades to figure out how to >turn software construction into a solid engineering discipline >rather than a guild craft. Much real progress has been made in >understanding the fundamental issues and in developing suitable >methodology, although as usual many practitioners remain ignorant >of theoretical developments (especially in the UNIX community, >which has more than its fair share of random hackers). (I've intentionally blurred the distinction between ADTs and OOP below.) Even very object oriented languages such as Smalltalk don't manage to completely eliminate globals: it is still useful (in the case of Smalltalk) to have such objects as Transcript, Disk, Sensor, and Display. In C you can write functions that assign and return what are really globals and restrict the scope of the actual globals to the file defining these functions (similar to class variables in Smalltalk), but it's arguably clearer to use an object than a function to represent entities such as the standard input stream that people tend to think of as objects. Another way to 'fake' globals is to have a set of functions (or macros) such as putchar() and printf() which take one less parameter than your base set and hide the global inside themselves. In the case of printf() this is convenient; in a drawing module it would require DrawGrayCircle, DrawBlackCircle, DrawWhiteCircle, etc., just to hide Gray, Black, and White from the extra-modular code. This discussion branch started as a question on where to put globals when you do use them; even if they can all be eliminated, most programmers are going to learn ADTs long before they elimate all globals. Most objects conceptually belong with certain modules. For instance, if I were working exclusively with one size of matrix, I would place the zero and identity matrices in the module defining the matrix ADT. ------------------------------------------------------------------------------ Oliver Steele ...!{decvax,ihnp4}!mcnc!unc!steele steele%unc@mcnc.org "They're directly beneath us, Moriarty. Release the piano!"