Guards are now ready for discussion (was: Nov 18 notes)

Brendan Eich brendan at
Mon Nov 22 11:12:36 PST 2010

On Nov 22, 2010, at 10:58 AM, P T Withington wrote:

> On 2010-11-22, at 13:13, Brendan Eich wrote:
>> That, plus the relative rarity of annotated initialisers (in my best guess -- we can argue about this or try to estimate by adding guards to existing code), make me still favor (2).
> The idea of guards as "adjectives" (ala C) is a non-starter?

That is awkward if you do require a leading var/let/const in addition to the annotation:

  var Int32Like i = 0;

and we don't want to reserve the names of all possible guards.

Also, guards or runtime types are not static types, so it seems better to avoid reusing type declarator order from static languages in the C family.

Functions are easier to extend this way:

  function foo(MyGuardA a, MyGuardB b) GuardForReturnValue { ... }

but the point about not copying type-then-declarator stands.

> Would keyword arguments ever be added to JS?  Any chance that would influence the choices made here?

Imponderable unless we reserve : in call expressions such as

foo(arg1: val1, arg3: val3);

to mean named formal parameter association -- keyword arguments if I understand what you meant by that. Yet this is both too close to an object initialiser, and also not ambiguous with annotations in declarations. This is an expression, not a declaration.


More information about the es-discuss mailing list