Sujet : Re: Which code style do you prefer the most?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 25. Feb 2025, 22:51:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vple07$26nr0$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 25.02.2025 17:17, Scott Lurndal wrote:
Ar Rakin <rakinar2@onesoftnet.eu.org> writes:
On 2/25/25 9:23 PM, David LaRue wrote:
I used a style similar to this in school. Before that I used much the same.
As for existing code bases I prefer to keep their style and add comments
accordingly. That generally goes for any language.
>
Agreed. For existing projects, the code style should be preserved.
>
Popularity of a style shouldn't be a goal. It should be consistantly
readable and documented. We must write for ourselves as well as our future
self and others.
>
This is true. I just wanted to know which style most people seem to prefer.
>
Thanks for your response!
I prefer the AT&T style (which you call GNU style, but which actually
predates Stallman).
The vi(1) editor has several commands that are designed to support
the AT*T (or more properly, Bell Labs) style, such as the '[['
and ']]' commands.
For non-Vi/Vim users it may be useful to point out that there's so
many navigation commands for all sorts of syntactical constructs,
whether editing programming languages, prose text, or data, that
you can choose your preferred way - and there are typically more
ways than just one - to navigate to any entity.
Starting a function definition with
the function name in column 1 enables the use of the VI
/^main
command to easily move the cursor to the start of a named function.
Yeah, I know that "advantage" from some projects; I never liked the
function return type to be on a separate line, though. (And I never
felt a need for that search in the first place. - Occasionally (but
rarely) I worked with Vi-supported tags. Mileages vary, of course.)
I'm fine with just searching the function name and typing 'n' or 'N'
to reach other places. - With Vim, BTW, there's the nice command to
"jump to definition" (with 'gD'); and this function is independent
of whether the name is (without spaces) left aligned in column 1 or
somewhere else. So I can just search '/' without '^' and optionally
'gD' in case I've not landed in the definition already. That command
also works with items other than function names, e.g. with variable
definitions or function parameters that I also don't want to have
separated from its type [just to serve the editor].
(Disclaimer: I've used this feature only in C and C++ so I can't tell
suitability for other common languages. But see the note above about
the many powerful language-agnostic positioning options in Vi/Vim.)
Generally I prefer to not have the editor impose the "rules" for
source code formatting in any language. (Again, YMMV.)
Janis