Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: C++ coding standards (Comment needed) Keywords: standard,variables Message-ID: <56529@microsoft.UUCP> Date: 13 Aug 90 22:11:05 GMT References: <2161@runxtsa.runx.oz.au> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 14 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 for the following reasons: .... I believe the major goal should be to initialize where declared. Since some initialization values are computed down-stream in a function, some declarations have to placed down-stream. The general rule my group uses is to move declarations into the smallest scope reasonable. If one keeps one's functions small, then any declaration strategy should work. If a variable is used through-out a function, continue to declare that variable at the start of the function.