Designing a consistent language is *very* hard

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Apr 28 11:10:17 PDT 2012


On Sat, Apr 28, 2012 at 06:19:44PM +0200, David Nadlinger wrote:
> On Saturday, 28 April 2012 at 15:43:52 UTC, H. S. Teoh wrote:
> >IMNSHO, *any* language that has === is fundamentally, irreparably
> >dainbramaged, and needs to be scrapped and redesigned from scratch.
> 
> Well, in D we have "is", so… (/me ducks)
[...]

To be frank, I find the various syntaxes of 'is' very inconsistent and
jarring. It has elicited several WATs from me while learning D. There's
no question that the various *uses* to which the syntax has been
assigned is extremely useful, but the syntax itself could do with a
redesign.

I mean, first you have:

	is(A==B)	is the type A is equal to the type B

If it were up to me, I'd have used instead the syntax:

	A==B

since, after all, A and B are already known to be types.

Then you have:

	is(A : B)	is the type A implicitly convertible to B

OK, not the best thing, but at least type comparisons are consistently
done in is() syntax, so it's partly palatable. Using : for implicit
convertibility is questionable, but at least there's an analogy with
base class syntax. So OK.

But then:

	is(A B)		if type A is a valid type, alias it to B

WAT? There's absolutely no correspondence between this syntax and the
previous two cases. NOBODY reading this code would be able to guess its
meaning unless they have already learnt the syntax. (Nobody would guess
what that piece of PHP code does unless they have already memorized its
meaning.)

Worse, you have:

	is(A B : C[D])	if type A is the same as (or is a subclass of)
			some kind of associative array

OK, there's no doubt the *meaning* of this construct is extremely
useful, but seriously, the syntax is just as bad as PHP's predisposition
to unexpected exceptions to arbitrary rules.

Then you have the overload of 'is' to mean a pointer comparison
operator:

	A is B		if A and B point to the same thing

This I can accept, since with D's implicit pointer deferencing, you'd
expect == to compare values, so when you want to compare identity (i.e.
are these two references pointing to one and the same thing?) you do
need a different syntax for it.

But the overload of 'is' as an operator with 'is()' as an expression
(and its various ugly arbitrarily assigned syntaxes)? WAT.

Seriously, one of the first things I'd like to see in D3 is a complete
overhaul of is(). I say again, the various *semantics* of it are
extremely useful, and are part of what makes D rock so much. But the
*syntax* badly needs a total redesign. We need much saner syntax
assigned to each of the current uses of is(), that doesn't look like it
was grafted in from a PHP development branch.


T

-- 
Life is unfair. Ask too much from it, and it may decide you don't
deserve what you have now either.


More information about the Digitalmars-d mailing list