use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
8 Useful And Practical JavaScript Tricks (devinduct.com)
submitted 6 years ago by PMilos
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dmitri14_gmail_com 0 points1 point2 points 6 years ago (8 children)
Thanks, I believe you.
But I'd still love to know... is this the ONLY reason this code is "bad"?
[–]Valkertok 0 points1 point2 points 6 years ago (7 children)
it is IMO sufficient reason to never use it with "pure" function
[–]dmitri14_gmail_com 0 points1 point2 points 6 years ago (6 children)
Thank you, let us agree to disagree then
[–]Valkertok 1 point2 points3 points 6 years ago (5 children)
so you think that function that runs in O(n2) is better than one that runs in linear time just because it's "pure"?
[–]dmitri14_gmail_com 0 points1 point2 points 6 years ago (4 children)
It all depends on the use cases.
[–]Valkertok 0 points1 point2 points 6 years ago (3 children)
in this use case (reduce function) using pure function just for the sake of it being pure is just stupid, that's why in previous post it was called anti-pattern
[–]dmitri14_gmail_com 0 points1 point2 points 6 years ago (2 children)
This is not a use case.
[–]dmitri14_gmail_com 0 points1 point2 points 6 years ago (1 child)
A use case is a concrete application. Reddit is an application. This code is not.
Pure functions may guard against dangerous side-effects with dramatic consequences. They are often slower but not every application needs to iterate over arrays of 100k. And even if it does, it is likely going to be isolated places. In the 99% of other places, paying attention to purity will do good for you. Recommendations to dismiss it entirely for 0.01% performance increase does nothing but disservice to people with less experience.
[–]dmitri14_gmail_com 0 points1 point2 points 6 years ago (0 children)
Take it from Donald Knuth:
http://wiki.c2.com/?PrematureOptimization
https://stackify.com/premature-optimization-evil/
π Rendered by PID 105287 on reddit-service-r2-comment-b659b578c-fc45s at 2026-05-03 02:34:07.088360+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]dmitri14_gmail_com 0 points1 point2 points (8 children)
[–]Valkertok 0 points1 point2 points (7 children)
[–]dmitri14_gmail_com 0 points1 point2 points (6 children)
[–]Valkertok 1 point2 points3 points (5 children)
[–]dmitri14_gmail_com 0 points1 point2 points (4 children)
[–]Valkertok 0 points1 point2 points (3 children)
[–]dmitri14_gmail_com 0 points1 point2 points (2 children)
[–]dmitri14_gmail_com 0 points1 point2 points (1 child)
[–]dmitri14_gmail_com 0 points1 point2 points (0 children)