www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Storage class consistency

reply Robert Fraser <fraserofthenight gmail.com> writes:
Okay, I know everyone wants to put "enum" to rest, but I just want an 
explanation for why "enum" was chosen in the facre of syntactic 
difficulties. In particular, what I mean is that for every other storage 
class the following is possible:

public
{
     int x =  5;
     float f = 7.0;
}

const
{
     int x = 5;
     float y = 7.0;
}

... but not with enum ...

enum
{
     int x = 5;
     float y = 7.0;
}

... which instead must be used as ...

enum int x = 5;
enum float y = 7.0;

I understand Walter probably thought it through and decided that this 
inconsistency was worth it to be able to use a confusing keyword, but 
these are the sort of reasons it's difficult for me to get excited about 
D2. Is there any particular reason this was thought unimportant?
Apr 05 2008
next sibling parent Sean Kelly <sean invisibleduck.org> writes:
== Quote from Robert Fraser (fraserofthenight gmail.com)'s article
 I understand Walter probably thought it through and decided that this
 inconsistency was worth it to be able to use a confusing keyword, but
 these are the sort of reasons it's difficult for me to get excited about
 D2. Is there any particular reason this was thought unimportant?
Near as I can tell, it was the desire to avoid the creation of an additional keyword that was the driving force behind the decision, as well as an apparent desire to allow addressability for invariant data. Sean
Apr 05 2008
prev sibling next sibling parent Paul D. Anderson <paul.d.anderson.removethis comcast.andthis.net> writes:
Robert Fraser Wrote:

 Okay, I know everyone wants to put "enum" to rest, but I just want an 
 explanation for why "enum" was chosen in the facre of syntactic 
 difficulties. In particular, what I mean is that for every other storage 
 class the following is possible:
 
 public
 {
      int x =  5;
      float f = 7.0;
 }
 
 const
 {
      int x = 5;
      float y = 7.0;
 }
 
 ... but not with enum ...
 
 enum
 {
      int x = 5;
      float y = 7.0;
 }
 
 ... which instead must be used as ...
 
 enum int x = 5;
 enum float y = 7.0;
 
 I understand Walter probably thought it through and decided that this 
 inconsistency was worth it to be able to use a confusing keyword, but 
 these are the sort of reasons it's difficult for me to get excited about 
 D2. Is there any particular reason this was thought unimportant?
I agree this is a problem but to me it is a syntax problem rather than a keyword problem. I'd like to see the syntax you described become available. If the problem with the syntax is a conflict with existing "enum" syntax then I think you make a strong case for a new keyword. IIRC, the favorite of the forum was "manifest". Paul
Apr 05 2008
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Robert Fraser" wrote
 Okay, I know everyone wants to put "enum" to rest, but I just want an 
 explanation for why "enum" was chosen in the facre of syntactic 
 difficulties. In particular, what I mean is that for every other storage 
 class the following is possible:

 public
 {
     int x =  5;
     float f = 7.0;
 }

 const
 {
     int x = 5;
     float y = 7.0;
 }

 ... but not with enum ...

 enum
 {
     int x = 5;
     float y = 7.0;
 }
I haven't used D2 since this was added, but from what I understood about it, this should work. If not, it should be a bug. -Steve
Apr 06 2008