Date: Fri, 1 Jun 2012 13:16:58 -0400 From: John Baldwin <jhb@freebsd.org> To: Eitan Adler <eadler@freebsd.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Bruce Evans <brde@optusnet.com.au> Subject: Re: svn commit: r236377 - head/sys/dev/vxge/vxgehal Message-ID: <201206011316.58330.jhb@freebsd.org> In-Reply-To: <CAF6rxgnTFVBNOewiPXNvHyt3YamWsa6YZDPFtM4-uumUD6Eqdg@mail.gmail.com> References: <201206010423.q514NKtf083043@svn.freebsd.org> <201206011024.49122.jhb@freebsd.org> <CAF6rxgnTFVBNOewiPXNvHyt3YamWsa6YZDPFtM4-uumUD6Eqdg@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Friday, June 01, 2012 12:39:48 pm Eitan Adler wrote: > On 1 June 2012 07:24, John Baldwin <jhb@freebsd.org> wrote: > > This is why I personally loathe assignment side effects in boolean expressions > > for control flow. I tend to write this sort of thing instead as: > > > > channel->dtr_arr[dtr_index].dtr = dtrh; > > if (dtrh != NULL) { > > Same here. I was told to use the assignment is style(9) by multiple > people though. If it really is, I wish it would change. style(9) doesn't make a clear statement either way, but it has contradicting examples. First: while ((ch = getopt(argc, argv, "abNn:")) != -1) (and this one I use all the time myself as that is the common idiom for getopt()) Second: error = function(a1, a2); if (error != 0) exit(error); Also, style(9) tends to frown on assignments that are side-effects in other places, for example: Be careful to not obfuscate the code by initializing variables in the declarations. Use this feature only thoughtfully. DO NOT use function calls in initializers. struct foo one, *two; double three; int *four, five; char *six, seven, eight, nine, ten, eleven, twelve; four = myfunction(); Some newer changes added at the end do use assignment side-effects while demonstrating other rules (the !p example and err(3) and warn(3) examples, this last I find particularly obfuscated and painful to read). Note that I do not consider this to be an assignment side effect: if (ioctl(...) < 0) err(1, "ioctl"); That is, I don't write that out as: i = ioctl(...); if (i < 0) However, I do split it out if the return value is used for more than error checking, e.g.: fd = open(...); if (fd < 0) err(1, "open"); -- John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206011316.58330.jhb>