Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!tcs!nujoizey!gwu From: gwu@nujoizey.Berkeley.EDU (George Wu) Newsgroups: comp.lang.c++ Subject: Re: C++ coding standards (Comment needed) Keywords: standard,variables Message-ID: <963@tcs.tcs.com> Date: 15 Aug 90 22:29:01 GMT References: <2161@runxtsa.runx.oz.au> Sender: usenet@tcs.com Reply-To: gwu@nujoizey.Berkeley.EDU (George Wu) Lines: 50 In article <2161@runxtsa.runx.oz.au>, edward@runxtsa.runx.oz.au (Edward Birch) writes: |> A friend of mine works with a large organization where they have defined a |> standard that "variables must be declared where first used". |> |> I think that this is an absolutely insane standard . . . I must agree with you. We have no such standard, and so I see all kinds. I find that the interspersed declarations really do cloud the issue. And especially when you have multiple programmers working together, you MUST take maintenance issues into consideration. I find myself screaming when I am debugging someone else's code, I want to find the declaration of a variable, and I find myself forced to wade through the code. This is made worse by the fact that often the variables are defined somewhere in the class hierarchy. But I, of course, still have to parse all the damn code. The only helpful points are that most people at least try to limit the length of routines, and modern editors can do string searches. As for the practice of declaring variables inside a block, ie. within a pair of curly braces, I used to do so to minimize the scope of the variable and clearly designate the variable for use only under certain conditions. For example, I might do something like: switch (fooCode) { case BAR: { char *ascii; // some complex mess ... } case BAZ: { char *ebcdic; // ... } } HOWEVER, I soon discovered that I was doing so because the bloody routine was getting too large. The excess size of the routine is what made restricted scoping use advantageous. The REAL solution was to break down the routine into smaller routines. George ---- George J Wu | gwu@tcs.com or ucbcad!tcs!gwu Software Engineer | 2121 Allston Way, Berkeley, CA, 94704 Teknekron Communications Systems, Inc.| (415) 649-3752