<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 13, 2014 at 3:19 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Mon, Oct 13, 2014 at 3:04 PM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">I’d like to discuss revising the LLVM coding conventions to change the naming of variables to start with a lowercase letter.</div></blockquote><div><br></div></span><div>Almost all of your negatives of the current conventions also apply to your proposed convention.</div><div><br></div><div>Type names: CamelCase</div><div>Function names: camelCase</div><div>Variable names: ???</div><div><br></div><div>If we name variables in camelCase then variable names and function names collide.</div><div><br></div><div>If we are going to change how we name variables, I very much want them to not collide with either type names or function names. My suggestion would be "lower_case" names.</div></div></div></div></blockquote><div><br></div><div><div>I think this would be bad:</div><div><br></div><div>  function();</div><div>  lambda();</div><div>  longFunction();</div><div>  long_lambda();</div><div><br></div><div>... but possibly not in practice, since function names rarely have only one word.</div><div><br></div><div>A partial-camel-case, partly-underscores convention sounds strange to me. (I don't find this to be problematic for BIG_SCARY_MACROS and for ABCK_EnumNamespaces because the former are rare and in the latter case the underscore isn't a word separator, it's a namespace separator.) We have a few people here who are used to such a style (since it's what the Google style guide and derivatives uses); any useful feedback from that experience?</div></div><div><br></div><div><br></div><div>Some arguments against the change as proposed:</div><div><br></div><div>1. Initialisms. It's common in Clang code (also in LLVM?) to use initialisms as variable names. This doesn't really seem to work for names that start with a lower case letter.</div><div><br></div><div>2. The ambiguity introduced might be worse than the one removed. It's usually easy to see if a name is a type or variable from the context of the use. It's not so easy to see if a name is a function or a variable, especially as more variables become callable due to the prevalence of lambdas.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>This also happens to be the vastly most common pattern across all C++ coding styles and C-based language coding styles I have seen.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><div style="word-wrap:break-word">  This should not be a discussion on the pain of such a transition, or how to get from here to there, but rather, if there is a better place to be.  <br><font color="#0f61c8"><br></font>My arguments for the change are:<br><font color="#0f61c8"><br></font>1. No other popular C++ coding style uses capitalized variable names.  For instance here are other popular C++ conventions that use camelCase:<br><font color="#0f61c8"><br></font>   <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml" target="_blank">http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml</a></div></div></div></blockquote></div></div></div></blockquote><div><br></div><div>This does not use camelCase for variable names.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><div style="word-wrap:break-word">   <a href="http://www.c-xx.com/ccc/ccc.php" target="_blank">http://www.c-xx.com/ccc/ccc.php</a><br>   <a href="http://geosoft.no/development/cppstyle.html" target="_blank">http://geosoft.no/development/cppstyle.html</a><br><font color="#0f61c8"><br></font>And, of course, the all-lower-case conventions (e.g. C++ ARM) don’t capitalize variable names.  In addition, all the common C derived languages don’t use capitalized variable names (e.g. Java, C#, Objective-C).</div></div></div></blockquote></div></div></div></blockquote><div><br></div><div>Some or all of those other conventions don't capitalize *any* names (other than perhaps macros), so we're not going to become consistent with them by making this change.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><div style="word-wrap:break-word">2. Ambiguity.  Capitalizing type names is common across most C++ conventions.  But in LLVM variables are also capitalized which conflates types and variables.  Starting variable names with a lowercase letter disambiguates variables from types. For instance, the following are ambiguous using LLVM’s conventions:<br><font color="#0f61c8"><br></font><span style="font-family:Monaco;font-size:x-small;white-space:pre-wrap">        </span><span style="font-family:Monaco;font-size:x-small">Xxx Yyy(Zzz);  // function prototype or local object construction?</span><br><span style="font-family:Monaco;font-size:x-small;white-space:pre-wrap">      </span><span style="font-family:Monaco;font-size:x-small">Aaa(Bbb);      // function call or cast?</span><br><font color="#0f61c8"><br><br></font>3. Allows name re-use. Since types and variables are both nouns, using different capitalization allows you to use the same simple name for types and variables, for instance:<br><font color="#0f61c8"><br></font><span style="font-family:Monaco;font-size:x-small;white-space:pre-wrap">   </span><span style="font-family:Monaco;font-size:x-small">Stream  stream;</span><br><font color="#0f61c8"><br><br></font>4. Dubious history.  Years ago the LLVM coding convention did not specify if variables were capitalized or not.  Different contributors used different styles.  Then in an effort to make the style more uniform, someone flipped a coin and updated the convention doc to say variables should be capitalized.  I never saw any on-list discussion about this.</div></div></div></blockquote></div></div></div></blockquote><div><br></div><div><div>FWIW, I thought the argument for the current convention was: capitalize proper nouns (classes and variables), do not capitalize verbs (functions), as in English. Though maybe that's just folklore.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"></div></div></div></blockquote></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><div style="word-wrap:break-word">5. Momentum only.  When I’ve talked with various contributors privately, I have found no one who says they likes capitalized variables.  It seems like everyone thinks the conventions are carved in stone...  </div></div></div></blockquote></div></div></div></blockquote><div><br></div><div>Momentum is an argument against the change, not in favour of it: this change has a re-learning cost for everyone who hacks on LLVM projects. (Your point that no-one seems to like capitalized variables is valid, but generally people are opposed to change too.)</div><div><br></div><div>I would add:</div><div><br></div><div><div>6. Lower barrier to entry. Our current convention is different from almost all other C++ code, and new developers *very* frequently get it wrong.</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><div style="word-wrap:break-word">My proposal is that we modify the LLVM Coding Conventions to have variable names start with a lowercase letter.  <br><font color="#0f61c8"><br></font><span style="font-family:Monaco;font-size:x-small">Index: CodingStandards.rst</span><br><span style="font-family:Monaco;font-size:x-small">===================================================================</span><br><span style="font-family:Monaco;font-size:x-small">--- CodingStandards.rst</span><span style="font-family:Monaco;font-size:x-small;white-space:pre-wrap"> </span><span style="font-family:Monaco;font-size:x-small">(revision 219065)</span><br><span style="font-family:Monaco;font-size:x-small">+++ CodingStandards.rst</span><span style="font-family:Monaco;font-size:x-small;white-space:pre-wrap"> </span><span style="font-family:Monaco;font-size:x-small">(working copy)</span><br><span style="font-family:Monaco;font-size:x-small">@@ -1073,8 +1073,8 @@</span><br><span style="font-family:Monaco;font-size:x-small">   nouns and start with an upper-case letter (e.g. ``TextFileReader``).</span><br><span style="font-family:Monaco;font-size:x-small"> </span><br><span style="font-family:Monaco;font-size:x-small"> * **Variable names** should be nouns (as they represent state).  The name should</span><br><span style="font-family:Monaco;font-size:x-small">-  be camel case, and start with an upper case letter (e.g. ``Leader`` or</span><br><span style="font-family:Monaco;font-size:x-small">-  ``Boats``).</span><br><span style="font-family:Monaco;font-size:x-small">+  be camel case, and start with a lower case letter (e.g. ``leader`` or</span><br><span style="font-family:Monaco;font-size:x-small">+  ``boats``).</span><br><span style="font-family:Monaco;font-size:x-small">   </span><br><span style="font-family:Monaco;font-size:x-small"> * **Function names** should be verb phrases (as they represent actions), and</span><br><div><div style="word-wrap:break-word"><div><div style="margin:0px"><font face="Monaco" size="1">   command-like function should be imperative.  The name should be camel case,</font></div></div></div></div></div><br></div></div><span class="">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></span></blockquote></div><br></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>