From:  Jason Orendorff <>
Date:  29 Sep 2017 03:35:51 Hong Kong Time

Re: C++ coding style rule for keeping class fields together


On Thu, Sep 28, 2017 at 2:10 AM, Lars Hansen  wrote:

> I dislike this proposal.  (a) A lot of the code I work with already have
> fields-at-the-beginning as the predominant pattern in the smaller classes
> (jit, wasm) so this would be major churn for no gain.  (b) For large
> classes this is an anti-pattern, like having all the vars at the beginning
> of a function in C; it separates the data from the functions that work on
> that data.  (c)  It brings private and public parts of the code close
> together, and separates public data from public methods.

Objections (a) and (b) make sense to me, so let's make the rule "For
reasonable-sized classes, put all the fields together, at the top
(immediately after any necessary typedefs). For unreasonably large classes,
do whatever seems best (but let's try to avoid making more of these)."

I don't really understand objection (c); maybe an example from SM code
would clear it up. (But let me grant in advance that all style rules are
subordinate to George Orwell's sixth rule: "Break any of these rules sooner
than say anything outright barbarous.")