STYLE: better to have one-file-many-functions or many-files-holding-one-function

STYLE: better to have one-file-many-functions or many-files-holding-one-function

Post by Mike Dicks » Fri, 23 Oct 1998 04:00:00



Hi

I am confronted witha a set of c files that contain many functions,
for use in a library.  Now, as a point of programming style,
is it better to have each function in it's own file, with the file
name being the function name, or to keep it the way it is?

I'm inclined towards the former, so that, for example, replacements
 can simple be dropped in.

Comments?

Thanks

...Mike

 
 
 

STYLE: better to have one-file-many-functions or many-files-holding-one-function

Post by Andrew Giert » Fri, 23 Oct 1998 04:00:00


 Mike> Hi
 Mike> I am confronted witha a set of c files that contain many
 Mike> functions, for use in a library.  Now, as a point of
 Mike> programming style, is it better to have each function in it's
 Mike> own file, with the file name being the function name, or to
 Mike> keep it the way it is?

Depends. One consideration when building libraries is that the linker
will pull in a whole object file if it needs any symbol from it, so
functions that are logically independent should be kept in separate
files.

On the other hand, a strict one-function-per-file policy is not
necessarily a good thing either, especially if several related
functions share some private data, private functions or implementation
details that you don't want to expose.

As usual, there is no "one answer fits all" rule that works in all
circumstances.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

STYLE: better to have one-file-many-functions or many-files-holding-one-function

Post by John D. Hicki » Fri, 23 Oct 1998 04:00:00


If your library exposes a broad spectrum of unreleated functions (such
as the c library does) you want to use several translation units.

In the development phase this can be a real pain. So you might want to
create a bunch of files, say *.X, and #include them in one file, say
mylib.c. For production builds you need a rule to rename the individual
files to *.c. It can be messy.

Regards, John.

 
 
 

1. One function per file coding style

Currently, where I work we are in a big debate about coding style.
One group insists on having every function in a seperate file no
matter how small.  I'm opposed to this, thinking that a file is
a good way to group related functions, particularly for editing,
greping, etc.  I don't advocate massive files, but I think files
of a few hundred lines of code and several functions seems reasonable.

I was just wondering what other people's conventions were.

---
Ed Overly

2. TB Malibu experience--UPDATE

3. How ? One file <----> One file descriptor

4. GhostScript viewing error

5. missing include in linux/dcache.h

6. If you need AIX work done, this company is one of the better ones.

7. Troubles with Sony DAT tape

8. Nawk: can I use more than one input file in one script?

9. Lines from a file, one-by-one

10. Nawk: can I use more than one input file in one script?

11. Lines from a file, one-by-one

12. File system performance, Shortest Seek vs First Come first served