[LLVMdev] RFC: variable names

Chandler Carruth chandlerc at google.com
Mon Oct 13 16:02:44 PDT 2014


On Mon, Oct 13, 2014 at 4:00 PM, Chris Lattner <clattner at apple.com> wrote:

> On Oct 13, 2014, at 3:44 PM, Chandler Carruth <chandlerc at google.com>
> wrote:
> > I actually have a particular allergy to member variable names and
> function names having similar styles:
> >
> > bool x = i->isMyConditionTrue;
> >
> > Did I mean to write 'isMyConditionTrue()'? Or 'bool &x =
> I->isMyConditionTrue'? Or something else? I have no idea. Warnings and
> other things can help reduce the likelihood of this becoming a live bug,
> but it still makes the code harder to read IMO.
>
> This is exactly why I was making the wishy-washy statement about instance
> variables.  This is the pattern that I tend to prefer:
>
>
> class Something {
>   bool IsMyConditionTrue;
>
>>
>   bool isMyConditionTrue() const { return IsMyConditionTrue; }
> }
>
> If you make instance variables be lower camel case, then you get serious
> conflict between ivars and methods.


Agreed.

I am also fine with:

class Something {
  bool is_my_condition_true;

...

  bool isMyConditionTrue() const { return is_my_condition_true; }
};


I think it has the same lack of ambiguity. Its somewhat nicer that there is
no type name conflict as well, but honestly that's a smaller gain IMO.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141013/3ba16654/attachment.html>


More information about the llvm-dev mailing list