public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Detlev Zundel <dzu@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/5] Tegra2: Add bitfield access macros
Date: Wed, 08 Jun 2011 09:37:42 +0200	[thread overview]
Message-ID: <m2oc286aex.fsf@ohwell.denx.de> (raw)
In-Reply-To: <20110607200042.88FE31B993AE@gemini.denx.de> (Wolfgang Denk's message of "Tue, 07 Jun 2011 22:00:42 +0200")

Hi,

> Dear Simon Glass,
>
> In message <BANLkTimN4NVD43B2Le7_ci9Picjd6pmuXA@mail.gmail.com> you wrote:
>> 
>> >        clrsetbits_le32(&my_device->ctrl, FIELD_MASK, FIELD_VAL(6));
>>
>> We now have a computed mask which is good, thank you.
>>
>> But the FIELD is specified twice in the same statement. Can we
>> therefore please take this a step further and write something like
>> this?
>>
>> clrsetfield_le32(&my_device->ctrl, FIELD, 6);
>
> I think I should provide a little moe explanation why I dislike your
> suggestion.  With "FOO_MASK, FOO_VAL()" it is obvious to the
> reader that we are dealing ith some (bit) mask and some value, and it
> is also trivial to locate the respective definitions of these macros,
> because you know their exact names.
>
> With "FOO, 6" you know nothing.  Searching for "FOO" in the source
> code and header files will probably return a ton of unrelated
> references, and you will have to read (and understand) the definition
> of the bitfield macro and follow it's preprocessor trickery with
> combining some magic name parts until you finally know what to look
> for.
>
> You consider this macro helpful, I consider it obscure, and that's why
> I don't want to have it.

For what its worth, I also consider the magic under the hood to be too
much.  It may look clever, but it actually makes the code harder to read
without knowing the definition of the macrot itself.  Having to know the
_definition_ of a macro to understand how it works violates the usual
paradigm of having a fixed API/contract independent of the
implementation.

Cheers
  Detlev

-- 
It's like manually inflatable airbags -- people will never
think to use it in time to actually get any help from it.
             -- Miles Bader in <20030607122005.GA1086@gnu.org>
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de

  reply	other threads:[~2011-06-08  7:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-02  0:14 [U-Boot] [PATCH 0/5] Add bitfields, clock and pinmux functions to simplify code Simon Glass
2011-06-02  0:14 ` [U-Boot] [PATCH 1/5] Tegra2: Add bitfield access macros Simon Glass
2011-06-06 18:50   ` Wolfgang Denk
2011-06-07  0:38     ` Simon Glass
2011-06-07  6:28       ` Wolfgang Denk
2011-06-07  6:46         ` Simon Glass
2011-06-07 10:06           ` Wolfgang Denk
2011-06-07 15:06             ` Mike Frysinger
2011-06-07 15:12             ` Simon Glass
2011-06-07 15:51               ` Wolfgang Denk
2011-06-07 20:00               ` Wolfgang Denk
2011-06-08  7:37                 ` Detlev Zundel [this message]
2011-06-08 16:10                 ` Simon Glass
2011-06-08 19:21                   ` Wolfgang Denk
2011-06-08 19:48                     ` Simon Glass
2011-06-08 20:46                       ` Wolfgang Denk
2011-06-02  0:14 ` [U-Boot] [PATCH 2/5] Tegra2: Add microsecond timer functions Simon Glass
2011-06-02  0:14 ` [U-Boot] [PATCH 3/5] Tegra2: Add more clock support Simon Glass
2011-06-02  0:14 ` [U-Boot] [PATCH 4/5] Tegra2: add additional pin multiplexing features Simon Glass
2011-06-02  0:14 ` [U-Boot] [PATCH 5/5] Tegra2: Use clock and pinmux functions to simplify code Simon Glass
2011-06-06 18:59 ` [U-Boot] [PATCH 0/5] Add bitfields, " Wolfgang Denk

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=m2oc286aex.fsf@ohwell.denx.de \
    --to=dzu@denx.de \
    --cc=u-boot@lists.denx.de \
    /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