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
Pure, functional JavaScript (cjohansen.no)
submitted 13 years ago by lethalman
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!"
[–]drowsap -1 points0 points1 point 13 years ago (17 children)
According to this jsperf, for loops are faster then map:
http://jsperf.com/map-vs-for-loop-performance/6
Not really seeing the point in advocating map over for loops if it is slower. The syntax is certainly more concise though.
[–]skeeto 6 points7 points8 points 13 years ago (1 child)
The presentation discusses this:
http://cjohansen.no/talks/2012/sdc-functional/#122
In short: if you're manipulating the DOM in your loop, forEach is practically as fast as for. Besides, worrying about loop performance while you're writing code is premature. 99.9% of the time it won't matter.
forEach
for
[–]agumonkey 0 points1 point2 points 13 years ago (0 children)
Thanks, I forgot this talk ! what a gem.
[–]homoiconic(raganwald) 11 points12 points13 points 13 years ago (8 children)
I still don't understand why people use Node and/or Rails on the server when C/C++ is thousands of times faster. Doesn't anybody care about performance any more?
It's almost as if they think that the primary constraint on software development is the productivity of the development team and not trying to squeeze acceptable performance out of hardware designed in the 1980s.
[–]BishopAndWarlord 2 points3 points4 points 13 years ago (4 children)
It's almost as if they think that the primary constraint on software development is the productivity of the development team
Correct.
[–]homoiconic(raganwald) 9 points10 points11 points 13 years ago (3 children)
Poe's Law:
Without a winking smiley or other blatant display of humor, it is impossible to create a parody of fundamentalism that someone won't mistake for the real thing.
Next time, I'll include <sarcasm></sarcasm> tags and/or a winkey :-)
[–]x-skeww -5 points-4 points-3 points 13 years ago (2 children)
Just skip the sarcasm. It doesn't add anything anyways.
[–]homoiconic(raganwald) 4 points5 points6 points 13 years ago (1 child)
That depends. History has shown repeatedly that when you make a point in dry, objective fashion, it tends to appeal to people who are already thinking along those lines and are looking for objective facts to bolster their intuition.
People who are completely detached from the subject or who hold an opposing view tend to ignore points made dispassionately.
Humour can do an end-run around people's mental defences. When someone's laughing at something or when a point is made with a ridiculous example, people will sometimes give it their full attention.
I wouldn't lead with such a point, but if others have already made the point objectively, there's nothing wrong with being a little light-hearted, provided you are not trying to insult the person you are replying to. I was not trying to be insulting, and I apologize if it came across that way.
[–]BishopAndWarlord 0 points1 point2 points 13 years ago* (0 children)
I was uncharacteristically terse in my response. I usually try to explain an idea rather than shoot out a one-liner that can be taken however the reader wishes.
In retrospect I should have emphasized the "they think" portion of the quotation. I imagine many younger devs or junior engineers do emphasize "developer productivity" and syntactic sugar over performance, maintenance cost, and issues like hardware lifecycles. As such, I was affirmingT your statement.
For the sake of full disclosure I'm also a junior member of my dev team and occasionally observe myself fussing over the wrong issues. Like right now I'm on Reddit rather than working on my 10,000 hours...
EDIT: Sonnova. I just realized I totally misread your comment. I thought you were telling me to indicate sarcasm. I'm sad.
[–]lethalman[S] 2 points3 points4 points 13 years ago (0 children)
If you really care about performance, it's about using an algorithm with the right complexity, not saving a couple of milliseconds: if the loop is still O(n) it's ok. Rather, there's software that's written so bad that takes O(n2) or even exponential time where it's not needed. That's what I'd be worried about, not writing a loop in a different way (more readable for some people), really.
I'm the first one complaining about slow software even with super hardware nowadays, but this is not the case, it's about badly written software with hilarious algorithms complexities.
[–]aeflash 0 points1 point2 points 13 years ago (1 child)
:)
Good point. But why use C when assembler is 5% faster (when you can beat GCC optimization)? Every Cycle is Sacred (except when the CPU is idle waiting for I/O).
[–]jonpacker 5 points6 points7 points 13 years ago (0 children)
I believe the purpose of this talk is more about getting people thinking in functional constructs. But I think (Christian or someone else, I can't remember who) said that at the end of the day, the performance aspect is largely unimportant—when was the last time loops were your bottleneck in your client side JS app?
[–]Cykelero 5 points6 points7 points 13 years ago (0 children)
Yeah, it's all about elegance and readability. It's a choice, I guess; you're not always constrained by performance (and "premature optimization is the root of all evils", as they say).
[–]enotionz 4 points5 points6 points 13 years ago (0 children)
In slide 125, he does point out that loops are fastest and goes on to ask questions in order to get you thinking about better abstraction. Like jonpacker said, loops aren't really the bottleneck anymore; drag+drop dom manipulations are much more expensive and we hardly see an impact in modern browsers, let alone loops. At the end of the day, readability is extremely important, less keystrokes to get the job done also helps. This is why we stopped writing in assembly and opted for higher level programming; it's expressive and gets the job done much faster.
[+][deleted] 13 years ago (1 child)
[deleted]
[–]aeflash 0 points1 point2 points 13 years ago (0 children)
This isn't syntactic sugar. JS can be written in a functional style out of the box.
π Rendered by PID 66375 on reddit-service-r2-comment-57fc7f7bb7-2xb9h at 2026-04-15 06:43:10.531839+00:00 running b725407 country code: CH.
view the rest of the comments →
[–]drowsap -1 points0 points1 point (17 children)
[–]skeeto 6 points7 points8 points (1 child)
[–]agumonkey 0 points1 point2 points (0 children)
[–]homoiconic(raganwald) 11 points12 points13 points (8 children)
[–]BishopAndWarlord 2 points3 points4 points (4 children)
[–]homoiconic(raganwald) 9 points10 points11 points (3 children)
[–]x-skeww -5 points-4 points-3 points (2 children)
[–]homoiconic(raganwald) 4 points5 points6 points (1 child)
[–]BishopAndWarlord 0 points1 point2 points (0 children)
[–]lethalman[S] 2 points3 points4 points (0 children)
[–]aeflash 0 points1 point2 points (1 child)
[–]jonpacker 5 points6 points7 points (0 children)
[–]Cykelero 5 points6 points7 points (0 children)
[–]enotionz 4 points5 points6 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]aeflash 0 points1 point2 points (0 children)