shouting versus dotting
Chris R. Miller
lordsauronthegreat at gmail.com
Sun Oct 5 17:57:31 PDT 2008
Ary Borenszweig wrote:
> Andrei Alexandrescu escribió:
>> The problem I see with "!" as a template instantiation is not
>> technical. I write a fair amount of templated code and over years the
>> "!" did not grow on me at all. I was time and again consoled by Walter
>> than one day that will happen, but it never did. I also realized that
>> Walter didn't see a problem with it because he writes only little
>> template code.
>>
>> I didn't have much beef with other oddities unique to D. For example,
>> I found no problem accommodating binary "~" and I was wondering what
>> makes "!" different. I was just looking at a page full of templates
>> and it looked like crap.
>>
>> One morning I woke up with the sudden realization of what the problem
>> was: the shouting.
>>
>> In C, "!" is used as a unary operator. That may seem odd at first, but
>> it nevers follows a word so it's tenuous to associate it with the
>> natural language "!". In D, binary "!" _always_ follows a word, a
>> name, something coming from natural language. So the conotation with
>> exclamation jumps at you.
>
> I was thinking about in which other way templates could be specified...
> Most of the other symbols already have a meaning as binary operator. And
> it also would be nice to have an opening and closing symbols, like <> in
> Java, C++, etc.
I remember reading that Walter specifically rejected that idea because
it became ambiguous with bitshift operations. In my time with Java, I
saw many of these:
public class Foo<Bar<o extends ArrayList>> { ... }
When instantiated in code the >> at the end of the template declaration
does become very ambiguous with a bitshift.
> Can't {} be used for that? For example:
>
> List{int} someList;
>
> void foo{T}(T val) {
> }
>
> It seems more quiet. :-)
I rejected that idea when I was searching for counterproposals because
it conflicts with the code-block syntax. The existing () is much less
ambiguous, since when you encounter two sets of parenthesis it must be a
template. If it were multiplication it would require the explicit *
binary operator.
The !() syntax seems to serve only as a heads up that it's a template.
Otherwise (as far as I can tell) a simple foo(int)(bar, baaz) would work
just as well as foo!(int)(bar, baaz).
More information about the Digitalmars-d
mailing list