Some more template syntax sugar
Kristian
kjkilpi at gmail.com
Fri Sep 1 12:26:59 PDT 2006
I still think that it would be good if parameters names would be
mandatory. But then again, I always name my parameters.
typedef int x;
void foo(x); //'x' is a typeless parameter -> this is a function
template
void foo(x y); //'x' is a typedef -> this is a normal function
Would this break too much old code?
If so, how about using '!' with templates (as I mentioned earlier)? For
example:
void foo!(x); //definitely a function template
On Fri, 01 Sep 2006 13:10:49 +0300, Reiner Pope
<reiner.pope at REMOVE.THIS.gmail.com> wrote:
> I've thought about this ambiguity and still come to not much more of a
> conclusion. However, a few thoughts:
>
> (just to clarify my naming, let's call the current system (parameters
> without names) nameless parameters, and my suggestion (implicit
> templating) typeless parameters)
>
> 1. Nameless parameters are a very small syntactical sugar as opposed to
> typeless parameters, and I assert that we can do without them. Most of
> the time, you should name your parameters anyway, so the caller can have
> a better idea of what they are used for, and if you decide that it is
> just way to much to type, then you can get away with only two more
> characters for each parameter:
>
> int foo(int, int);
>
> becomes
>
> int foo(int a, int b);
>
> which really isn't much more to type.
>
> 2. It would be possible to do a small modification of the typeless
> parameter syntax to make it grammatically distinct from typeless
> parameters. For instance, add a '@' to make it clear:
>
> auto sqr(@x) {...}
>
> While, on the surface, this seems the rights solution, I think it
> creates a similar mental block as we get with lazy parameters: even
> though
>
> foo( {x();} );
>
> is only three characters more than
>
> foo( x() );
>
> you will get people used to 'proper' lazy evaluation (Smug Lisp Weenies)
> who say that this means D doesn't *really* support it. My point: by
> using the same typeless syntax that dynamically typed languages use, it
> appeals much more to fans of those languages.
>
>
>
> I think that an unmodified syntax is the best approach from a niceness
> point of view, and if the language were being designed afresh, I would
> go for that and ban nameless parameters, since I've already said they
> are hardly useful.
>
> However, given that we are not starting afresh, there may be some code
> out there which uses nameless parameters. I would guess that that code
> doesn't appear much, and the only places I can imagine it being is in
> interfaces and in extern declarations. Since interfaces can't have
> templates, this would be flagged as an error at compile-time, making it
> easy to find and solve. For extern declarations, I don't know whether
> templates are permitted, so this *may* cause a problem.
>
> Thoughts, anyone?
>
> Cheers,
>
> Reiner
More information about the Digitalmars-d
mailing list