Description
Dart syntax relies on keywords in many situations. For example:
class C<X extends B<X>> extends S with M<X> implements I, J {}
We could introduce punctuation based alternatives to some of the most frequently used keywords. The rationale would be that this is more concise, and it would very quickly be established as a notation for the given purpose. In other words, extends
might arguably be more self-explanatory than :
, but it won't take long before they are equally readable if we see them all the time.
One example of a language using punctuation for several of the elements shown above is Kotlin:
// Kotlin.
class C<X : B<X>> : S(), I, J {}
Kotlin uses :
to indicate that the following type is the bound of the type variable, and also to indicate that the supertypes of the class are specified (that is, an optional superclass which is extended, and zero or more interfaces which are implemented).
Dart cannot directly use the same syntax for superinterfaces because the superclass can be composite (consisting of a superclass and one or more mixins), and the implemented superinterfaces cannot be recognized by being interfaces (it can be an interface class
, but it can also be any other kind of class).
However, we could use two colons (one to replace extends
and the next one to replace implements
):
// Hypothetical Dart.
class C<X : B<X>> : S & M<X> : I, J {}
If a class implements something and doesn't specify a superclass then we'd have the two colons together: class A :: I {}
. Similarly, class A {}
means class A : Object {}
.
There are many other locations in Dart code where a similar thing could be done. For example, required
in a declaration of a named parameter could be written as !
(for example, immediately before the name of the parameter). Also Function
in a function type could be abbreviated (perhaps Fun
, or maybe a plain F
would do).
What do you think? The conciseness can be striking, but the punctuation based notation will surely be considered harder to read by some developers..