Using keywords as identifiers

52 messages Options
Embed this post
Permalink
1 2 3
Peter Gummer-2

Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
Now that "attribute" and "note" are becoming Eiffel keywords, we have to
rename some of our variables and classes. For example, I just compiled a
project in EiffelStudio 6.3 RC2 and I have 4 warnings saying, "Keyword
'attribute' is used as an identifier".

It's usually easy enough to rename the conflicting identifier, but I was
wondering whether consideration has been given to providing a mechanism
for forcing the keyword to be treated as an identifier. For example, C#
allows you to prefix an identifier with @ so that "@class" becomes a
legal variable name, not conflicting with C#'s "class" keyword. (I
recently had a need to do exactly this in some auto-generated C# code.)

Maybe Eiffel already has such a mechanism, but I'm not aware of it.

- Peter Gummer

helmut.brandl

Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
Peter Gummer wrote:

> Now that "attribute" and "note" are becoming Eiffel keywords, we have to
> rename some of our variables and classes. For example, I just compiled a
> project in EiffelStudio 6.3 RC2 and I have 4 warnings saying, "Keyword
> 'attribute' is used as an identifier".
>
> It's usually easy enough to rename the conflicting identifier, but I was
> wondering whether consideration has been given to providing a mechanism
> for forcing the keyword to be treated as an identifier. For example, C#
> allows you to prefix an identifier with @ so that "@class" becomes a
> legal variable name, not conflicting with C#'s "class" keyword. (I
> recently had a need to do exactly this in some auto-generated C# code.)
>
> Maybe Eiffel already has such a mechanism, but I'm not aware of it.
>  
What about the underline character?  _attribute?

Most (if not all) of the other characters will produce conflicts.

Just my opinion.

Helmut

The Eiffel Compiler/Interpreter: http://tecomp.sourceforge.net
http://www.sourceforge.net/projects/tecomp

Colin LeMahieu

Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by Peter Gummer-2
I'm not aware of any keywords usable as identifiers in C#.

--- In [hidden email], Peter Gummer <p-gummer@...> wrote:

>
> Now that "attribute" and "note" are becoming Eiffel keywords, we have to
> rename some of our variables and classes. For example, I just compiled a
> project in EiffelStudio 6.3 RC2 and I have 4 warnings saying, "Keyword
> 'attribute' is used as an identifier".
>
> It's usually easy enough to rename the conflicting identifier, but I was
> wondering whether consideration has been given to providing a mechanism
> for forcing the keyword to be treated as an identifier. For example, C#
> allows you to prefix an identifier with @ so that "@class" becomes a
> legal variable name, not conflicting with C#'s "class" keyword. (I
> recently had a need to do exactly this in some auto-generated C# code.)
>
> Maybe Eiffel already has such a mechanism, but I'm not aware of it.
>
> - Peter Gummer
>


helmut.brandl

Re: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
colinlema wrote:
> I'm not aware of any keywords usable as identifiers in C#.
>

As far as I understood Peter, he has not asked a question about C#, he
used it just as an example.

Peter addressed a problem, which at least deserves an answer.

Eiffel (like many other languages) has the same syntax for keywords and
identifiers. Since Eiffel is still evolving, it is probable that more
keyword/identifier clashes will appear. The recently introduced keywords
have been:

  note, attribute, attached, detachable

The discussion on object test syntax some months ago has demonstrated
the preference of the ECMA committee for keyword syntax over operator
syntax. Every introduction of a new keyword will produce clashes with
identifiers with the same name already in use.

There are 2 possible answers to Peter (and others suffering from clashes):

a) The rigorous way: If you want to have an improved language feature,
you have to change your identifiers. Fullstop.

b) The more open way: We invent some escape mechanism in Eiffel to allow
keywords used as identifiers (e.g. `attribute' like proposed by Peter or
'attribute' or ...).

Option b) has been requested by Peter.

I don't know how the ECMA committee members and Eiffel gurus think about
the problem. But it would be nice if they shared their opinion with us.

Regards
Helmut





> --- In [hidden email], Peter Gummer <p-gummer@...> wrote:
>> Now that "attribute" and "note" are becoming Eiffel keywords, we have to
>> rename some of our variables and classes. For example, I just compiled a
>> project in EiffelStudio 6.3 RC2 and I have 4 warnings saying, "Keyword
>> 'attribute' is used as an identifier".
>>
>> It's usually easy enough to rename the conflicting identifier, but I was
>> wondering whether consideration has been given to providing a mechanism
>> for forcing the keyword to be treated as an identifier. For example, C#
>> allows you to prefix an identifier with @ so that "@class" becomes a
>> legal variable name, not conflicting with C#'s "class" keyword. (I
>> recently had a need to do exactly this in some auto-generated C# code.)
>>
>> Maybe Eiffel already has such a mechanism, but I'm not aware of it.
>>
>> - Peter Gummer
>>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
Jonathan S. Ostroff

Windows console

Reply Threaded More More options
Print post
Permalink
A console application compiled and executed from the command line in Linux
will run within the same shell window.

However in windows, running the executable from a window's console will
spawn a new console and run in the new window, e.g. try running:

========================================

        make
                do
                        io.put_string ("How old are you?%N")
                        io.read_integer
                        io.put_string ("You are " + io.last_integer.out + "
years old%N")
                        io.read_character
                end
==========================================


How do we get the above program (under windows) to run in the same console
window from which it is invoked?

Thanks

Jonathan



dlebansais

Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by Colin LeMahieu
The C# spec defining identifiers at http://msdn.microsoft.com/en-us/library/aa664670.aspx  states that you can use a keyword as identifier if prefixed with '@'.

David Le Bansais

--- In [hidden email], "colinlema" <clemahieu@...> wrote:

>
> I'm not aware of any keywords usable as identifiers in C#.
>
> --- In [hidden email], Peter Gummer <p-gummer@> wrote:
> >
> > Now that "attribute" and "note" are becoming Eiffel keywords, we have to
> > rename some of our variables and classes. For example, I just compiled a
> > project in EiffelStudio 6.3 RC2 and I have 4 warnings saying, "Keyword
> > 'attribute' is used as an identifier".
> >
> > It's usually easy enough to rename the conflicting identifier, but I was
> > wondering whether consideration has been given to providing a mechanism
> > for forcing the keyword to be treated as an identifier. For example, C#
> > allows you to prefix an identifier with @ so that "@class" becomes a
> > legal variable name, not conflicting with C#'s "class" keyword. (I
> > recently had a need to do exactly this in some auto-generated C# code.)
> >
> > Maybe Eiffel already has such a mechanism, but I'm not aware of it.
> >
> > - Peter Gummer
> >
>


Emmanuel Stapf

RE: Windows console

Reply Threaded More More options
Print post
Permalink
In reply to this post by Jonathan S. Ostroff
Make sure that you have enabled the `console_application' option in your project
configuration file.

Regards,
Manu

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Jonathan S. Ostroff
> Sent: Monday, May 11, 2009 12:24 PM
> To: [hidden email]
> Subject: [eiffel_software] Windows console
>
> A console application compiled and executed from the command line in
> Linux
> will run within the same shell window.
>
> However in windows, running the executable from a window's console will
> spawn a new console and run in the new window, e.g. try running:
>
> ========================================
>
> make
> do
> io.put_string ("How old are you?%N")
> io.read_integer
> io.put_string ("You are " + io.last_integer.out + "
> years old%N")
> io.read_character
> end
> ==========================================
>
>
> How do we get the above program (under windows) to run in the same
> console
> window from which it is invoked?
>
> Thanks
>
> Jonathan
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

------------------------------------------------------------------------  
Eiffel Software
805-685-1006
http://www.eiffel.com       
Customer support: http://support.eiffel.com       
User group: http://groups.eiffel.com/join       
------------------------------------------------------------------------  
Jonathan S. Ostroff

RE: Windows console

Reply Threaded More More options
Print post
Permalink
Thanks Manu. I forgot about that setting. Jonathan

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Emmanuel Stapf [ES]
Sent: Monday, May 11, 2009 3:56 PM
To: [hidden email]
Subject: RE: [eiffel_software] Windows console

Make sure that you have enabled the `console_application' option in your
project
configuration file.

Regards,
Manu

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Jonathan S. Ostroff
> Sent: Monday, May 11, 2009 12:24 PM
> To: [hidden email]
> Subject: [eiffel_software] Windows console
>
> A console application compiled and executed from the command line in
> Linux
> will run within the same shell window.
>
> However in windows, running the executable from a window's console will
> spawn a new console and run in the new window, e.g. try running:
>
> ========================================
>
> make
> do
> io.put_string ("How old are you?%N")
> io.read_integer
> io.put_string ("You are " + io.last_integer.out + "
> years old%N")
> io.read_character
> end
> ==========================================
>
>
> How do we get the above program (under windows) to run in the same
> console
> window from which it is invoked?
>
> Thanks
>
> Jonathan
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>



------------------------------------

Yahoo! Groups Links




Peter Gummer-2

Re: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by Colin LeMahieu
colinlema wrote:
> I'm not aware of any keywords usable as identifiers in C#.
>
>  

All C# keywords are usable as identifiers, Colin, simply by prefixing
the keyword with "@".

I'm requesting similar functionality in Eiffel, except that I think a
more Eiffelesque approach would be to surround the identifier with `'.

Adding an underscore suffix is a hack. Although "attribute_" would
impair the readability of the class text only mildly, the main problem
is when this propagates through to other tools -- diagrams,
documentation, XMI, etc. -- where "attribute_" would be the wrong name
for publication to external parties.

- Peter Gummer

Berend de Boer

Re: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
>>>>> "Peter" == Peter Gummer <[hidden email]> writes:

    Peter> I'm requesting similar functionality in Eiffel, except that
    Peter> I think a more Eiffelesque approach would be to surround
    Peter> the identifier with `'.

+1

When generation source it's very useful to have an escape functionality.

--
Cheers,

Berend de Boer
rfo

RE: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by Peter Gummer-2
Hi All!

I agree that this is clearly an issue.  Hacking the name, or using a
not-so-perfect replacement identifier is a clumsy workaround around
certainly.  Quoting gives me the creeps to, but I could live with an
operator, or yes, even a keyword escape mechanism.  A prefix escape
token would be especially handy I suspect, for the lexer as well as the
programmer.  A leading underscore is not permitted in identifiers and is
not used in visible keywords, but is, I recall used internally.  It
strikes me as a reasonable candidate.  The percent character is also a
possiblity as it has limited use and I don't think would introduce any
ambiguity.
Examples:

   _attribute
   %attribute

or perhaps better,

   _ attribute
   % attribute (my favorite)

The lone underscore certainly is not ambiguous but I'm not all that keen
on it.  The percent appears in quotes as an escape char, so having act
as an escape when outside of quotes seems to me the best option. It's in
use, it's probably not ambiguous, and the semantics are similar to
current ones (being a escape mechanism).

Depending on the lexer of course, it might be that the intervening
whitespace is optional, as there might be no need for a separator.  I
dislike anything "optional" in syntax.

     R
 
==================================================
Roger F. Osmond
----------------------------------------
Amalasoft Corporation
273 Harwood Avenue
Littleton, MA 01460

> -------- Original Message --------
> Subject: Re: [eiffel_software] Re: Using keywords as identifiers
> From: Peter Gummer <[hidden email]>
> Date: Mon, May 11, 2009 7:53 pm
> To: [hidden email]
> colinlema wrote:
> > I'm not aware of any keywords usable as identifiers in C#.
> >
> >  
> All C# keywords are usable as identifiers, Colin, simply by prefixing
> the keyword with "@".
> I'm requesting similar functionality in Eiffel, except that I think a
> more Eiffelesque approach would be to surround the identifier with `'.
> Adding an underscore suffix is a hack. Although "attribute_" would
> impair the readability of the class text only mildly, the main problem
> is when this propagates through to other tools -- diagrams,
> documentation, XMI, etc. -- where "attribute_" would be the wrong name
> for publication to external parties.
> - Peter Gummer

Berend de Boer

Re: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
>>>>>   <[hidden email]> writes:

    > strikes me as a reasonable candidate.  The percent character is
    > also a possiblity as it has limited use and I don't think would
    > introduce any ambiguity.

It does. The % is a comment start sign in many languages.

--
Cheers,

Berend de Boer
rfo

RE: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by Peter Gummer-2
Hi Berend (et al)!

Yes indeed it does, but not in Eiffel, and the suggestion was to extend
Eiffel.  The ambiguity to which I was referring was lexical, not
cultural.  The intent is to have a token that can precede an identifier
that would otherwise be a keyword.
I might be wrong, but I believe the percent sign is used only within
string literals as an escape character, and as such would be a good
candidate, lexer-wise.  It is an even better candidate, reading-wise,
because it is already associated (in Eiffel) with escaping.

     R

==================================================
Roger F. Osmond
----------------------------------------
Amalasoft Corporation
273 Harwood Avenue
Littleton, MA 01460

> -------- Original Message --------
> Subject: Re: [eiffel_software] Re: Using keywords as identifiers
> From: Berend de Boer <[hidden email]>
> Date: Tue, May 12, 2009 7:52 am
> To: [hidden email]
> >>>>>   <[hidden email]> writes:
>     > strikes me as a reasonable candidate.  The percent character is
>     > also a possiblity as it has limited use and I don't think would
>     > introduce any ambiguity.
> It does. The % is a comment start sign in many languages.
> --
> Cheers,
> Berend de Boer

dlebansais

Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by rfo
--- In [hidden email], <rfo@...> wrote:

>
> Hi All!
>
> I agree that this is clearly an issue.  Hacking the name, or using a
> not-so-perfect replacement identifier is a clumsy workaround around
> certainly.  Quoting gives me the creeps to, but I could live with an
> operator, or yes, even a keyword escape mechanism.  A prefix escape
> token would be especially handy I suspect, for the lexer as well as the
> programmer.  A leading underscore is not permitted in identifiers and is
> not used in visible keywords, but is, I recall used internally.  It
> strikes me as a reasonable candidate.  The percent character is also a
> possiblity as it has limited use and I don't think would introduce any
> ambiguity.
> Examples:
>
>    _attribute
>    %attribute
>
> or perhaps better,
>
>    _ attribute
>    % attribute (my favorite)
>
> The lone underscore certainly is not ambiguous but I'm not all that keen
> on it.

This notation conflicts with free operators, since you can define most symbols, including %, to be operators for your class. The underscore character can't be a free operator, though.

David Le Bansais.


rfo

RE: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by Peter Gummer-2
Hi David!

Good point.  It appears then that freedom has its cost.

It might not be fatal though, as:
  "%"[ \t]*<keyword>

Should be distinquishable from
  "%"[ \t]*<non-keyword identifier>

as the former becomes:
  <identifier>

and the latter becomes
  <operator><identifier>

It does strike me as all that gymnastic.

    R

==================================================
Roger F. Osmond
----------------------------------------
Amalasoft Corporation
273 Harwood Avenue
Littleton, MA 01460

> -------- Original Message --------
> Subject: [eiffel_software] Re: Using keywords as identifiers
> From: "dlebansais" <[hidden email]>
> Date: Tue, May 12, 2009 8:25 am
> To: [hidden email]
> --- In [hidden email], <rfo@...> wrote:
> >
> > Hi All!
> >
> > I agree that this is clearly an issue.  Hacking the name, or using a
> > not-so-perfect replacement identifier is a clumsy workaround around
> > certainly.  Quoting gives me the creeps to, but I could live with an
> > operator, or yes, even a keyword escape mechanism.  A prefix escape
> > token would be especially handy I suspect, for the lexer as well as the
> > programmer.  A leading underscore is not permitted in identifiers and is
> > not used in visible keywords, but is, I recall used internally.  It
> > strikes me as a reasonable candidate.  The percent character is also a
> > possiblity as it has limited use and I don't think would introduce any
> > ambiguity.
> > Examples:
> >
> >    _attribute
> >    %attribute
> >
> > or perhaps better,
> >
> >    _ attribute
> >    % attribute (my favorite)
> >
> > The lone underscore certainly is not ambiguous but I'm not all that keen
> > on it.
> This notation conflicts with free operators, since you can define most symbols, including %, to be operators for your class. The underscore character can't be a free operator, though.
> David Le Bansais.

Peter Gummer-2

Re: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by Berend de Boer
Berend de Boer wrote:
> When generation source it's very useful to have an escape functionality


Yes indeed, Berend. This is exactly the case where I've needed to use
C#'s escape functionality recently.

- Peter Gummer

Peter Gummer-2

Re: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by dlebansais
dlebansais wrote:
>>    % attribute (my favorite)
>>
>> ...
>>    
>
> This notation conflicts with free operators, since you can define most symbols, including %, to be operators for your class. The underscore character can't be a free operator, though.
>  

I think ` can't be a free operator either, so it would also be suitable,
although for legibility I think that closing the quote would be good:
`attribute'.

- Peter Gummer

Bertrand Meyer

RE: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
I am skeptical of the benefit of all this. The rule that identifiers may not
clash with keywords seems sound, especially given that there are not so many
keywords.

 

Let's assume that we get into a frenzy of language extensions and introduce
a keyword every two years over the next 50 years (after which few of the
current users will presumably be interested). That's 25 keywords, of which
presumably only a few, say half,  might be common words that have a
significant chance of clashing with identifiers in existing code. Is it
necessary to add a special language mechanism for a dozen cases?

 

The problem is of course common words such as `note' turned into keywords
after many years in which they were free. A special compiler hack for such
cases, whenever possible, seems preferable to a language mechanism. The
problem with any language mechanism is that it requires changing user  code
anyway. If you are going to change every occurrence of the identifier `note'
to `@note' or some such convention, why not change it to a normal identifier
name? This avoids polluting the code with strange notations, and encouraging
nonstandard identifiers even in the absence of a conflict with existing code
(i.e. what if people start calling their identifiers `@do' and `@feature' in
new code?) At least a compiler hack lets you keep your code as it is, with
the expectation that you will clean it up when you have time. Such a cleanup
should happen just once.

 

So while I am willing to be convinced otherwise I don't think a special
notation is justified.

 

Of course I sympathize with programmers who had the bad luck of choosing
names that became keywords later on.

 

At the moment the only common word that could become a keyword is `across'.
It's a good idea to stay away from it.

 

Thanks,

 

-- BM

 



[Non-text portions of this message have been removed]

Berend de Boer

Re: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
>>>>> "Bertrand" == Bertrand Meyer <[hidden email]> writes:

    Bertrand> Let's assume that we get into a frenzy of language
    Bertrand> extensions and introduce a keyword every two years over
    Bertrand> the next 50 years (after which few of the current users
    Bertrand> will presumably be interested). That's 25 keywords, of
    Bertrand> which presumably only a few, say half, might be common
    Bertrand> words that have a significant chance of clashing with
    Bertrand> identifiers in existing code. Is it necessary to add a
    Bertrand> special language mechanism for a dozen cases?

We got `note' and `attribute' in four years, so the trend-line
definitively doesn't favour half being common keywords.

A good keyword is a common identifier.


    Bertrand> A special compiler hack for such cases, whenever
    Bertrand> possible, seems preferable to a language mechanism.

Agree. Gobo has an Eiffel parser anyway, so I think such hacks don't
need to be distributed over too many custom Eiffel code parsers.

--
All regards,

Berend de Boer
Thomas Beale-3

Re: Re: Using keywords as identifiers

Reply Threaded More More options
Print post
Permalink
In reply to this post by rfo
[hidden email] wrote:
 >
 >
 > Hi All!
 >
 > I agree that this is clearly an issue. Hacking the name, or using a
 > not-so-perfect replacement identifier is a clumsy workaround around
 > certainly. Quoting gives me the creeps to, but I could live with an
 > operator, or yes, even a keyword escape mechanism. A prefix escape
 > token would be especially handy I suspect, for the lexer as well as the
 > programmer. A leading underscore is not permitted in identifiers and is
 > not used in visible keywords, but is, I recall used internally. It
 > strikes me as a reasonable candidate. The percent character is also a
 > possiblity as it has limited use and I don't think would introduce any
 > ambiguity.
 > Examples:
 >
 > _attribute
 > %attribute
 >

as the author of some of the code in question, I would ask: have we even
shown that features of names like 'attribute' and 'note' can't simply be
used, and contextually disambiguated by the compiler from the keywords
of the same name?


--
    Thomas Beale
Chief Technology Officer, Ocean Informatics

Chair Architectural Review Board, openEHR Foundation
Honorary Research Fellow, University College London
Chartered IT Professional Fellow, BCS, British Computer Society




1 2 3