Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Parentheses phobia strikes again. This is 1 character longer than an IIFE (since you replace "()" with "run"


i'd say that it's a bit more readable:

  run(() => { return foo })
looks better than, and assuming pre-existing knowledge of what `run` does, is more understandable than

  (() => { return foo })()
but this is also a fairly contrived example


I agree that `run()` is more readable than an IIFE if you remove all context and history from the analysis. But the IIFE is a well-known idiom to JavaScript programmers, so readers will not have to pay a cognitive "what is `run()` do?" penalty in order to understand the code.

New abstractions have a cost, and "clever" abstractions tend to confuse the average developer more than the benefit they provide.

If there's a problem with an IIFE (yes, they can be abused), the usual approach is to replace it with a named function definition. This works in their React example as well--rather than (necessarily) creating a new component as they suggest, the standard approach is to add a named rendering helper in the function closure that returns JSX.


Yes, I do think the extra parens are less readable.

Its not about number of characters, its about reasoning that the inline function that you just wrapped in parens is then called later, potentially after many lines. At least with `run` it's immediately clear based on the name that you are running the function.

Edit: This is pretty funny. I'm a parensaphobe! (not really) https://www.reddit.com/r/ProgrammerHumor/comments/qawpws/the...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: