Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Jan 2016 10:14:23 -0800
From:      Luigi Rizzo <rizzo@iet.unipi.it>
To:        gljennjohn@gmail.com
Cc:        Konstantin Belousov <kostikbel@gmail.com>, Boris Astardzhiev <boris.astardzhiev@gmail.com>,  threads@freebsd.org, "freebsd-net@freebsd.org" <net@freebsd.org>
Subject:   Re: Does FreeBSD have sendmmsg or recvmmsg system calls?
Message-ID:  <CA%2BhQ2%2BhZZSfyRaUUOPGipnFZ560zedq7eGtTwGCQOijh_2Zrug@mail.gmail.com>
In-Reply-To: <20160126182543.64050678@ernst.home>
References:  <20160118140811.GW3942@kib.kiev.ua> <CAP=KkTzLCOnJVqt5F3ZuuZUiwkmWcne2Ynpi6-daE2jTzSBtfw@mail.gmail.com> <20160120073154.GB3942@kib.kiev.ua> <CAP=KkTx3dAUuSBrJiwNAAe%2BhHSG4j5Qp7sAcgtOgmVi8a12k1A@mail.gmail.com> <20160121093509.GK3942@kib.kiev.ua> <20160121233040.E1864@besplex.bde.org> <CAP=KkTw=ML=oPo2OgFfmor_nsL3om6HvmTQjKNMrOiU_dmWc2g@mail.gmail.com> <20160124050634.GS3942@kib.kiev.ua> <20160124100747.551f8e3f@ernst.home> <CAP=KkTyHG9Rb%2BnrDC1TDxzjUQFca9NkVp8Suo1c_-C00RUtkuQ@mail.gmail.com> <20160126134005.GD3942@kib.kiev.ua> <CA%2BhQ2%2BivWYJMDUwzdZGW88-mWzSVfPzX212sOFVmxxN0hpZ%2BQQ@mail.gmail.com> <20160126182543.64050678@ernst.home>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jan 26, 2016 at 9:25 AM, Gary Jennejohn <gljennjohn@gmail.com> wrote:
> On Tue, 26 Jan 2016 09:06:39 -0800
> Luigi Rizzo <rizzo@iet.unipi.it> wrote:
>
>> On Tue, Jan 26, 2016 at 5:40 AM, Konstantin Belousov
>> <kostikbel@gmail.com> wrote:
>> > On Mon, Jan 25, 2016 at 11:22:13AM +0200, Boris Astardzhiev wrote:
>> >> +ssize_t
>> >> +recvmmsg(int s, struct mmsghdr *__restrict msgvec, size_t vlen, int flags,
>> >> +    const struct timespec *__restrict timeout)
>> >> +{
>> >> +     size_t i, rcvd;
>> >> +     ssize_t ret;
>> >> +
>> >> +     if (timeout != NULL) {
>> >> +             fd_set fds;
>> >> +             int res;
>> > Please move all local definitions to the beginning of the function.
>>
>> This style recommendation was from 30 years ago and is
>> bad programming practice, as it tends to complicate analysis
>> for the human and increase the chance of improper usage of
>> variables.
>>
>> We should move away from this for new code.
>>
>
> Really?  I personally find having all variables grouped together
> much easier to understand.  Stumbling across declarations in the
> middle of the code in a for-loop, for example, takes me by surprise.
>
> I also greatly dislike initializing variables in their declarations.
>
> Maybe I'm just old fashioned since I have been writing C-code for
> more than 30 years.

(sorry for the digression)

I am in the same ballpark in terms of coding age,
but systems have become a lot more
complex in that time window, code size generally exploded,
and compilers are smarter so they do not need hints from the
programmer on when to do initializations, or stack reuse or
register allocations.

I find that reducing the scope of variables helps a lot
understanding third party code (e.g. where information belongs to)
and reduces the chance of misuse (such as, leaking information
from the body of a loop).

About initializers in declarations, I think the rule should be
"use good judgement and privilege readability".

E.g., do postpone initialization if the first use is 20 lines down,
so that it is clear what the value is by the time you use
the variable; or when there is some complex condition to check,
as writing it as a conditional expression may be ugly and
cause code duplication and lead to poor error handling.

But when the first use is close to the declaration, splitting
the initialization is just unnecessary source bloat.

cheers
luigi

>
> --
> Gary Jennejohn



-- 
-----------------------------------------+-------------------------------
 Prof. Luigi RIZZO, rizzo@iet.unipi.it  . Dip. di Ing. dell'Informazione
 http://www.iet.unipi.it/~luigi/        . Universita` di Pisa
 TEL      +39-050-2217533               . via Diotisalvi 2
 Mobile   +39-338-6809875               . 56122 PISA (Italy)
-----------------------------------------+-------------------------------



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2BhQ2%2BhZZSfyRaUUOPGipnFZ560zedq7eGtTwGCQOijh_2Zrug>