unsigned policy

Bruno Medeiros brunodomedeiros+spam at com.gmail
Mon Feb 12 07:10:42 PST 2007


Andrei Alexandrescu (See Website For Email) wrote:
> Henning Hasemann wrote:
>> I know this is a more general questions as it applies to C and C++ as 
>> well,
>> but somewhere I have to ask and actually D is what Im coding in:
>>
>> Should one try to use uint in favor of int whenever one knows for sure 
>> the value
>> wont be negative? That whould be a bit more expressive but on the 
>> other hand
>> sometimes leads to type problems.
>> For example, when having things like this:
>>
>> T min(T)(T a, T b) {
>>   return a < b ? a : b;
>> }
>>
>> Here you whould need to ensure to cast values so they share a common 
>> type.
>>
>> How do you code? Do you use uint whenever it suitable reflects the 
>> data to
>> store (eg a x-y-position on the screen) or only when necessary?
> 
> Current D botches quite a few of the arithmetic conversions. Basically 
> all conversions that may lose value, meaning, or precision should not be 
> allowed implicitly. Walter is willing to fix D in accordance to that 
> rule, which would yield an implicit conversion graph as shown in:
> 
> http://erdani.org/d-implicit-conversions.pdf
> 

By the way, do you think bool should be implicitely convertible to a
numeric type? Such that this preciousness is allowed in D:

   if( true == 2 ) writeln("THEN");

and the "then" clause is not executed.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list