TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Is arrow code sometimes unavoidable?

2 pointsby Jigsyalmost 2 years ago
So a while back I changed my awful coding habits to &quot;if (!true) { return } ...&quot; after reading a post about &quot;flattening arrow code.&quot;<p>But it got me wondering about conditions with multiple instances such as: &quot;if (true) { if (!true) { return } ... }&quot;<p>Is arrow code sometimes unavoidable? Or should I be setting flags for everything?

2 comments

ubermanalmost 2 years ago
I always try to use guard code to quick return, but I also find no rule is absolute. If a guard makes your code easier to write and understand then use it. If you feel like you are doing gyrations to place a guard then it might not make sense.
JohnFenalmost 2 years ago
I have a general opinion about this sort of thing: no programming pattern is always bad or always good. Even gotos are not always harmful.<p>The important thing is clarity of code. If arrow code makes that part of the code easier to understand and less likely to lead a future dev (who may be you!) to make a mistake, then it&#x27;s a good thing.<p>If setting flags makes that code easier to understand and less likely to lead a future dev to make a mistake, then that&#x27;s a good thing.<p>It all depends on the project, and has to be balanced with a consistent approach also being a good thing. If flags are used everywhere else, then use them even if arrow code would be more clear for a given section, and vice versa. This is the purpose for &quot;house rules&quot; about coding style, and such house rules are usually the best way to go.<p>My TL;DR is: anytime someone says that &quot;X is always good&quot; or &quot;X is always bad&quot;, that person is wrong. X may <i>usually</i> be good or bad, but there are always exceptions.
评论 #37169220 未加载