Procnames Start Lines. But Why?

By Artyom Bologov Soft beige thumbnail with green text split over multiple lines. First line says 'void', Second says 'procname()', and the third is '{}'. This is mimicking a style of putting C procedure/function names on their own lines. 'aartaka.me' and 'Artyom Bologov' are added in the corners, also split over multiple lines.

Looking at some old Open Source C codebase (everyone does that, right?) one can notice a weird convention. Procedure names and return types are split on two separate lines:

char *
hello(char *you)
{
// ...
}
Weird convention, right?

Pros of this style are

  1. It's easy to find procedure definition with grep: just search for /^procname/.
  2. It saves some space for argument list. Especially when the return type includes qualifiers like static and const. Or something like struct long_struct_name *
  3. K&R did that. That's the reason someone on StackOverflow provided, but it's wrong. "The C Programming Language" had return type on the same line as procedure name. But! It also had main() starting the line, because it was possible to omit the "obvious" int return type. That might be where the confusion started from.

Another reason, provided by Žarko Asen over email:

return type, procedure qualifications, template characteristics go on the line above the procedure's name its easier to distinguish the procedure name from the code when it resides in the beginning of a new line
Highlighting the visual recognition this style gives (text preserved verbatim)

Relatively obvious cons are:

  1. It splits return type and name on separate lines. Looking up full prototype of the procedure is harder—one needs to open the file and look at the line above the name.
  2. It likely doesn't match the aesthetic preferences of most programmers and languages.

What I'm about to describe is a well-established synthesis of the two conventions: split and joined. This synthesis is:

This way, procedure prototype is easy to search for (look for .h files), while the actual procedure source is equally easy to locate (/^procname/).

Not forcing that on anyone, of course. But... does it make any sense now?

Leave feedback! (via email)