Re: #include recommendation
- From: Giacomo Catenazzi <cate@xxxxxxxxxx>
- Date: Thu, 23 Apr 2009 10:06:15 +0200
kid joe wrote:
Hi,
In the next release of the C standard, Id like to see an extension of the
#include directive to allow multiple files to be included on a single line.
Many files start with a large number of #include lines like
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <platform_specific1.h>
#include <platform_specific2.h>
and often many more than this!
This shouldnt be the first thing you see when you open a C file!
Why not allow
#include <stdio.h>,<stdlib.h>,<string.h>,<platform_specific1.h>,<platform_specific2.h>
or
#include <stdio.h><stdlib.h><string.h><platform_specific1.h><platform_specific2.h>
for more flexibility in how the C source file is laid out?
No, I think the old version is a lot more readable and desirable.
The header files are documentation!
When I read a file, I should understand what it is the meaning of the
different identifiers. So I recommend programmers to explicitly
write all header files which provide the used interface (API).
You may wonder how many files forgot to include needed headers
(which normally I see when compiling with other architectures
and/or new libraries). Namespace is not unique, so
with a catch all #include "myproject.h" I don't see if foobar is
a home made of if it is the common foobar() found in the library
libfoo.
So, to your proposal:
Check the quoted text and tell me if you included <stdargs.h>.
With the old methods the eyes tend to parse quicker the headers;
in your proposal the eyes should parse horizontally (and
vertically if there are much more headers) and you see that it
take a lot more time (relative to old methods).
BTW python allow multiple import:
import foo, bar, han, spam
but for the coding style for standard module (and good programs)
mandate one lime per module.
ciao
cate
.
- References:
- #include recommendation
- From: kid joe
- #include recommendation
- Prev by Date: Re: #include recommendation
- Next by Date: Re: #include recommendation
- Previous by thread: Re: #include recommendation
- Index(es):
Relevant Pages
|