
Chrome 80 stable has a regression with Array.reduce that affects Angular - m_tremblay
https://bugs.chromium.org/p/chromium/issues/detail?id=1049982
======
Lx1oG-AWb6h_ZG0
I used to love using array.reduce when I was first learning JavaScript, but
over the years, my opinion has firmly shifted to Jake Archibald’s:

“All code using array.reduce should be rewritten without array.reduce so it's
readable by humans.

Ok ok, fair enough, there are cases where array.reduce is the best thing to
use.

Specifically, cases where you want to look really smart and don't care about
readability.”

[https://mobile.twitter.com/jaffathecake/status/1213077702300...](https://mobile.twitter.com/jaffathecake/status/1213077702300852224?lang=en)

Seriously, even the simplified repro example in the bug is not immediately
obvious - I can only imagine how bad the actual code is.

~~~
perceptronas
That is why learning programming languages is important. I would argue this
concept is picked from functional ones. `reduce` function is not hard to read
if you understand how it works and code is a lot easier to read because it
does not introduce mutability. Even better - it has almost the same signature
in other languages so you only need to learn it once.

~~~
codedokode
I always forget the order of arguments and what they mean. For me it is an
awful function that should not exist.

~~~
beatgammit
Isn't the solution there to name variables well?

A reduce function turns an array into a single value, passing the result of
computation of each element to the next element. So, the signature is:

function (accumulator, element) -> accumulator

So, you take in some accumulated value (or the initial value on the first
iteration) and an element and return the accumulated value to the next
element. If the values were swapped, it would be inconsistent with the rest of
the array functions where optional arguments are tacked on to the end (e.g.
index, array), so the obvious assumption is that the accumulator goes in front
to keep the rest of it as similar to the other array functions as possible.

I think it's unfortunate that array.reduce takes the accumulator after the
function, but that also makes sense since it's technically valid to omit the
accumulator (defaults to undefined).

The problem, I think, is that reduce is often abused when another function
might make more sense (e.g. as a ghetto "find" or something). If it's used
properly, I think it's quite elegant. If it's not, it's a confusing mess.

------
londons_explore
Looking at the comments on this bug, I'm pretty impressed with the Chrome
teams response.

Sure, it's bad that this made it into a release in the first place, but when
it did, they were quick to identify the issue, halt the release, find 2
potential fixes, manually test the fix, get a canary release out to get wider
testing, update the test bench to prevent this class of bug happening again,
and start rollout to the public stable build.

All that across tens of team members, with regular status updates from humans
and bots, and despite the fact no bug reporter could give them a proper repo
testcase for a long time.

------
_bxg1
Ouch. Doubly embarrassing since Angular is developed by Google.

~~~
pjmlp
I doubt it, you just need to experience Android development for a while, and
their "stable" releases.

------
darepublic
Weird that the title includes Angular it's just a regression with
Array.protoype.reduce that could naturally effect any JS framework

