Implicit enum conversions are a stupid PITA
Walter Bright
newshound1 at digitalmars.com
Thu Mar 25 02:55:35 PDT 2010
yigal chripun wrote:
> here's a simple version without casts: int toString(dchar[] arr) { int temp =
> 0; for (int i = 0; i < arr.length; i++) { int digit = arr[i].valueOf - 30; //
> * if (digit < 0 || digit > 9) break; temp += 10^^i * digit; } return temp; }
>
> [*] Assume that dchar has a valueOf property that returns the value.
>
> where's that mess of casts you mention?
In Pascal, you'd have type errors all over the place. First off, you cannot do
arithmetic on characters. You have to cast them to integers (with the ORD(c)
construction).
> Pascal is hardly the only language without excplicit casts.
Pascal has explicit casts. The integer to character one is CHR(i), the character
to integer is ORD(c).
> ML is also
> properly strongly typed and is an awesome language to use.
I don't know enough about ML to comment intelligently on it.
> The fact that D has 12 integral types is a bad design, why do we need so many
> built in types? to me this clearly shows a need to refactor this aspect of D.
Which would you get rid of? (13, I forgot bool!)
bool
byte
ubyte
short
ushort
int
uint
long
ulong
char
wchar
dchar
enum
More information about the Digitalmars-d
mailing list