Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!nrl-cmf!cmcl2!brl-adm!adm!cantrell@arecibo.aero.ORG From: cantrell@arecibo.aero.ORG (JOHN CANTRELL) Newsgroups: comp.lang.pascal Subject: RE: Global variables Message-ID: <12633@brl-adm.ARPA> Date: 25 Mar 88 12:31:57 GMT Sender: news@brl-adm.ARPA Lines: 59 I can't speak for Borland (maybe somebody in netland will), but I can speak from experience in the DoD software area. Seen from here, there are several shortcomings with declaring everything global. For example: 1. Global variables exist (i.e., they hold space) as long as the program does, locals go away when the procedure is done. Sure, you say, memory is cheap, I can always buy another megabyte. For every megabyte you add, there is some programmer waiting to use it. There are ways to get around this, but why should you, Pascal has local variables for this purpose, so why not make use of the facilities of the language. 2. If you have a big project (500,000 lines, 40 programmers), how are you going to keep the names straight? Try using i, j and k as loop counters where a subroutine or two is called inside a loop. If these are global, you are guaranteed to have trouble. And no matter how many loop counters you declare globally, I will bet my last dollar that some hacker on the project will need 'just one more'. 3. Let's just say that you do declare everything global. Your names may not make much sense to the other programmers on the job, but so what, they shouldn't be using your variables anyway. Then you get some new guy on the job finishing up for someone else who left and this guy makes the mistake of using one of YOUR variables. How are you going to debug the program when you put everything together later? (This is my pet peeve -- I was in testing!) I tell you how it's done now: You unit test your little piece, then hand it over to the testing organization and get yourself a new job on a new project. Oh, yes, DON'T ever leave a phone number, either, those testing weenies will bother the heck out of you with questions when the code is as plain as the nose on their face. Now, just let me get down off the soapbox . . . So, there really are uses for local declarations. CMU is probably trying to get you ready for the great big world out here where all projects are NOT one-man jobs. The best advice: Let them show you the way, but then reserve judgement until you have worked on a project with 40 other programmers -- or better yet, until you have TESTED the work of some 40 programmers. Then you might get an idea of what they are trying to put across to you at CMU. Hope this helps a little. -jc John C. Cantrell The Aerospace Corporation 2350 East El Segundo Boulevard El Segundo, CA 90245-4691 Tel: (213) 336-4333 cantrell@arecibo.aero.org ******************************************************************************* * * * Fill in your own standard disclaimer, but don't hold me responsible! * * * ******************************************************************************* ------