Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>, Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 2/5] [gdb] Make addrmap_mutable::insert_empty return bool
Date: Fri, 29 Aug 2025 10:28:24 +0200	[thread overview]
Message-ID: <de97e4d7-ff5a-4b43-a545-98d60f605dbd@suse.de> (raw)
In-Reply-To: <87frdbj7ws.fsf@tromey.com>

On 8/29/25 02:20, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
> 
> Tom> +      if (addrmap_node_value (n))
> Tom> +    {
> Tom> +      /* Already mapped.  */
> Tom> +      full_range = false;
> Tom> +      continue;
> Tom> +    }
> Tom> +
> Tom> +      addrmap_node_set_value (n, obj);
> 
>>> FWIW, I still think that they way I wrote is is much better.  My
>>> opinion is based on this coding standard rule (
>>> https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
>>> ).
> 
> I don't think we should use LLVM's coding standards. 

Hi Tom,

I realize I'm probably not going to convince you, so all I'm trying to 
do here is to better make my argument, since I have not done a good job 
sofar.

I'm not advocating that we should use LLVM's coding standards, regardless.

I'm saying that we could use some of them if they make sense and don't 
conflict with the existing coding standard.

Reading the rule was a light-bulb moment for me, and has shaped my 
opinion on how to write code.

Agreed, it can be argued that the rule doesn't apply here because the 
if-else branches are too small.

It also says "Aim to reduce indentation where possible when it doesn’t 
make it more difficult to understand the code".

Of course it's highly debatable how to fill this in.

For me, it makes sense to look at the impact of the branches.

To illustrate my point, I think it makes sense to do:
...
if (...)
   a = b;
else
   c = d;
...
but not
...
if (...)
   a = b;
else
   exec ("rm -Rf /")
...

In the latter case, I'd rather write:
...
if (!...)
   {
      a = b;
      continue;
   }

   exec ("rm -Rf /");
...
to have the most impactful statement stand out both by less indentation, 
and by having it standalone rather than as part of an if/else.

And I feel the same applies to:
...
if (...)
   { /* Don't do something and make a note of it.  */ }
else
   { /* Do something. */ }
...

> Particularly so
> now that I've worked on LLVM this last year.
> 
> Simon> I also like early returns and early continue in loops.  It tells me: you
> Simon> don't need to think about that case for the rest of the function loop.
> 
> In this particular case the two branches are single lines.

FWIW, one branch is one line, the other 4 lines:
...
       if (addrmap_node_value (n))
         {
           /* Already mapped.  */
           full_range = false;
         }
       else
         addrmap_node_set_value (n, obj);
...

Thanks,
- Tom

> Using a continue here seems more confusing for that reason -- it's just
> more to process here.
> 
> I get it for longer loops, at least situationally.
> 
> Tom


  reply	other threads:[~2025-08-29  8:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 13:31 [PATCH v2 0/5] [gdb/symtab] Handle invalid .gdb_index better Tom de Vries
2025-08-21 13:31 ` [PATCH v2 1/5] [gdb/symtab] Bail out of create_addrmap_from_gdb_index on error Tom de Vries
2025-08-21 13:31 ` [PATCH v2 2/5] [gdb] Make addrmap_mutable::insert_empty return bool Tom de Vries
2025-08-22 14:54   ` Simon Marchi
2025-08-22 18:51   ` Tom Tromey
2025-08-23  4:20     ` Tom de Vries
2025-08-23 17:53       ` Simon Marchi
2025-08-29  0:20         ` Tom Tromey
2025-08-29  8:28           ` Tom de Vries [this message]
2025-08-21 13:31 ` [PATCH v2 3/5] [gdb/symtab] Detect overlapping ranges in create_addrmap_from_gdb_index Tom de Vries
2025-08-22 14:57   ` Simon Marchi
2025-08-21 13:31 ` [PATCH v2 4/5] [gdb/symtab] Improve invalid range check " Tom de Vries
2025-08-22 14:56   ` Tom de Vries
2025-08-22 15:17   ` Simon Marchi
2025-08-22 18:53   ` Tom Tromey
2025-08-23  4:33     ` Tom de Vries
2025-08-21 13:31 ` [PATCH v2 5/5] [gdb/symtab] Turn complaints in create_addrmap_from_gdb_index into warnings Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=de97e4d7-ff5a-4b43-a545-98d60f605dbd@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox