Archived

This forum has been archived. Please start a new discussion on GitHub.

Why reserve *all* words beginning with "Ice"?

From the Ice documentation, section 4.5.3 "Identifiers":
Reserved Identifiers

Slice reserves the identifier Ice and all identifiers beginning with Ice for the Ice implementation. For example, if you try to define a type named Icecream , the Slice compiler will issue an error message.

First question ... why reserve *all* words starting with "Ice"? That seems a little restrictive.

Secondly, why does it apply to nested scopes? For example, say I was designing a distributed version of a popular arcade game from 1982:
module Pengo
{
   struct Position
   {
       short x;
       short y;
   };

   interface Block
   {
     Position getPos();
   };

   interface Ice extends Block // Ouch!! This won't work!
   {
     void smash();
   };

   interface Penguin
   {
     void moveUp();
     void moveDown();
     void moveLeft();
     void moveRigth();
   };
};

Pengo::Ice is invalid :( Even Pengo::IceCube is not permitted. The idea of modules is to partition off different scopes, so it could be irritating that I'm forbidden to use certain names in my *own* scopes! Especially as Ice is a common English word.

However, I'm confident there's a good reason, but I just can't think of it ... something to do with the generated code, perhaps?

Comments

  • Re: Why reserve *all* words beginning with "Ice"?
    Originally posted by dthomson


    First question ... why reserve *all* words starting with "Ice"? That seems a little restrictive.

    Secondly, why does it apply to nested scopes?

    Ice is a reserved prefix to create a naming scope that we can safely use for internal purposes. For example, Ice is a module at the global level. If we were to allow you to define an identifier Ice at the global level, we get a clash.

    We applied the rule to identifiers in nested scopes because, again, it allows us to use Ice as a prefix for generated identifiers. This is a problem in general: if a mapping generates new identifiers that are not present in the Slice definition, those identifiers must be generated into a separate namespace, otherwise they can clash with other legitimate identifiers. For an example, try compiling the code generated by an IDL-to-C++ compiler for CORBA if the IDL contains interface foo and interface foo_var. The IDL is valid, but the generated code cannot possibly compile.

    So, in the end, we decided that Ice was going to be our universal escape hatch for such cases.

    Note that you can use ice without any problems -- only Ice is reserved.

    So, if you really want to implement Pengo, I'm afraid that you will have to use ice, ICE, or, if you like, FrozenWater ;)

    Cheers,

    Michi.
  • Re: Re: Why reserve *all* words beginning with "Ice"?
    Originally posted by michi

    So, if you really want to implement Pengo, I'm afraid that you will have to use ice, ICE, or, if you like, FrozenWater ;)

    Hmmm... Actually, this is even more draconian contrary to what I said earlier. Because of the case-insensitive nature of Slice identifiers, we actually outlaw all identifiers that start with Ice, no matter how it is capitalized. This protects us if we want to map to languages such as FORTRAN, which is case-insensitive.

    Derek, I'm afraid you are down to FrozenWater ;)

    Cheers,

    Michi.