I'm not a Lisp weenie.  However, I have always preferred
hyphens over underscores, and I have always preferred
identifiers that use delimiters over camel-cased ones.

I just think `foo-bar-baz' looks better than `foo_bar_baz'.
Maybe it's the "lexical connotation" of hyphens from natural
language (it joins words), or maybe it's that hyphens fall
more or less on the center of gravity of an identifier,
whereas underscores usually fall beneath the baseline,
making it a purely typographical preference.

Maybe it's that I like Lisp, Dylan, CSS, XSLT, or some other
language in which hyphens are predominant.  But I don't
think that's it, because I like even more languages in which
underscores are predominant.  It's simply that I like the
look of the identifiers better in Lisp.

I realize that lots of people feel the same, only with the
exact opposite viewpoint.  It's purely a matter of taste.

My brother just walked past my monitor, glanced through the
above text and exclaimed, "Yeah, if Perl 6 allowed hyphens
in identifiers, it would be, like, the ultimate language!"

I don't mean to quote my beloved brother as an authority on
this matter (quite to the contrary, I don't think there are
any authorities, since it's a matter of taste).  I just mean
to illustrate that people do feel strongly about this issue.
(And I don't need to tell you that aesthetic aspects play a
serious role in deciding, if not whether a person is going
to end up liking the language, then at least what their
first impression is going to be.)

So what is my suggestion?  Obviously disallowing underscores
and instead allowing hyphens would just replace one problem
with an even worse problem (not only would there still be
people who don't like hyphens, but it would alienate a large
portion of the user base).  Therefore, to make the language
more appealing (i.e., less alienating) to the group of
people I am going to refer to as "Lispers", it's obvious
that both characters should be allowed.

But simply adding hyphen as another character allowed in
identifiers would only superficially solve the problem.
To be sure, it would cause a new group of people, Lispers,
to migrate to Perl 6, and might even case a few long-time
users (any closet Lispers around?) to switch to hyphens.
But it would also doom these two camps to forever remain at
war with one another.

This is because if you like underscores, you aren't going to
want libraries to use to have hyphens all over the place.
For one thing, it would be plain hell to have to remember
which packages used underscores and which used hyphens.

Therefore, my suggestion is to allow both characters, but
have them mean the same thing.  This concept caused some
confusion on IRC, so let me provide a screenshot:

   sub foo-bar ($x) { say $x }
   foo_bar(42);  # says 42

                         (image courtesy of luqui on #perl6)

If you think about it, this makes sense.  Just as you are
not forced to use the same indentation style as the authors
of the libraries you use, you should be free to use whichever
word-joiner (subtle hint not intended) you prefer.

I did not invent this solution.  "For convenience," as the
modprobe(1) man page puts it, "there is no difference
between _ and - in module names."  As another example,
GObject, the GTK+ object system, uses it to allow

   g_object_set (foo, "bar-baz")  and

   g_object_set (foo, "bar_baz")

as synonymous, which is particularly convenient since there
are so many different language bindings for GObject.
(I should --- since it is advantageous to my case --- point
out that GObject uses hyphens internally.)  There are probably
other examples (if you can think of any, please tell).

Anyway, if we can agree --- without considering the syntactical
implications --- that it is desirable to make these characters
synonymous, we have to look at the implications next.

The first thing that comes to mind is that some people write
binary minus without surrounding whitespace.  Were this
proposal to be accepted, those people would do best to
change habits, lest they be bitten when they try to subtract
the return value of a subroutine call from something.

What about unary minus?  I propose the following:

    -foo-bar   ===   -(foo-bar)   ===   -(foo_bar)
    _foo-bar   ===   _foo-bar     ===   _foo_bar

That is, hyphen and underscore are synonymous in identifiers,
but an initial hyphen is not taken to be part of the identifier.

I'm not sure about postfix unary minus, however.  You could
argue the case both ways (so please do that).

My gut feeling is that any postfix unary minus is doomed to
be confusing either way, so it might not matter.

Oh, by the way, I've been using hyphens in my Ruby
identifiers for some time now, and have not ran into any
serious problems.  The problems I have ran into are related
to either the modified Ruby mode for Emacs, or to the kludgy
implementation --- I wrote a preprocessor that parses code
looking for identifiers.  You can find that here:

   <http://www.brockman.se/software/hyphen-ruby/>


Finally, I realize that this is a religious issue, I hope
that I have not stepped on anybody's toes, and I humbly ask
that you approach this discussion with an open mind.


Kind regards,

-- 
Daniel Brockman <[EMAIL PROTECTED]>

Reply via email to