Reputation: 82
Good morning, sir,
I use VisualStudio Code to code in C language. I recently discovered the Prettier extension for C, ( and "C/C++")
I saw that I could add an automatic indentation, when I added a ";" or when I saved with Ctrl+S.
with the addition of the lines ;
"editor.formatOnSave": true,
"editor.formatOnType": true
in visual studio's settings.json file.
Now, despite the almost perfect indentation, I wanted to make some adjustments such as the fact that after an initialization of variable type int
there's not a space but a tabulation, like this;
int x;
//rather than;
int x;
as well as for the type of functions
void ft_function(int x);
//rather than ;
void ft_function(int x);
(Because I have a standard to meet, and when I save or what, all the indentation of these variable initializations no longer meets my standard)
I don't know anything about json, and I've just discovered the function so I was wondering if the geniuses in the forum know anything about it, and if so how? At least some leads ^^
I found the setting "C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, AlignConsecutiveDeclarations: true }"
It works for my variables alignement but not for the functions. Therefore, my functions got auto-indent like this:
int ft_strlen(char *str) {
int i;
i = 0;
while (str[i])
i++;
return (i);
}
I would like something like:
int ft_strlen(char *str) {
int i;
i = 0;
while (str[i])
i++;
return (i);
}
Upvotes: 2
Views: 1100
Reputation: 144520
The style you wish to implement, in use in some famous French programming schools such as Epita, Epitech and 42, is not widely implemented in programming environments. The original description, in French, is here.
Using tabs instead of spaces has fallen out of fashion because tab settings vary from one environment to another which breaks code and comment alignment, but for some reason, they are mandated by this document.
Aligning identifiers as they document is just an arbitrary constraint to teach programming students to pay great attention to detail and learn to follow local rules. At 42 for example, they run students' programs through a style checker and fail programs that break the strict presentation rules.
Among other surprising rules in effect there, programmers are taught to use while
instead of for
, which is highly questionable.
Similarly, I cannot think of a good reason to parenthesize the return value in the return
statements.
Configuring Visual Studio Code to reformat your code for these rules does not seem easy without some extra code: if you find a utility to reformat the code to meet these rules, you might be able to register it as a custom filter. Search for moulinette on github... But if you cannot find one, write it yourself, it is a good exercise and will be so useful to your fellow students. You could even patch VSC.
Upvotes: 1