Implicit enum conversions are a stupid PITA
yigal chripun
yigal100 at gmail.com
Thu Mar 25 01:15:18 PDT 2010
Walter Bright Wrote:
> Nick Sabalausky wrote:
> > To put it simply, I agree with this even on mere principle. I'm convinced
> > that the current D behavior is a blatant violation of strong-typing and
> > smacks way too much of C's so-called "type system".
>
> You're certainly not the first to feel this way about implicit conversions.
> Niklaus Wirth did the same, and designed Pascal with no implicit conversions.
> You had to do an explicit cast each time.
>
> Man, what a royal pain in the ass that makes coding in Pascal. Straightforward
> coding, like converting a string of digits to an integer, becomes a mess of
> casts. Even worse, casts are a blunt instrument that *destroys* type checking
> (that wasn't so much of a problem with Pascal with its stone age abstract types,
> but it would be killer for D).
>
> Implicit integral conversions are not without problems, but when I found C I
> threw Pascal under the nearest bus and never wrote a line in it again. The taste
> was so bad, I refused to even look at Modula II and its failed successors.
>
> D has 12 integral types. Disabling implicit integral conversions would make it
> unbearable to use.
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?
Pascal is hardly the only language without excplicit casts. ML is also properly strongly typed and is an awesome language to use.
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.
More information about the Digitalmars-d
mailing list