(non)nullable types

Yigal Chripun yigal100 at gmail.com
Sat Feb 14 12:35:19 PST 2009


Nick Sabalausky wrote:
> "Yigal Chripun"<yigal100 at gmail.com>  wrote in message
> news:gn771i$ded$1 at digitalmars.com...
>> Besides, such a change will allow us to remove the ugly ?: operator and
>> will free the ? sign.
>>
>
> I like the ?: operator :-). It's short. But I agree it might be worth
> switching to an expression "if...else..." if that meant we could do the
> following...
>
>> One of my favorite Ruby features (besides Blocks) is that Ruby allows
>> using ? and ! as part of identifiers. This is used in Ruby by convention
>> to represent methods that answer questions, and methods that are more
>> "dangareous" like in-place modification of data.
>>
>> so you can write:
>> if (range.more?) ..
>
> When I was looking into Ruby, I was impressed by this too. I had always
> liked MS's convention of prepending "is" to flags, but that only works on
> certain flags (sometimes you really mean "has" or "exists" or "capable of"
> something else besides "is"). Appending "?" is much more general.
>
>> and it also has array.sort vs. array.sort! where the former gives a sorted
>> copy and the latter sorts in-place.
>
> It would be kind of handy to have a nice simple convention for in-place vs
> non-inplace functions. Obviously "!" wouldn't work for D though, unless we
> were masochistic enough to revisit the old "What syntax to use for
> templates?" issue.
>
>
well, IMO there are better syntax options for templates but I doubt it 
if it'll ever change, I remember that long thread about this very subject..
there's another way to mark in-place vs. copy which I don't like as much 
- I think it's used in Python:
array.sort vs. array.sorted
where the first form is in-place and the other is a copy. the convention 
is to use adjectives for copies - if you say array.sort (with a verb) 
you actually sort the *current* array.
this is more fragile IMO than just using a "!" since you need to be 
familiar with English grammar. (for non-native English speakers that can 
be an issue)
e.g:
egg.rot vs. egg.rotten, etc..





More information about the Digitalmars-d mailing list