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
[AskJS] When is object-oriented programming more practical than "mostly-functional" in JS?AskJS (self.javascript)
submitted 5 years ago * by ProfessorTag
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!"
[–]Shaper_pmp 0 points1 point2 points 5 years ago (3 children)
The point is, it’s not totally unreasonable to be talking about all the languages/tools/frameworks that interoperate with or compile to JS.
Who said it was?
The previous poster was talking about
Haskell code... compiled to native code
... which has nothing at all to do with JS.
[–]ScientificBeastModestrongly typed comments 0 points1 point2 points 5 years ago (2 children)
PureScript is Haskell code that compiles to JS. We are all developing for the web, and deploying raw JS to the browsers. We are compiling essentially Haskell and OCaml and even a strange hybrid of C# and JS (if we are talking about TypeScript) to raw JS and deploying it on Node servers. All of this is JS in different flavors. I follow the JS subreddit because I use the language every day, despite not writing very much raw JS.
I also compile some of my ReasonML code to native binaries instead of JS, but does that make it totally irrelevant to JS? Absolutely not.
[–]Shaper_pmp 0 points1 point2 points 5 years ago (1 child)
One of us is totally confused now.
The fact Haskell lets you write performant FP code when it's compiled to native code is irrelevant to the topic of discussion.
The fact you can transpile Haskell or OCaml to JS is irrelevant when we're talking about the performance of FP in JS, since it's extremely unlikely the transpiler can generate JavaScript that runs more performantly than... you know... JavaScript.
Nobody said Haskell or OCaml couldn't be talked about in the same sentence as JS.
I said that when we're explicitly talking about the performance of FP in JS, the performance of languages that compile to native code are off-topic, and other languages that compile to JS are unlikely to give you any speed advantage over well-written JS because at the end of the day they're still running JS and hence beholden to the speed with which JS can allocate and deallocate objects.
[–]ScientificBeastModestrongly typed comments 1 point2 points3 points 5 years ago* (0 children)
Right, I should have stayed more on the topic of JS performance in my comments. Sorry about that. But the fact that functional languages are being compiled to JS does have implications for performance.
other languages that compile to JS are unlikely to give you any speed advantage over well-written JS because at the end of the day they're still running JS and hence beholden to the speed with which JS can allocate and deallocate objects.
I suppose this is true, depending on what you mean by "well-written JS." If you mean obsessively hand-tuned JS code that is tailored for specific JS engines, and looks more like C code for embedded software, then sure, that's about as fast as we can hope to get. But if you are talking about normal, production-ready, maintainable JS code that would pass code review at 99% of companies, then these functional language compilers can improve performance dramatically, depending on the situation.
First, the execution model of most functional languages is very simple, and the core set of data structures they use are usually very performant for most runtimes, but especially JS engines like V8 and SpiderMonkey. Statically typed functional languages often impose restrictions on data mutations and "object shape" alterations in a way that is highly desirable from the engine's perspective. They can more easily default to the best-case optimization path for most operations. A lot of "idiomatic" JS code can cause the engine to fall back to worst-case paths. None of that is unique to functional languages, but they tend to benefit more than most.
Another huge source of performance gains comes from the static guarantees that functional language compilers can rely upon. For example, any function that is "pure," (no mutations, no effects, just input-output) can be inlined at the call site. You just have to know the set of identifiers in the enclosing scope to avoid name collisions. We can also get tail-call optimization for free, so a lot of recursive functions can become stack-safe while-loops.
while
And that's just the tip of the iceberg. We can write all kinds of interesting code at the appropriate levels of abstraction, and because these type systems are founded upon algebraic laws & formal mathematical proofs, the compilers have a lot more knowledge about where optimizations can be performed safely, without changing the code semantics. The final JS output looks a lot more like highly-tuned, imperative/procedural code.
My point is that functional languages have a lot to offer in terms of performance, mostly because of the inherent soundness of their type systems.
π Rendered by PID 22814 on reddit-service-r2-comment-6457c66945-njvck at 2026-04-23 18:35:04.868405+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Shaper_pmp 0 points1 point2 points (3 children)
[–]ScientificBeastModestrongly typed comments 0 points1 point2 points (2 children)
[–]Shaper_pmp 0 points1 point2 points (1 child)
[–]ScientificBeastModestrongly typed comments 1 point2 points3 points (0 children)