Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Understanding && Date: Sat, 17 Apr 2021 23:04:21 +0100 Organization: A noiseless patient Spider Lines: 53 Message-ID: <875z0kbmai.fsf@bsb.me.uk> References: <87wnt2e06e.fsf@bsb.me.uk> <87mttydm95.fsf@bsb.me.uk> <21031565.EfDdHjke4D@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="cebc7205e7af165aaf5b3baa2f235ea5"; logging-data="30567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fD/p7e4nPDBzHZQLUCAUCrm9kurTfaDc=" Cancel-Lock: sha1:KBQue4Cl9VTIcC7pMJzFDH4ej4s= sha1:MsSPKyVanNTs5fzxoi4D+F8SVDA= X-BSB-Auth: 1.08639171bfd589a1503b.20210417230421BST.875z0kbmai.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:39967 Thomas 'PointedEars' Lahn writes: > Ben Bacarisse wrote: > >> Jon Ribbens writes: >>> On 2021-04-16, Ben Bacarisse wrote: >>>> Jon Ribbens writes: >>>>> You most often see this sort of thing in JavaScript that was >>>>> automatically generated by a compiler (either because the original >>>>> source was in something else like TypeScript or a more modern version >>>>> of JavaScript or because the author wanted to compress/minify the >>>>> script), but human beings are also quite capable of writing >>>>> hard-to-read code like this. >>>> >>>> Is that specifically when the right-hand operand is an assignment >>>> expression? I don't find that hard to read but then I'm used to >>>> assignment being and expression so it seems like a natural extension of >>>> the more frequently seen uses of &&. >>> >>> I mean where it's an expression being abused as a control flow >>> mechanism. >> >> If readability is not the problem I'm not sure what constitutes abuse. > > To begin with: One is a *statement*, the other an *expression*. It's not clear what you are referring to. There have been both expressions and statements posted, so we could just pick some examples and assume that's what you are referring to, but it's an odd remark to begin with. No one in the discussion is a beginner. > Those are > two different kinds of token in a programming language (certainly in > ECMAScript implementations). Neither is a token in ECMAScript. > Also, such code easily makes newcomers think that > > a && b || c > > would be equivalent to > > if (a) b; else c; I don't think there's much you can do for people like that. These two are so obviously not equivalent that someone who might think they are can't be helped by banning or deprecating certain uses. Even the newest newcomer should know the difference between an expression and a statement. -- Ben.