Results 1 to 4 of 4

Thread: Class-Scoped Enums

  1. #1
    acbell is offline Registered User
    Name: Andrew Bell
    Organization: Iowa State University
    Project: National Resources Inventory
    Join Date
    Jan 2005
    Location
    Ames, IA, USA
    Posts
    89

    Class-Scoped Enums

    Hi,

    I'd like to see Slice support class-scoped enums:

    class foo {
    enum Fruit { Apple, Pear, Orange };
    };

    I'm not sure if this is a problem for some of the mappings, however.

    Thanks!

    -- Andrew Bell
    andrew.bell.ia@gmail.com

  2. #2
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    Please have a look at this post regarding our new support policy.

    As a general rule, Slice does not allow nested type definitions, to avoid various problems with language mappings. I also don't see any advantage of having such nested types. While for implementation languages, such types can be helpful (for hiding types private to classes), I don't see how an interface definition would benefit from this.

  3. #3
    acbell is offline Registered User
    Name: Andrew Bell
    Organization: Iowa State University
    Project: National Resources Inventory
    Join Date
    Jan 2005
    Location
    Ames, IA, USA
    Posts
    89
    Hi,

    If the answer is that there are problems with language mappings, then so be it. On the other hand, I don't understand why it is useful to occasionally scope these things at a lower level in an implementation, but not in the interface. For example:

    module Vehicles {

    class Car {
    enum Color { RED, BLUE, YELLOW };
    };

    class Bus {
    enum Color { RED, WHITE, GREEN };
    };
    };

    Is it unreasonable to want to reuse the name "RED"? Not to me.

    Anyway, in our case we are using freeze and in some cases the slice objects are only server side. It is cleaner for us to limit the scope of the enums to the lowest applicable scope. We may stick other things in the namespace created by the module, and the ability to change the scope can be useful.

    It's not a big deal, I just thought it might be a useful extension that would be simple to implement.

    Thanks,

    -- Andrew Bell
    Iowa State University - Center For Survey Statistics and Methodology
    andrew.bell.ia@gmail.com

  4. #4
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    Enums are a somewhat unfortunate example, because Slice enums had to inherit the brain-dead enum scoping rules from C/C++, otherwise the C++ mapping would have been very ugly. Without these silly scoping rules, you could simply define CarColor and BusColor, and use RED in both of them, without any name clashes.

    In the end, it is a trade-off. We decided to not allow nested enums because we don't allow any other nested types, so to make an exception for enums would be inconsistent. The reason why we don't allow other nested types is simplicity: It would be hard to map to certain languages, and it would also make the slice compilers more complex (see CORBA). Furthermore, as I wrote before, I do not believe that nested types would provide any significant benefit for interface definitions, except perhaps for enums, because of the scoping rules.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Patch for slice2cs with scoped constants
    By ben.boeckel in forum Patches
    Replies: 0
    Last Post: 11-18-2010, 11:59 AM
  2. Replies: 1
    Last Post: 11-29-2007, 07:26 AM
  3. Replies: 1
    Last Post: 06-30-2006, 02:32 PM
  4. Java enums
    By dashie in forum Comments
    Replies: 2
    Last Post: 07-29-2005, 12:10 AM
  5. About self-referential class
    By level in forum Help Center
    Replies: 8
    Last Post: 09-07-2004, 10:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •