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.

Writing code for both computers and humans

49 pointsby pfrrpover 1 year ago

4 comments

jinwoo68over 1 year ago
I don&#x27;t think what the author says is the intent of the code. isNaN() returns true not just for NaN but for anything that is &quot;not a number&quot;[1]. For example, it returns true for things like &quot;hello&quot;.<p>So it just canonicalizes everything that is not a number into NaN.<p>[1] <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;isNaN" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Refe...</a>
评论 #38229874 未加载
评论 #38231418 未加载
评论 #38226188 未加载
评论 #38229722 未加载
评论 #38231281 未加载
评论 #38230147 未加载
orn688over 1 year ago
I agree with the author that this is a reasonable way to indicate their intent. But I&#x27;ve seen so many accidentally ineffectual code snippets that if I saw this code I&#x27;d be inclined to delete it unless there was also a comment expressing its purpose.
评论 #38226186 未加载
rco8786over 1 year ago
I don&#x27;t know if that was the real intent of this code, considering all the weird nuance around NaN in Javascript - however I agree with the point the author makes, and will take it one step further:<p>We should be building these semantics directly into our languages, not relying on programmers to strictly follow a &quot;best practice&quot;. In this case, it would be making values non-nullable and baking in Result&#x2F;Option&#x2F;etc style types that force programmers into handling the null (or NaN) case.
lordwizover 1 year ago
This communicates an important idea, Well-written code is not only correct and efficient, but it is also readable, maintainable, and understandable to other programmers.<p>This culture should be encouraged more to make other developer&#x27;s life easier, The thing I do nowadays is that I would often switch perspectives now and then, When switching perspectives, if i become confused, i would work on making the code more meaningful.<p>Even if we are doing a solo project, if we come back to the code after a long while, the code should be greeting us with wide open hands rather than looking like an unexplored jungle.
评论 #38232550 未加载