Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Mar 2006 11:15:06 +1030
From:      Greg 'groggy' Lehey <grog@FreeBSD.org>
To:        Dmitry Pryanishnikov <dmitry@atlantis.dp.ua>, "M. Warner Losh" <imp@bsdimp.com>, Robert Watson <rwatson@FreeBSD.org>
Cc:        freebsd-current@freebsd.org, cperciva@FreeBSD.ORG
Subject:   Re: style(9) question
Message-ID:  <20060303004506.GA13218@wantadilla.lemis.com>
In-Reply-To: <20060302171112.A77029@fledge.watson.org> <20060302.100922.130234735.imp@bsdimp.com> <20060302.100608.80501136.imp@bsdimp.com> <20060302105229.P83093@atlantis.atlantis.dp.ua> <200002110637.RAA79715@freebie.lemis.com>
References:  <4407226D.3050901@freebsd.org> <20060302171112.A77029@fledge.watson.org> <20060302105229.P83093@atlantis.atlantis.dp.ua> <20060302163633.H77029@fledge.watson.org> <4407226D.3050901@freebsd.org> <20060302.100922.130234735.imp@bsdimp.com> <20060302105229.P83093@atlantis.atlantis.dp.ua> <20060302.100608.80501136.imp@bsdimp.com> <20060302105229.P83093@atlantis.atlantis.dp.ua> <200002110637.RAA79715@freebie.lemis.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--pWyiEgJYm5f9v55/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


On Thursday,  2 March 2006 at 11:06:31 +0200, Dmitry Pryanishnikov wrote:
>
>   I apologize for asking here my question (it should belong to -questions,
> but the most developers are available here, and I just hope it won't hurt).
> What's the historical reason of the following style(9) advise:
>
> 	Values in return statements should be enclosed in parentheses.

The background is "that's the way our grandfathers did it".  I asked
dmr about this some years ago.  Here his reply:

On Friday, 11 February 2000 at  1:36:53 -0500, Dennis Ritchie wrote:
>> I've been wondering about the tradition of writing 'return
>> (expression)' instead of 'return expression' in C code.  The earliest
>> documentation I have (K&R I) suggests I use the former (page 68),
>> without specifying why, while appendix A (page 218) specifies 'return
>> expression'.
>>
>> I got hold of last1120

This is the last version of the C compiler written for the PDP 11/20,
some time in 1972.

>> and compiled and ran it against a test program, and it seems that
>> this version won't accept the syntax 'return expression': the
>> parentheses are mandatory.  Would it be fair to consider the usage
>> 'return (expression)' as an archaism?
>
> An archaism: just so.  The language and compiler ca. 1973
> did want the parens.  By the 5th edition (1975) I had realized that
> they weren't needed and the syntax was just 'return expression'.
>
> On the other hand, no one seemed to want to make use of the
> new freedom.  I glanced at v7 source (1977) and couldn't
> find any instances of non-parenthesized return values--
> I might have missed an instance, but there couldn't have
> been more than a very few. Evidently it had become wired
> into the mental syntax.
>
> This was certainly true for Brian in K&R 1 and evidently
> for me as well, since the very few examples in the appendix
> use the ().  But the grammar does indeed reflect the
> fact that they weren't required.
>
> 	Dennis

On Thursday,  2 March 2006 at 10:06:08 -0700, M. Warner Losh wrote:
>
> No.  Debates over style(9) aren't productive.

Agreed.

On Thursday,  2 March 2006 at 10:09:22 -0700, M. Warner Losh wrote:
> In message: <4407226D.3050901@freebsd.org>
>             Colin Percival <cperciva@freebsd.org> writes:
>> Robert Watson wrote:
>>> I can't really think of a good reason
>>> for return (foo) over return foo
>>
>> I'm not sure if this qualifies as a *good* reason, but
>> writing "return (foo)" is more consistent with other
>> keyword usage: "if (foo)", "for (foo)", "while (foo)",
>> "switch (foo)".
>
> Before 'void' existed, many people recommended () so that you could
> make 'return' a macro for extra debugging.  With void functions that
> have naked returns make this impossible these days...

This is actually a useful property.  Pity it's gone.

On Thursday,  2 March 2006 at 17:12:09 +0000, Robert Watson wrote:
> On Thu, 2 Mar 2006, Colin Percival wrote:
>
>> Robert Watson wrote:
>>> I can't really think of a good reason
>>> for return (foo) over return foo
>>
>> I'm not sure if this qualifies as a *good* reason, but writing "return
>> (foo)" is more consistent with other keyword usage: "if (foo)", "for
>> (foo)", "while (foo)", "switch (foo)".
>
> I also find myself doing search and replace on return values more on
> FreeBSD source than I do on other source.  I.e.:  s/return (0)/return
> (NULL)/ and that sort of thing.  I think I would be less comfortable doing
> that without the parens.

Why?  This sounds like the MySQL argument for writing:

  foo= bar;

instead of

  foo = bar;

Greg
--
See complete headers for address and phone numbers.

--pWyiEgJYm5f9v55/
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (FreeBSD)

iD8DBQFEB5GSIubykFB6QiMRAmK4AKCR2YqygL2s0D4JHY0dom+qtG7SVgCbByYV
savMs8jmFfT9rSFTBwVPmY4=
=97rn
-----END PGP SIGNATURE-----

--pWyiEgJYm5f9v55/--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060303004506.GA13218>