tag:blogger.com,1999:blog-2441850399540300710.post4037838242323885290..comments2024-02-17T03:47:06.818-08:00Comments on CraigBlog: Trailing CommasCraig Anderahttp://www.blogger.com/profile/17084199593129216563noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-2441850399540300710.post-38583760235655645062009-01-17T08:33:32.000-08:002009-01-17T08:33:32.000-08:00While it's good for making the code easier, it...While it's good for making the code easier, it's not part of the standards and therefore leads to unpredictables behavior. <br /><br />Don't take me wrong. I'm not exactly the guy who follows the rules but I have had nightmares when I got a bug on my code and you never expect that this little comma could be the reason of it.<br /><br />GreetingsAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-9954280874818047012006-08-02T10:22:00.000-07:002006-08-02T10:22:00.000-07:00This is intential. It was part of the ANSI C stand...This is intential. It was part of the ANSI C standard, and carried over to C#. I was on the working group that discussed and approved this, the rationale for allowing the syntax was all of the reasons that Craig pointed out orginally.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-30210284095680714222006-06-13T07:34:00.000-07:002006-06-13T07:34:00.000-07:00You can use the same trailing comma syntax for arr...You can use the same trailing comma syntax for array initializers in both C and C#.<br /><br><br /><br>const Point corners[4] = {<br /><br> {1, 1},<br /><br> {2, 1},<br /><br> {2, 2},<br /><br> {1, 2},<br /><br>};Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-1536629525803188032006-05-11T17:29:00.000-07:002006-05-11T17:29:00.000-07:00Yup, I've been using that from K&R days. ...Yup, I've been using that from K&R days. I still use and it every once in a while someone will point out that it's a bug. Sigh. It *is* very helpful for reordering elements, which is why is was put in by K&R iirc.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-27254074379163976272006-05-11T12:32:00.000-07:002006-05-11T12:32:00.000-07:00This is OLD SKOOL C!!! Kernighan and Ritchie... Wo...This is OLD SKOOL C!!! Kernighan and Ritchie... Wow, some people really were born yesterday!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-66985265462893524572006-05-10T07:42:00.000-07:002006-05-10T07:42:00.000-07:00>> how would it make it easier to reorder th...>> how would it make it easier to reorder the enum elements and generate source code <<<br /><br><br /><br>Well for reordering you can simply cut and paste lines - there's no need to remove the trailing comma on whatever enum happens to be last now, and there's no need to add a comma to whatever enum used to be last, but no longer is.<br /><br><br /><br>And for code generation, it's a bit of state that no longer needs to be tracked in whatever is generating the code - just always slap a comma at the end of the enum-list-item. When the generated code is compiled, the compiler won't care if there's a 'dangling' comma at the end.<br /><br><br /><br>These aren't earth shattering issues, but they are small plusses without any drawbacks (as far as I can see).Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-76766183119343583602006-05-10T04:49:00.000-07:002006-05-10T04:49:00.000-07:00Craig, My question is in the context of what you s...Craig, My question is in the context of what you said: "It means I can more easily reorder these elements, more easily generate source code". Unless I am missing something, how would it make it easier to reorder the enum elements and generate source code?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-7411408052178461852006-05-09T18:10:00.000-07:002006-05-09T18:10:00.000-07:00Shepard: not sure if you're joking or not. In ...Shepard: not sure if you're joking or not. In all the context where this would be used, an empty element isn't legal.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-38149707368783339112006-05-09T18:05:00.000-07:002006-05-09T18:05:00.000-07:00Craig, I don't see how this is a cool feature ...Craig, I don't see how this is a cool feature because it seems to simply ignore the empty element.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-66613658223702769382006-05-09T08:54:00.000-07:002006-05-09T08:54:00.000-07:00Ineresting - a trailing comma on an enumerator-lis...Ineresting - a trailing comma on an enumerator-list has been in ANSI C syntax from the start (6.7.2.2), but it does not appear in my copy of the C++ 98 spec (ISO/IEC 14882).<br /><br><br /><br>I just thought that it's been there from the beginning (maybe even K&R days).<br /><br><br /><br>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-77279103722573993342006-05-08T16:18:00.000-07:002006-05-08T16:18:00.000-07:00Just be forewarned that if you do the same thing i...Just be forewarned that if you do the same thing in JavaScript to an array, you'll get an extra nameless object, that'll really hork up Behaviour.js [not that I speak from experience].<br /><br><br /><br>Personally, I prefer the leading-comma strategy...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-36233329910385768882006-05-08T10:41:00.000-07:002006-05-08T10:41:00.000-07:00Isn't it document in the K&R book too?Isn't it document in the K&R book too?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-75783565257779393322006-05-08T09:46:00.000-07:002006-05-08T09:46:00.000-07:00Kim, I don't have a reference, but I'm pre...Kim, I don't have a reference, but I'm pretty sure it's intentional and part of the C# spec. I recall it being explained as to make code generation easier.<br /><br><br /><br>But I could be confusing it with C++...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-50570995544935733162006-05-08T09:32:00.000-07:002006-05-08T09:32:00.000-07:00Support for trailing coma is part of the C99 stand...Support for trailing coma is part of the C99 standard. AFAIK, it should be included in C++ standard as well. See here:<br /><br><br /><br>http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#518<br /><br>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-49766408082011533342006-05-08T08:26:00.000-07:002006-05-08T08:26:00.000-07:00I'd classify it as a feature, not a bug. I can...I'd classify it as a feature, not a bug. I can't think of anything that it hurts, as there's no need to specify an empty element anywhere I can think where I'd want to use this. <br /><br><br /><br>Anyway, bug or feature, I hope they don't change it. :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-38589319311130214542006-05-08T08:20:00.000-07:002006-05-08T08:20:00.000-07:00I wonder if this is intentional... Microsoft's...I wonder if this is intentional... Microsoft's C++ compilers have allowed it for ages as well, and it freaked me out the first time I saw it too.<br /><br><br /><br>I've been thinking it's easier to let the parser accept it than reject it, and that they never bothered to fix the bug, but maybe it is in fact a feature.Anonymousnoreply@blogger.com