public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Evan Lloyd <Evan.Lloyd@arm.com>
To: "ryan.harkin@linaro.org" <ryan.harkin@linaro.org>
Cc: "ard.biesheuvel@linaro.org" <ard.biesheuvel@linaro.org>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	"edk2-devel@ml01.01.org" <edk2-devel@ml01.01.org>
Subject: Re: [PATCH 4/4] ArmPkg:Provide GetTriggerType/SetTriggerType functions
Date: Fri, 17 Feb 2017 12:06:30 +0000	[thread overview]
Message-ID: <AM5PR0801MB17621F84D63C3A1FFD9D78FA8B5D0@AM5PR0801MB1762.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <CAD0U-hKzY11cKHXj8AfUvfaYQ+6YzqWrmymWacAW77DwZvwfOA@mail.gmail.com>

Hi Ryan.

From: Ryan Harkin [mailto:ryan.harkin@linaro.org]
Sent: 16 February 2017 20:42
To: Evan Lloyd
Cc: ard.biesheuvel@linaro.org; Leif Lindholm; edk2-devel@ml01.01.org
Subject: RE: [PATCH 4/4] ArmPkg:Provide GetTriggerType/SetTriggerType functions


On 16 Feb 2017 20:27, "Evan Lloyd" <Evan.Lloyd@arm.com<mailto:Evan.Lloyd@arm.com>> wrote:
>
> Hi Leif.
> We accept all the comments except that about ternaries.
> Response inline.
>
> >> +
> >> +  *TriggerType = (MmioBitFieldRead32 (RegAddress, BitNumber,
> >BitNumber) == 0)
> >> +                 ?  EFI_HARDWARE_INTERRUPT2_TRIGGER_LEVEL_HIGH
> >> +                 :  EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING;
> >> +
> >
> >Ternaries are excellent when they increase code readability.
> >I am not convinced that is the case here.
> >
> >Consider:
> >
> >  if (MmioBitFieldRead32 (RegAddress, BitNumber, BitNumber) == 0) {
> >    *TriggerType = EFI_HARDWARE_INTERRUPT2_TRIGGER_LEVEL_HIGH;
> >  } else {
> >    *TriggerType = EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING;
> >  }
> >
> >?
> >
> >The versions generate identical code with gcc at -O1 and above.
>
> Firstly, I'm not sure why 5 lines of code is more readable than 3.
> My main point though  is that the ternary expression clearly indicates that all we are doing is setting *TriggerType.
> The multiple assignment "if" requires examination to determine that there is nothing else going on. (Because otherwise why wouldn't you use a ternary?)
> I'm about to submit v2 without this, in the hope that I've made the case.
>

I find your argument unconvincing and would prefer an "if" clause.

That is fine,  lots of people have irrational prejudices.  ;-)

Do you have a counter argument though?

Leif points out that “Ternaries are excellent when they increase code readability.”

The debate would thus seem to be a subjective assessment of “readability”.

What criteria should we use to identify when a ternary is more readable, and when not?

And how do we ensure consistency across all EDK2 maintainers?

Evan



…



IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

  reply	other threads:[~2017-02-17 12:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09 19:26 [PATCH 0/4] HardwareInterrupt2 protocol evan.lloyd
2017-02-09 19:26 ` [PATCH 1/4] EmbeddedPkg: introduce " evan.lloyd
2017-02-13 12:26   ` Leif Lindholm
2017-02-09 19:26 ` [PATCH 2/4] ArmPkg/ArmGicDxe: expose " evan.lloyd
2017-02-13 12:21   ` Leif Lindholm
2017-02-13 12:26     ` Ard Biesheuvel
2017-02-09 19:26 ` [PATCH 3/4] ArmPkg/GenericWatchdogDxe: Set Watchdog interrupt type evan.lloyd
2017-02-13 12:30   ` Leif Lindholm
2017-02-09 19:26 ` [PATCH 4/4] ArmPkg:Provide GetTriggerType/SetTriggerType functions evan.lloyd
2017-02-13 12:15   ` Leif Lindholm
2017-02-16 20:27     ` Evan Lloyd
2017-02-16 20:42       ` Ryan Harkin
2017-02-17 12:06         ` Evan Lloyd [this message]
2017-02-17 12:30           ` Ryan Harkin
2017-02-17 15:08             ` Alexei Fedorov
2017-02-17 18:18               ` Ard Biesheuvel
2017-02-24 14:06           ` Leif Lindholm
2017-02-13 13:05   ` Ard Biesheuvel
2017-02-16 20:16     ` Evan Lloyd
2017-02-16 20:46       ` Ard Biesheuvel
2017-02-17 11:53         ` Evan Lloyd
2017-02-24 11:26           ` Leif Lindholm
2017-02-13 15:51 ` [PATCH 0/4] HardwareInterrupt2 protocol Evan Lloyd
2017-02-13 17:15   ` Leif Lindholm

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-list 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=AM5PR0801MB17621F84D63C3A1FFD9D78FA8B5D0@AM5PR0801MB1762.eurprd08.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /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