News for hackers. Stuff that matters.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by khaledh on Tuesday March 11, 2025 @02:23PM (#43335520)
That's not true. The lambdas used in the functional version are each called once for every item in the list.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by stouset on Tuesday March 11, 2025 @02:45PM (#43335724)
No sane optimizer is going to emit the functional code as a gajillion function calls.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by tvier on Tuesday March 11, 2025 @02:59PM (#43335873)
Yeah, if you treat it as javascript vs python they're likely correct (I'm not that familiar with js). The article and original comment were about function vs imperative though, so I assumed half decent runtimes for both.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by khaledh on Tuesday March 11, 2025 @02:59PM (#43335865)
True, but now you're relying on a specific implementation and optimization of the compiler, unless the language semantics explicitly say that lambdas will be inlined.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by stouset on Tuesday March 11, 2025 @03:03PM (#43335914)
This is true of literally anything and everything your compiler emits. In practice the functional style is much easier to optimize to a far greater degree than the imperative style.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by tvier on Tuesday March 11, 2025 @03:10PM (#43335977)
This is why you shouldn't get into arguments about performance on the internet without highly specified execution environments.

I'm going to take my own advice and go back to work :)

Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by Spivak on Tuesday March 11, 2025 @04:36PM (#43336753)
It's not? How could that possibly work when the lambda could throw and it could throw on the nth invocation and your stack trace has to be correct?

If I run this in the JS console I get two anonymous stack frames. The first being the console itself.

    [1, 2, 3].filter(x => [][0]())