On Tue, 28 Apr 2009 13:12:41 -0400, Robert Fraser <fraseroftheni...@gmail.com> wrote:

Steven Schveighoffer wrote:
On Mon, 27 Apr 2009 18:36:55 -0400, Sean Kelly <s...@invisibleduck.org> wrote:

== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article
For the same reason, C accepts enum X { a, b, } but not ,a ,b.
Mechanically generating enum values is easier if each value has a
trailing comma.

This has always seemed weird to me.  C doesn't accept a trailing comma
in function parameter lists.  I don't mind it accepting commas in enum
blocks mostly because leaving a trailing comma in multi-line blocks
can mean a smaller diff if I want to append new elements to the block
later, but it certainly isn't sufficient to justify the syntax IMO.
You know, this just reminded me of something. What is the purpose of allowing trailing commas in enums in C? mostly for this:
 enum {
  val1,
  val2,
#ifdef INCLUDE_VAL_3
  val3
#endif
};
Which would require some weird preprocessor logic for val2 if a trailing comma weren't allowed But hasn't this behavior been *specifically* frowned upon by Walter due to it's lack of maintainability? In fact, I'd say that except for C portability (which is becoming more and more a moot argument), we could get rid of allowing the comma at the end of the last enum definition. In fact, it would discourage the undesirable behavior of versioning around elements versus versioning around the enum. I know the argument is over for splitter, but I just thought this was an interesting connection to explore.
 -Steve

NO! Allowing trailing comma in stuff is great if it's being generated by CTFE, or if it's just a long list you're adding to/removing from/commenting parts out during development. I'd rather trailing commas be allowed in array literals, too.

I'm not strongly in favor of removing the commas, but your arguments aren't that convincing to me.

How hard is it to output ", x" instead of "x, " when building an enum body, and then substring the result[2..$]?

Adding to/removing from/commenting isn't that hard to deal with the comma. I think this is a small amount of work you are saving. I generally do not leave the trailing comma and it isn't that hard to deal with. It also only affects you if you are messing with the last element.

-Steve

Reply via email to