Re:Second-Guessing the Modern Web
by jwells89 on Thursday September 21, 2023 @08:51PM
(#37606520)
What makes it weird for me is the filter/map/etc with an implicit destination, since function chains like that usually get rolled into a variable. It'd get you a compiler warning in Swift or Kotlin ("Result of call to 'map' is unused", etc). Agree that a for loop reads better in this case.
[ Parent
| on HN ]
Re:Second-Guessing the Modern Web
by jakelazaroff on Thursday September 21, 2023 @09:00PM
(#37606569)
I suppose that depends on whether you look at it as a templating DSL within a JavaScript expression, or expressions within a templating language.
A `for` loop doesn't really make sense from the JS expression viewpoint — `for` loops in JS are statements, and in languages that do treat them as expressions they usually evaluate to the last iteration of the loop. From there, the filter/map makes more sense, since it's an expression that evaluates to an array of template-y stuff.
If you see it primarily as a templating langauge, though, the `for` loop makes way more sense — every iteration, it's adding a string to the template.