Consistency in The Negative Result Values Through Expansion of null's Role

Andreas Rossberg rossberg at google.com
Tue Aug 21 02:41:15 PDT 2012


On 20 August 2012 18:41, Brendan Eich <brendan at mozilla.org> wrote:
> This loop could indeed test
>
>   while ((i = s.indexOf('  ', j)) !== undefined) ...
>
> That is unsightly, overlong, and contrived, but never mind.

I suppose we have to agree to disagree then. Index = undefined
naturally reads as "not present" to me, whereas the purpose of "index
>= 0" isn't particularly obvious. So, familiarity bias aside, I
actually find the latter far more contrived.


> Sorry, missed my off by one at the end (morning coffee not strong enough!).
>
> Try this:
>
> var s = "a bbb cccc ddddd\n"
>
> var i, j = 0;
> var a = [];
> do {
>     i = s.indexOf(' ', j);
>     print(j, i);
>
> } while ((j = i + 1) != 0);
> print(a + '!');

Hm, something seems to be missing in the correction you pasted.

Anyway, you sort of made my point :).  Because in my experience, one
problem with "useful" sentinels is that they encourage "clever", i.e.,
hard to read code, and by extension, buggy code. The gain in
conciseness, OTOH, usually is both rare and minor.


> Also, the monotyped approach is easier to optimize, all else equal. See
> http://qfox.nl/weblog/265 for testimony about this (find "JIT mixed
> messages").

That's a fair point, although one that shouldn't prematurely affect
language design.

Anyway, all this isn't particularly relevant for ES right now, so I'm
happy to let it rest.

/Andreas


More information about the es-discuss mailing list