An inconvenient truth

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Oct 8 07:49:49 PDT 2008


Denis Koroskin wrote:
> On Wed, 08 Oct 2008 18:09:52 +0400, Aziz K. <aziz.kerim at gmail.com> wrote:
> 
>> On Wed, 08 Oct 2008 14:21:02 +0200, Andrei Alexandrescu 
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>> Walter discovered a showstopper for the curls.
>>>
>>> class A : B
>>> {
>>> }
>>>
>>>
>>> Andrei
>>
>> How about if we leave the current syntax as it is and introduce an 
>> alternative syntax using Unicode mathematical letters?
>> Here's a template function using the Unicode angle brackets "〈〉":
>>
>> template ToString〈ulong U〉
>> {
>>      static if (U < 10)
>>     const char[] ToString = "" ~ cast(char)(U + '0');
>>      else
>>     const char[] ToString = ToString〈U / 10〉 ~ ToString〈U % 10〉;
>> }
>>
>> The advantages:
>>
>> *) Programmers can still use the normal ASCII template instantiation 
>> syntax.
>> *) The new syntax doesn't create any grammar ambiguities.
>> *) More potential converts from the C++ world.
>>
>> The disadvantages:
>>
>> *) Using the angle brackets would require some effort, although smart 
>> editors could alleviate this problem if it detects that an identifier 
>> is a template or if you specify a macro that turns <- into 〈 and -> 
>> into 〉.
>> *) Practically any font I tried in kwrite/kate didn't render the angle 
>> brackets at all and instead showed a rectangular box. Interestingly 
>> enough a few other special Unicode mathematical characters are 
>> rendered correctly.
>>
>> Here is a nice page of all mathematical Unicode characters: 
>> http://tlt.its.psu.edu/suggestions/international/bylanguage/mathchart.html 
>>
> 
> There are also ‹ and ›, that are much cutier than yours!
> They also have a benefit that most of the fonts I've checked do support 
> them *and* you can type them using Alt+0139 and Alt+0155 hotkeys (i.e. 
> no copy-paste or special keyboard layouts needed) :)
> 
> template reduce(F...)
> {
>     NxNHelper!(F).For!(Args).Result reduce(Args...)(Args args)
>     {
>         alias NxNHelper!(F).For!(Args) Aux;
>         ...
>     }
> }
> 
> now becomes:
> 
> template reduce(F...)
> {
>     NxNHelper‹F›.For‹Args›.Result reduce(Args...)(Args args)
>     {
>         alias NxNHelper‹F›.For‹Args› Aux;
>         ...
>     }
> }
> 
> P.S. Hotkeys may be different on your system, check the Character Map 
> utility that comes with Windows for right hotkeys. Their codes are 
> U+2039 and U+203A.

Unicode characters would be great and quite innovative. My personal 
choice is the chevrons Foo«Bar» which are easily distinguished visually 
from ASCII symbols and also easy on the eyes. But I never thought of it 
as an either-or choice, only as an alternate. I mean, requiring special 
editor support or typing Alt+171 whenever it comes about templates will 
do nothing in their favor. So an ASCII-only syntax that's also palatable 
is a must.

It's fairly easy to add editor support such that whenever you type e.g. 
"Foo!(", that morphs into "Foo«»" and places the cursor inside the quotes.

I only have a source of worry. This is to some extent a bet - how sure 
can we be that today's and tomorrow's editors will display Unicode 
characters properly? In fact I was expecting things to be a lot worse. 
All editors I tried in both Unix and Windows displayed the chevrons 
properly (beautifully in fact). Even command-line programs such as less 
and cat had no problem. Could people try the chevrons with various 
editors and report their experience here?

Anyhow, this segment of the discussion is somewhat orthogonal to the 
rest of it as I think we all agree a Unicode notation will be an 
alternative, not an exclusive choice for template instantiations.


Andrei



More information about the Digitalmars-d mailing list