Design of intuitive interfaces

KennyTM~ kennytm at gmail.com
Mon Feb 22 01:24:01 PST 2010


On Feb 22, 10 07:29, Ary Borenszweig wrote:
> KennyTM~ wrote:
>> On Feb 22, 10 06:07, Ary Borenszweig wrote:
>>> Michel Fortin wrote:
>>>> On 2010-02-21 10:19:06 -0500, bearophile <bearophileHUGS at lycos.com>
>>>> said:
>>>>
>>>>> Michel Fortin:
>>>>>> array.sort(predicate) // sort in place using predicate
>>>>>> array.sorted(predicate) // create sorted copy using predicate
>>>>>> array.isSorted(predicate) // tell if the array is sorted using
>>>>>> predicate
>>>>>
>>>>> Good.
>>>>>
>>>>> Another possibility is to let D2 accept ? and ! too inside variable
>>>>> names, so they can become (as in Ruby I think, and something similar
>>>>> is common in Lisp-like languages too):
>>>>> array.sort(predicate)
>>>>> array.sort!(predicate); // void function
>>>>> array.sorted?(predicate)
>>>>
>>>> Note that Ruby only accept this as a suffix, but yeah it's part of the
>>>> identifier.
>>>>
>>>> And I'd love this, but the ! suffix is totally ambiguous with the
>>>> template instantiation syntax, and the ? suffix would be ambiguous in
>>>> the ternary operator "?:".
>>>
>>> But ruby has the ternary operator "?:", it just gives the "?" in the
>>> identifier more precedence.
>>>
>>> So there's just the backwards compatibility problem, but if you had:
>>>
>>> foo? something : something_else
>>>
>>> then now it won't compile ("foo?" can't be found) and you'll have to
>>> change it to
>>>
>>> foo ? something : something_else
>>>
>>> so it's a safe backwards incompatible change.
>>
>> enum foo = false;
>> enum bar = 2;
>> ...
>> case foo?(1):bar: break;
>>
>> Suddenly, if "foo?" is defined, the value of the case completely
>> changed and you've got a "bar" label.
>
> Cases are known at compile-time.

The program is changed when you recompile. (The foo? function can be CTFE).

The point is it is an unsafe backward incompatible change.



More information about the Digitalmars-d mailing list