Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39956
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Understanding && |
| Date | 2021-04-17 02:01 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87o8edd8qk.fsf@bsb.me.uk> (permalink) |
| References | (1 earlier) <slrns7ishn.4j8.jon+usenet@raven.unequivocal.eu> <87wnt2e06e.fsf@bsb.me.uk> <slrns7jb5v.4j8.jon+usenet@raven.unequivocal.eu> <87mttydm95.fsf@bsb.me.uk> <slrns7jv2m.4j8.jon+usenet@raven.unequivocal.eu> |
Jon Ribbens <jon+usenet@unequivocal.eu> writes:
> On 2021-04-16, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>>> On 2021-04-16, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>>>> Jon Ribbens <jon+usenet@unequivocal.eu> 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.
>
> You snipped the next lines of my post where I said that readability
> *is* the problem.
Oh, sorry. The fact that you didn't address my questions about
readability made me think you were now making a broader point. If you
don't mind, can say if the problems you have with its readability is
down to there being an assignment on the right, or is it with any use of
&& that relies on the short-circuit evaluation.
>> Is it just a rule of yours to keep these two things entirely separate?
>
> It's not a rule of mine, it seems to be a rule of almost everyone.
The trouble is that a non-trivial number of languages have this form,
and I've seen it used quite widely. But maybe most of the uses don't
rise to your standard of abuse. I've not come across the rule, but then
it's a long time since I worked anywhere that had rules about
programming.
>> Maybe some uses are acceptable and don't constitute abuse? Is any
>> reliance on short-circuit evaluation in an expression an abuse?
>
> No, of course not. I think it's "abuse" because it's written to look
> like an expression but it isn't, really - we don't care about its
> result, we only care about its side-effects.
Ah, right. So the abuse (as you see it) is not exactly the control flow
but using it to control side-effects.
I've seen (and, dare I say, written) code that uses the result. I
wonder if that absolves the programmer from the charge of abuse:
return (data = parse_input(file_name))
&& (result = transform(data))
&& write_file(file_name);
<cut>
>> I only suggested that assignment might be where it crosses the line for
>> you because I think that's where the line is for a lot of people, but it
>> sounds like go further than that.
>
> Maybe it is there. Fundamentally the issue is that if you're going to
> sacrifice readability, you'd better be getting something good in return.
> In the case we're talking about some readability has been sacrificed and
> we've gained absolutely nothing in return - the code isn't shorter, or
> neater, and it doesn't run faster.
I don't have any problem with the readability, in general. Obviously
you can make unreadable examples, but I not a fan of rules than ban
something because of the potential for abuse.
--
Ben.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Understanding && Andrew Poulos <ap_prog@hotmail.com> - 2021-04-16 14:30 +1000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-16 11:00 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-16 11:17 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-16 16:09 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-16 15:26 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-16 21:09 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-16 21:06 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-17 02:01 +0100
Re: Understanding && The Natural Philosopher <tnp@invalid.invalid> - 2021-04-17 08:33 +0100
Re: Understanding && John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-17 12:06 +0100
Re: Understanding && The Natural Philosopher <tnp@invalid.invalid> - 2021-04-17 14:13 +0100
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-17 15:50 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-17 15:21 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-17 23:46 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-17 23:46 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-18 23:59 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-19 13:56 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-19 23:08 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-19 22:52 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-20 01:23 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-20 01:08 +0000
Re: Understanding && Arno Welzel <usenet@arnowelzel.de> - 2021-04-18 00:49 +0200
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-18 17:26 +0100
Re: Understanding && Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-17 17:05 +0200
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-17 23:04 +0100
Re: Understanding && Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-18 00:48 +0200
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-18 17:13 +0100
Re: Understanding && Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-19 21:58 +0200
Re: Understanding && John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-18 18:20 +0100
Re: Understanding && Arno Welzel <usenet@arnowelzel.de> - 2021-04-18 00:40 +0200
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-18 00:14 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-18 00:01 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-18 17:44 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-18 17:51 +0000
Re: Understanding && Arno Welzel <usenet@arnowelzel.de> - 2021-04-19 13:41 +0200
Re: Understanding && John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-19 15:02 +0100
Re: Understanding && The Natural Philosopher <tnp@invalid.invalid> - 2021-04-20 17:40 +0100
Re: Understanding && John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-20 18:19 +0100
Re: Understanding && The Natural Philosopher <tnp@invalid.invalid> - 2021-04-21 10:11 +0100
Re: Understanding && John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-21 19:46 +0100
Re: Understanding && The Natural Philosopher <tnp@invalid.invalid> - 2021-04-22 13:48 +0100
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-19 21:28 +0100
Re: Understanding && Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-04-19 21:56 +0000
Re: Understanding && Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-19 23:13 +0100
csiph-web