Re:Writing code for both computers and humans
by orn688 on Friday November 10, 2023 @06:49PM
(#38226107)
I agree with the author that this is a reasonable way to indicate their intent. But I've seen so many accidentally ineffectual code snippets that if I saw this code I'd be inclined to delete it unless there was also a comment expressing its purpose.
[ Parent
| on HN ]
Re:Writing code for both computers and humans
by HuangYuSan on Friday November 10, 2023 @07:03PM
(#38226186)
And a comment on its own would be enough anyway
Re:Writing code for both computers and humans
by earthboundkid on Friday November 10, 2023 @07:34PM
(#38226387)
Yeah, ideally you’d have some kind of static typing to restrict the code to only use Number, and then a comment that says what the function does in case of NaN.
Re:Writing code for both computers and humans
by carapace on Saturday November 11, 2023 @10:18AM
(#38231037)
Yeah!
There was a thread the other day about a linter that flagged useless code and all the odd bugs it caught, and I think it would have flagged this snippet, eh?
"Interesting bugs caught by no-constant-binary-expression"
https://news.ycombinator.com/item?id=38196644
https://eslint.org/blog/2022/07/interesting-bugs-caught-by-n...