[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aW25lLbuIQGCr0FHtnqiM-UB-VYfk-BaLhhwq3Ur9ONgrXyxHspO_JKXCIgAeI0IBhW7hqZwTdACzd9a1b8A9MIBDrn12ymzMGYjbeqcSYE=@emersion.fr>
Date: Mon, 14 Feb 2022 10:52:13 +0000
From: Simon Ser <contact@...rsion.fr>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Thomas Zimmermann <tzimmermann@...e.de>,
linux-fbdev@...r.kernel.org, David Airlie <airlied@...ux.ie>,
Daniel Vetter <daniel.vetter@...ll.ch>,
Javier Martinez Canillas <javierm@...hat.com>,
linux-kernel@...r.kernel.org,
Noralf Trønnes <noralf@...nnes.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
dri-devel@...ts.freedesktop.org, Sam Ravnborg <sam@...nborg.org>,
Maxime Ripard <maxime@...no.tech>
Subject: Re: [PATCH v4 1/6] drm/format-helper: Add drm_fb_xrgb8888_to_gray8_line()
On Monday, February 14th, 2022 at 11:38, Andy Shevchenko <andriy.shevchenko@...ux.intel.com> wrote:
> > > > IMO *always* prefer a for loop over while or do-while.
> > > >
> > > > The for (i = 0; i < N; i++) is such a strong paradigm in C. You
> > > > instantly know how many times you're going to loop, at a glance. Not so
> > > > with with the alternatives, which should be used sparingly.
> > >
> > > while () {} _is_ a paradigm, for-loop is syntax sugar on top of it.
> >
> > Naw, that's not true.
>
> In the section 3.5 "Loops - While and For" in "The C Programming
> Language" 2nd by K&R, the authors said:
>
> The for statement ... is equivalent to ... while..."
>
> They said that for is equivalent to while, and not otherwise.
>
> Also, syntax sugar by definition declares something that can be written as
> a single line of code, which usually is done using more (not always).
arr[i] is syntaxic sugar for *(arr + i), yet we keep writing the former,
because it's way more readable. The same goes for the for vs. while loops.
It may be obvious for you because you're a C guru, but to me it just obfuscates
the code. Too many C projects end up becoming completely unreadable because of
patterns like these.
Idiomatic C code isn't written by doing pointless micro-optimizations.
Powered by blists - more mailing lists