Reference: style(9)
The style(9) guide describes style for kernel source files. It is also applied to non-kernel code in base.
Here's an example where I think the advice of style(9) is obsolete.
There's the DRY (don't repeat yourself) principle which - according to wikipedia - has been around about 20 years.
en.wikipedia.org
The idea is to avoid multiple parallel definitions (or implementations) of the same thing.
With regards to functions in C, style(9) advises this:
This has been applied not just to external functions but to local, static file scope functions.
Since bectl is a recent addition to base, I'll use it as an example.
Here are the local file scope function prototypes for bectl.c:
All of these commands are implemented further down in the same source file. The implementation also declares the function name, parameters and return type. This means the prototypes are unnecessary. They don't help the compiler and don't make the code more readable. It's just a bit of text duplicated twice in the same file - all because style(9) says so.
This repetition is a nuisance - a small one - but still a nuisance.
Edit:
For userland code, place main() at the end of the source file (just as was done in the bectl example above).
The style(9) guide describes style for kernel source files. It is also applied to non-kernel code in base.
Here's an example where I think the advice of style(9) is obsolete.
There's the DRY (don't repeat yourself) principle which - according to wikipedia - has been around about 20 years.
Don't repeat yourself - Wikipedia
The idea is to avoid multiple parallel definitions (or implementations) of the same thing.
With regards to functions in C, style(9) advises this:
Code:
All functions are prototyped somewhere.
This has been applied not just to external functions but to local, static file scope functions.
Since bectl is a recent addition to base, I'll use it as an example.
Here are the local file scope function prototypes for bectl.c:
Code:
static int bectl_cmd_activate(int argc, char *argv[]);
static int bectl_cmd_check(int argc, char *argv[]);
static int bectl_cmd_create(int argc, char *argv[]);
static int bectl_cmd_destroy(int argc, char *argv[]);
static int bectl_cmd_export(int argc, char *argv[]);
static int bectl_cmd_import(int argc, char *argv[]);
#if SOON
static int bectl_cmd_add(int argc, char *argv[]);
#endif
static int bectl_cmd_mount(int argc, char *argv[]);
static int bectl_cmd_rename(int argc, char *argv[]);
static int bectl_cmd_unmount(int argc, char *argv[]);
All of these commands are implemented further down in the same source file. The implementation also declares the function name, parameters and return type. This means the prototypes are unnecessary. They don't help the compiler and don't make the code more readable. It's just a bit of text duplicated twice in the same file - all because style(9) says so.
This repetition is a nuisance - a small one - but still a nuisance.
Edit:
For userland code, place main() at the end of the source file (just as was done in the bectl example above).