public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Coding style for C++ constructs going forward
@ 2020-08-07 14:06 Luis Machado
  2020-08-07 14:56 ` Joel Brobecker
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Luis Machado @ 2020-08-07 14:06 UTC (permalink / raw)
  To: gdb, gcc Mailing List, Pedro Alves, Simon Marchi

Hi,

cc-ing the GCC mailing list, as we may want to use the same coding style 
for GDB and GCC.

Yesterday I brought this topic up on IRC. I notice we started using more 
and more the "auto" keyword. In some cases, this is actually useful and 
makes the code a bit more compact. GDB has been using those more often, 
whereas GCC, for example, isn't using those too much.

Looking at the coding standards for GCC 
(https://gcc.gnu.org/codingconventions.html), I don't see anything 
dictating best practices for "auto" use.

I guess it is a consensus that "auto" is a good fit when dealing with 
iterators, lambda's and gnarly templates (but only when the type is 
already obvious from its use).

There are other situations where "auto" may make things a little more 
cryptic when one wants to figure out the types of the variables. One 
example of this is when you have a longer function, and you use "auto" 
in a variable that lives throughout the scope of the function. This 
means you'll need to go back to its declaration and try to figure out 
what type this particular variable has.

Pedro has pointed out LLVM's coding standards for "auto", which we may 
or may not want to follow/adopt: 
https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable

It sounds like a reasonable idea to me. Thoughts?

Are there other C++ constructs people think would benefit from a more 
formal style guideline? As we move to newer C++ standards over time, it 
is more likely we will start using newer constructs, and some of those 
may make the code potentially less readable.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-08-13  8:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 14:06 Coding style for C++ constructs going forward Luis Machado
2020-08-07 14:56 ` Joel Brobecker
2020-08-07 15:48   ` Jakub Jelinek
2020-08-07 18:21 ` Jonathan Wakely
2020-08-07 19:09 ` Christian Biesinger
2020-08-11 13:55 ` Nathan Sidwell
2020-08-11 15:48   ` Jonathan Wakely
2020-08-12  2:46   ` Liu Hao
2020-08-12 18:40     ` David Blaikie
2020-08-13  6:44       ` Liu Hao
2020-08-13  8:03         ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).