[Openmcl-devel] CCL kernel coding style question
Ron Garret
ron at flownet.com
Sun May 1 13:55:26 PDT 2016
On May 1, 2016, at 12:47 PM, Pascal J. Bourguignon <pjb at informatimago.com> wrote:
> Ron Garret <ron at flownet.com> writes:
>
>> The CCL kernel C code is written in this style
>>
>> return_type
>> function_name(args…)
>> {
>> code…
>>
>> Instead of what has always seemed to me to be the much more readable
>> (and conservative of screen real estate):
>>
>> return_type function_name(args) {
>> code…
>>
>> Because I hold the CCL developers in the highest regard I thought I
>> would ask: is there a reason you chose the first style over the
>> second?
>
> Obviously you've never programmed in Pascal.
Why is that obvious? (Because in point of fact I have coded in Pascal, though not for a long time.)
> C is a loony and twisted language.
> Who puts the type first and the variable second?
>
> The place of the return type of a function obviously is AFTER the
> function signature.
No argument from me there. But that’s kind of beside the point.
> The consequence of putting types and modifiers first, is that their size
> having a high variance, the function names and parameters cannot easily
> be aligned anymore.
>
> export t1 foo(…);
> export ttttttyyyyyyppppppeeeeee22222 bar(…);
>
> or:
>
> export t1 foo(…);
> export ttttttyyyyyyppppppeeeeee22222 bar(…);
>
> both are ugly.
>
>
> Instead, in a sane programming language:
>
> function foo(…):t1;
> function bar(…):ttttttyyyyyyppppppeeeeee22222;
>
> things are nicely aligned.
>
>
> So one way to recover some sanity in C, to the cost of having to ignore
> every other line, is to put the return type on its own line.
>
>
> export t1
> foo(…);
> export ttttttyyyyyyppppppeeeeee22222
> bar(…);
Vertical alignment only helps if the things that are vertically aligned with each other are all associated with each other. If you don’t follow that rule then vertical alignment doesn’t help very much.
Also, I’m talking about .c files here, not .h files, so the function definition lines are separated by blocks of code. Seeing two function definitions close enough to each other to even tell that (let alone care if) they are vertically aligned is pretty rare in a .c file.
The .h files are all written in the more compact style where the function name and the type are on the same line. This includes things like typedef structs, which are syntactically similar to a function definition in that they consist of an initial declaration followed by a curly-brace-delimited block.
> (You may use grep -v export).
How is that supposed to help?
In fact, one of the reasons that the more compact style is useful is that you can find the definition of a function by doing:
grep function_name | grep ‘{‘
The ccl kernel style makes it much harder to find the place where a given function is defined.
rg
More information about the Openmcl-devel
mailing list