[nem-en] Syntax change - your thoughts?
Gerard Murphy
g.j.murphy at sageserpent.com
Fri Feb 3 20:20:55 CET 2006
Dear all,
One thing I notice from time to time is the inconsistency in the syntax for
generic types in Nemerle.
Let's say I have a class:-
public
class AGenericClass[TypeParameter]
{
public
this()
{
}
public static
ackleWithIt[AnotherTypeParameter](it: AnotherTypeParameter): void
{
}
public static
disappearUpOnesOwn(): void
{
disappearUpOnesOwn()
}
}
Not the most sensible class, I agree!
Now, if I want to declare a variable of this class type, then I can write:-
public
class Client
{
public
Foo(): void
{
def x = AGenericClass.[int]();
mutable y: AGenericClass[int] = null;
// etc.
}
}
Note the use of the dot before the type parameters when the generic class
type is used as a constructor invocation.
The same thing happens if I want to refer to a method in the generic class:-
public
class Client
{
public
Foo(): void
{
AGenericClass[string].disappearUpOnesOwn();
AGenericClass[string].ackleWithIt.[int](2);
// etc.
}
}
Again, a dot has mysteriously appeared before the type parameters, even
though the non-generic method doesn't require a dot to be called, nor do the
type parameters in the generic method's definition require separation from
the method name with a dot.
I get the impression that the decision to use a dot before the type
parameters in an expression context was driven by an implementation decision
- without the dot, the expression would look like an indexer call (and
indeed, neglecting the dot results in such an error message).
My point is that the syntax should be consistent and the compiler should
have to work a little harder - I should be able to write:-
def x = AGenericClass[int]();
as well as
AGenericClass[string].ackleWithIt[int](2);
and the compiler should know that 'AGenericClass' is the leading part of a
generic type, not the name of a variable that is about to be subject to an
indexing operator call!
Well, you might say I'm dwelling on trivial details here - but I keep
tripping up over this syntax inconsistency and find myself either trying
alternatives to get the compiler to vet my syntax, or going to the Nemerle
homepage to check the language grammar.
This isn't right - a good programming language is something that working
programmers should be able to internalise - the syntax should be intuitive.
Consider that C++, Java and C# all have the consistent syntax approach in
their use of generics / templates: the expression usages mirror the
definition syntax. I would argue that if the goal is to attract a base of
software engineers to rally in support of the language (and I would
certainly like to see this happen, as I know others on this mailing list
would), then perhaps this change of the language syntax should be included
in order not to put off folk who are used to the consistent syntax in their
'home' languages.
It's all very well to have good features in a language - and I think Nemerle
is packed full of them, put together in an elegant way - but don't forget
the mundane ergonomics factors. People have to sit down in front of a
computer and type this stuff in, day after day after day!
In case you aren't convinced, ask yourselves how many Lisp, Algol 68 and APL
programmers you've met in your careers. Why is Java becoming increasingly
popular in comparison with C++? It isn't increased expressive power; it's
convenience of everyday use that swings these matters.
OK, that's the polemic over with - meanwhile there are the language
developers and the existing user community to consider. So what are your
thoughts on this?
Is my difficulty with the syntax just a case of my brain being addled with
age? ;-)
Perhaps there is a more fundamental reason that I'm not aware of that
prohibits using semantic context to disambiguate the parsing?
In closing - I'd be delighted to investigate making the changes myself to
the compiler to support a consistent generics syntax, if others become
convinced that it should change. I suspect that the Wroclaw team might be
able to carry these out a bit faster then me, though. :-)
One last thing - I'm on holiday for the next four days, so if anyone directs
a question at me, please don't be offended if I don't reply immediately -
I'll try to peek at the mailing list if I can, though.
Kind Regards,
Gerard Murphy www.sageserpent.com <http://www.sageserpent.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman/pipermail/devel-en/attachments/20060203/2cf2eefc/attachment.html
More information about the devel-en
mailing list