• I don't quite understand the question. The comma operator is a normal operator valid in any full Expression (13.16 ). It is historically descended from Algol68's semicolon operator, and (despite the different precedence) semantically related to JS's && operator. Like && it processes the left argument and returns the right; unlike && it voids the left argument and proceeds unconditionally. In fact, I suspect a, b could be defined (semantically) as !a < 2 && b or some such stupidity.

    Syntactically it has only one oddity, which is that it, like the bare assignment operator, is also used for other things, such as forming VariableDeclarationLists (14.3.2) and ArgumentLists (13.3), which means that there are places where the semantic expectation is an expression but the syntax restricts you to an AssignmentExpression to resolve the ambiguity of which kind of comma is expected.

    In any case, none of this has anything to do with the conditions in control constructs, which are uniformly and uncomplicatedly Expressions (14.6, 14.7.2.1, 14.7.3.1, 14.7.4, 14.7.5, 14.12).

    There's also no case to be made that it is a semantic restriction of Espruino or its debugging mechanism, since the semantically identical while ((0, 0)); parses and executes flawlessly. This is nothing but an issue with Espruino's internal grammar, as far as I can see, either a typo (I hope) or an utterly capricious decision to alter the syntax of while () while not even making the same change for if ().

    To the argument that this feature of the language is not pretty and adds confusion, all I can say is that today it was recommended to me that I replace
    search: while (…) while (…) if (…) break search; (which Espruino does not implement) with
    (() => {while (…) while (…) if (…) return;})();. It does not appear that prettiness and lack of visual confusion is the driving force behind this project(!). And, for goodness' sake, if you really hate the comma operator so passionately, why allow it in if and switch?

    Orthogonality and lack of bugs are generally considered virtues in the programming language community; I'm honestly not sure what's going on here. If it's that efficiency trumps usability, then what's the point of Espruino at all? C, or indeed assembly, is easy enough to write; I came here in the expectation that things would “just work” without too much hassle :-}.

  • it was recommended to me that I replace
    search: while (…) while (…) if (…) break search; (which Espruino does not implement) with
    (() => {while (…) while (…) if (…) return;})();

    I did not recommend that. I suggested real named function that would do the search and return the result that was found. Didn't see whole code so maybe it does not fit well. The idea was to split larger complex code into smaller functions for better readability and possibly also reusability.

    It does not appear that prettiness and lack of visual confusion is the driving force behind this project

    Well, I find your original code with label and break already visually confusing and not pretty :-)

About

Avatar for fanoush @fanoush started