LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Axel Lin <axel.lin@ingics.com>
To: Olliver Schinagl <oliver@schinagl.nl>
Cc: Mark Brown <broonie@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	Priit Laes <plaes@plaes.org>, Liam Girdwood <lgirdwood@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] regulator: axp20x: Get rid of AXP20X_xxx_START/END/STEPS defines
Date: Sat, 23 Mar 2019 21:41:20 +0800	[thread overview]
Message-ID: <CAFRkauA-NB=FBjxoXcnytsGE2A7-MQ6ipeA3s1LDTyjXYr9mng@mail.gmail.com> (raw)
In-Reply-To: <15e97e28-0008-cda4-176d-a3feb9ad4e8a@schinagl.nl>

Olliver Schinagl <oliver@schinagl.nl> 於 2019年2月24日 週日 上午4:37寫道:
>
> On 23-02-2019 13:54, Axel Lin wrote:
> >> I will not disagree that it may be extra work to look up the define
> >> (especially if there is no tool tip or split view in the editor) but
> >> reading the whole lot of code, with only the magic values, you still
> >> have to look up the meaning of each magic value, have to guess which one
> >> has the same meaning etc.
> >>
> >> Further more, I do believe far more people reading will find an define
> >> to be more descriptive to read. Whoever needs to actually go in and
> >> fix/change things.
> > I disagree.
> > The reason I sent this patch is because these defines reduce readability.
> > I do care about readability, but in this case these defines make
> > readability worsen.
> Well this really is up to personal preference isn't it? As personally
> find it much nicer to read without the magics :) If I actually have to
> modify or go into the actual meaning, then yes, I will have to dig into
> it a little deeper. But the overal code to a passer by, is still in my
> opinion much more readable.

It's not about personal preference.
The thing is your changes added unnecessary complexity as I pointed out.

> >
> > At the context of REGULATOR_LINEAR_RANGE, each fields has well known meaning.
> > When I look at the table with values (I don't care if it's hex or decimal),
> > it tells everything I need to know.
> > I can easily check if any linear ranger cover other ranges.
> > I can easily check if any gap between linar ranges, (probably due to
> > reserved bits).
> > I can easily count the number of entries in each range.
> > I can easily calculate the min/max voltage of each range and double
> > check with datasheet.
> > i.e. If there are something wrong, it's eash to detect it.
>
> In any case, you seem like a smart person that reads and writes hex and
> bits often enough. This is not true for everyone. I can just as easily
> reverse your arguments of course, for example, 'each field has a well
> known meaning' ... to whom? People that use these things daily, sure.
> People who just need to double check something or modify something, not
> so much. They have to look up the MACRO, the struct its in, compare it
> to others, so as you can see, what is natural for you, is not true for
> everyone. :)

To judge the readability you still have to understand the meaning of
fields of a REGULATOR_LINEAR_RANGE no matter using DEFINES or constant values.
Once you understand the fields of REGULATOR_LINEAR_RANGE, you will know
there is no readability issue with constant values in the table.

>
> Also, the general consensus is still to avoid magic values, and to stay
> consistent with the rest and not make expceptions, it makes sense to
> have defines instead of magic values.
>
> >
> > When you change the values to DEFINES, I have to check the value of
> > each define *one-by-one*.
> > There is no benefit in this case.
> >
> > I don't mean adding DEFINES is wrong. Just in this case it does not
> > help and actually has downside.
> > I only remove AXP20X_xxx_START/END/STEPS defines, not all defines.
> >
> > BTW, just show you an example (from drivers/regulator/88pm8607.c)
> > I don't think change all below values to DEFINES help in readability.
> > static const unsigned int BUCK1_table[] = {
> >          725000,  750000,  775000,  800000,  825000,  850000,  875000,  900000,
> >          925000,  950000,  975000, 1000000, 1025000, 1050000, 1075000, 1100000,
> >         1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000,
> >         1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000,
> >               0,   25000,   50000,   75000,  100000,  125000,  150000,  175000,
> >          200000,  225000,  250000,  275000,  300000,  325000,  350000,  375000,
> >          400000,  425000,  450000,  475000,  500000,  525000,  550000,  575000,
> >          600000,  625000,  650000,  675000,  700000,  725000,  750000,  775000,
> > };
>
> Personally, I think this is a horrible table :p sure, I can guess that
> these are voltages (based on the fact that it's a regulator table and I
> am a little familiar here), but without knowing the context, I see a
> bunch of voltages, from 0,725 to 1,5 appearantly in equal steps, but the
> first question I ask, is the step always .25? I can't see, i'd have to
> go over each value and compare them all. Quite cumbersome ;)
>
> And then, there is a nother row, which starts after the 1.5 but at 0 and
> goes to 7.75. Are these two the same regulator? Why the overlap?

Your guessing is wrong. This is *not* a linear range table.
To judge the readability you had better really read the code first.
Macro's and defines cannot help you regarding this.

Axel

      parent reply	other threads:[~2019-03-23 13:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20 16:50 Axel Lin
2019-02-20 21:38 ` Olliver Schinagl
2019-02-21  0:22   ` Axel Lin
2019-02-21  9:42     ` Mark Brown
2019-02-23  7:55       ` Olliver Schinagl
2019-02-23 12:54         ` Axel Lin
2019-02-23 20:37           ` Olliver Schinagl
2019-02-25 17:25             ` Mark Brown
2019-02-27 19:41               ` Olliver Schinagl
2019-02-27 20:05                 ` Mark Brown
2019-02-27 20:26                   ` Olliver Schinagl
2019-03-23 13:41             ` Axel Lin [this message]

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='CAFRkauA-NB=FBjxoXcnytsGE2A7-MQ6ipeA3s1LDTyjXYr9mng@mail.gmail.com' \
    --to=axel.lin@ingics.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver@schinagl.nl \
    --cc=plaes@plaes.org \
    --cc=wens@csie.org \
    --subject='Re: [PATCH] regulator: axp20x: Get rid of AXP20X_xxx_START/END/STEPS defines' \
    /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

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 NNTP newsgroup(s).