flocks.dev

How I do my computing

On code indentation

I've always considered debates about code indentation silly and pointless. For me it was only a matter of taste. I had no strong opinion on it and would adapt to the project convention I'm working on. And for personal project, I would simply rely on default style convention of tools such as prettier, that automatically formats code.

But recently, I stumbled upon a code formating convention in some C projects where the definition of function would follow this pattern

type_of_return
name_of_function(args....)

So you would have first the return type, and then on a newline, the name of the function.

At first, I didn't really like it. No strong argument, only aesthetics.

But then I realized how powerful it is. Now without any LSP, or any fancy IDE features, you can quickly find any function declaration by assuming it will be on a line starting with the function name.

So it's just a matter of doing:

grep -rn ^function_name

Now, I wonder if there is any other formatting conventions that favor code discovery with simple and ubiquitous tools like grep!