Xref: utzoo comp.software-eng:2590 comp.misc:7553 Path: utzoo!attcan!uunet!samsung!think!ames!ncar!tank!cps3xx!eecae!upba!dsndata!wayne From: wayne@dsndata.uucp (Wayne Schlitt) Newsgroups: comp.software-eng,comp.misc Subject: Re: Coding standards (was Re: Programmer productivity) Message-ID: Date: 3 Dec 89 20:03:24 GMT References: <34796@regenmeister.uucp> <2226@jato.Jpl.Nasa.Gov> <128179@sun.Eng.Sun.COM> <546@sagpd1.UUCP> <4727@netcom.UUCP> <9157@hoptoad.uucp> Sender: wayne@dsndata.UUCP Organization: Design Data Lines: 54 In-reply-to: tim@hoptoad.uucp's message of 1 Dec 89 22:48:48 GMT In article <9157@hoptoad.uucp> tim@hoptoad.uucp (Tim Maroney) writes: > In article dopey@sun.UUCP (Can't ya tell by the name) writes: > >I would set strict standards that deal with well written programs > >(e.g. IMHO a. few if any globals, b. one routine per file, c. well > >documented, etc.). > > [ .... ] > > I share your distaste for the rule of one routine per file. Short > functions are almost always easier to read than long ones. A > medium-sized project (say, 15,000 lines) with functions averaging out > at a reasonable size (say, forty lines) would have 375 source files > using this rule. What an atrocity! > hmmm... one of the first things i usually do to code that i get off the net is break it up into one function per file. i am not that dogmatic about it, i just it because it seems to me to be easier to work with. take your example of a project with 15,000 lines of C code. the two extremes are one file of 15,000 lines, or 375 files with around 40 lines per file. if given only the choice between these two extremes, i would definitely pick the latter. the compile time alone will kill you if you choose just one file. in practice i usually do not go to the extreme of always just one function per file, but i rarely let any given file go over 1000 lines. i only put functions in the same file if they are closely related. if the directory gets too many files, i break the directory up into sub directories. maybe some of the reason why i find it easier to work with lots of files is that i use emacs and it is very easy to have several files loaded at the same time. when i am looking at the code it is very easy to see what another function does by doing a "Ctl-x 4 f function_name.c" and then i can see both the calling function and the called function on the screen at the same time. going to the beginning or end of a function is easy as going to the beginning or the end of a file. searching and replacing text doesnt spill over into other functions. yes, you can do these things when everything is in one file too, but to me it seems simpler and easier to have one function per file. another reason why i may lean toward one function per file is that i am used to working on large projects (>100k lines) and when you get to that size, you almost _have_ to work with lots of files, directories of directories, libraries and such. oh well... to each there own... -wayne Brought to you by Super Global Mega Corp .com