shouting versus dotting

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Oct 4 21:50:47 PDT 2008


Alexander Pánek wrote:
> Andrei Alexandrescu wrote:
>> 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.
>>
>> That's why I find the choice of "!" poor. I believe it can impede to 
>> some extent acquisition of templates by newcomers, and conversely I 
>> believe that using .() can make templates more palatable. I tried 
>> using ".()" in my code and in only a couple of days it looked and felt 
>> way better to me. Based on that experience, I suggest that "!()" is 
>> dropped in favor of ".()" for template instantiation for D2.
>>
>> Sean's argument that "The exclamation mark signifies an assertion of 
>> sorts" is exactly where I'd want templates not to be: they should be 
>> blended in, not a hiccup from normal code. Serious effort has been, 
>> and still is, made in D to avoid shell-shocking people about use of 
>> templates, and I think ".()" would be a good step in that direction.
> 
> Sean has a point. Templates are not runtime constructs. So a clear 
> distinction between instantiating a function with a given type and just 
> calling a function that has fixed argument types and a fixed return type 
>  is necessary.

Why? This sounds objective, so you better back it up. Au contraire, I 
see absolutely, but absolutely no need for a distinction. If it weren't 
for syntactic difficulties, to me using straight parentheses for 
template instantiation would have been the perfect choice. (How many 
times did you just forget the "!"? I know I often do. Why? Because most 
of the time it's not even needed.)

> The exclamation mark gives us this clear distinction and 
> has served well in terms of readability for me, especially because it 
> jumps out — not because it’s an exclamation mark, thus having a meaning 
> in natural language, but rather just because of its form. A straight 
> vertical line with a dot underneath it. That just works perfectly well 
> as seperator between identifier/type and type argument.

I believe the clear distinction is not only unnecessary, but 
undesirable. We should actively fight against it.

> Also, you might want to consider changing your font if exclamation marks 
> jump at you so intensively. ;)

I use Vera, probably the best code font I've ever had.


Andrei



More information about the Digitalmars-d mailing list