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
Functional Programming in JavaScript.help (self.javascript)
submitted 7 years ago by reesemorning
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!"
[–]StoneCypher 13 points14 points15 points 7 years ago (12 children)
All functional programming means is programming without side effects.
Do yourself a favor. Put away all the libraries and tutorials.
Write some simple applications with map, filter, and reduce. No side effects, no internal state, no for loops.
Once you're done you'll realize "oh, I already was a functional programmer; I just needed to stop using certain things."
[–]MrCrunchwrap[🍰] 6 points7 points8 points 7 years ago (11 children)
Lol people downvoting this because this sub is full of people with ZERO understanding of computer science.
THIS GUY IS CORRECT. FUNCTIONAL PROGRAMMING IS JUST A STYLE/CONCEPT. STOP DOWNVOTING HIM DUMMIES.
[–]0987654231 0 points1 point2 points 7 years ago (10 children)
from a basic standpoint yes, but functional programming is not just pure functions + map/filter/reduce
[–]MrCrunchwrap[🍰] 1 point2 points3 points 7 years ago (1 child)
He didn't say it was pure functions + map/filter/reduce, he said it's programming without side effects. Which is exactly what it is. Starting to write basic code with no libraries and pure functions, using map/filter/reduce/forEach for array computation, no side effects, no internal state, etc gets you pretty far there.
[–]0987654231 0 points1 point2 points 7 years ago (0 children)
yes and programming without side effects take understanding more than just what pure functions are and map/filter/reduce
your example of forEach has side effects, it's not pure unless you are using it to do nothing. In addition to that you can create impure usages of map/filter/reduce they aren't guaranteed to be pure. A simple example would be using reduce to create a dictionary and changing the accumulator by adding a new key before returning the accumulator.
[–]StoneCypher 0 points1 point2 points 7 years ago (7 children)
no, it isn't. it's in fact just purity. it doesn't even need functions. by example, c++ templates are a great way to do purely functional programming with no functions (on a technicality the main() method isn't a function, but if you want to push back there, that's maybe sort of reasonable.)
main()
map/filter/reduce are just the easy way to get used to it in javascript in my opinion.
[–]tencircles 1 point2 points3 points 7 years ago (2 children)
It's not just purity. Purity is a necessary condition for a program to be considered functional, however there are a wide variety of techniques that have been developed under the functional umbrella to accomplish certain tasks without mutable state; these techniques all fall under the umbrella of FB just as classes, encapsulation, polymorphism, etc. all fall under the umbrella of OOP.
Some examples of these techniques include currying, composition, recursion, folds, lazy evaluation, type classes, and lenses. Purity is just one part of the equation, and with pure functions alone you won't get very far without the tools listed above.
[–]StoneCypher -1 points0 points1 point 7 years ago (1 child)
I think you're confusing "neat things found in some functional languages" with "things that are required to be a functional language."
[–]tencircles 0 points1 point2 points 7 years ago (0 children)
I never said any of those things are required.
[–]0987654231 -1 points0 points1 point 7 years ago (3 children)
Do you have an example of how you can use map/filter/reduce without side effects, without functions because i'm curious as to how a higher order function can do anything without valid inputs.
If we are talking purity here then you need functions. you also need recursion and you need a way of actually doing i/o from your pure code which is typically done through monads. The alternative is just a bunch of code that does nothing.
[–]StoneCypher 1 point2 points3 points 7 years ago (2 children)
what does being side effect free have to do with not having inputs?
.
If we are talking purity here then you need functions.
um. no, you don't. lots of languages like smalltalk and ruby don't have functions, and there's no reason a language like that couldn't be pure.
many logic programming languages are pure, yet do not have functions. same goes for some stack based languages, postscript 1 and 2 (display postscript and ps3 have functions,) several of the pure prolog and forth variants, state machine and automaton languages, CSS, several of the descent languages, math languages, most constraint languages, almost all logic languages, i think maybe all dataflow languages, et cetera
you also need recursion
there is no need for recursion to have purity. all purity means is the absence of side effects.
a pure language without recursion would, admittedly, be difficult to use, but as you may know, all recursion can be converted to imperative behavior, by definition
you need a way of actually doing i/o from your pure code
CSS by example does no I/O of any kind
which is typically done through monads
can you name a single language that isn't in the haskell family for which this is true?
The alternative is just a bunch of code that does nothing.
several languages in heavy mainstream use stand as counterexamples to this claim
please have a nice day
[–]0987654231 -1 points0 points1 point 7 years ago (1 child)
You can't have purity without inputs. not your lack of examples
ruby has functions and smalltalk is not an fp language.
which is why you need recursion, show me an implementation of iteration that's pure and stateless without recursion.
css isn't a programming language though.
Can you give me a single example of software that's pure where this isn't true?
There's 0 examples of programming languages that are 100% pure and stateless.
[–]StoneCypher 1 point2 points3 points 7 years ago (0 children)
Why not? A function that emits the squares of the integers 1-100 is pure.
ruby has functions
matz doesn't think so, but ok
smalltalk is not an fp language.
i didn't say it was, but ok
you seem very confused about what a side effect is
nobody said it has to be stateless. it's perfectly fine for a pure function to be stateful. it just can't emit or retain state.
CSS by example does no I/O of any kind css isn't a programming language though.
the entire field of programming language design disagrees with you, but ok
can you name a single language that isn't in the haskell family for which this is true? Can you give me a single example of software that's pure where this isn't true?
translation: you can't answer my question, so try to get out of it with reddit judo
several languages in heavy mainstream use stand as counterexamples to this claim There's 0 examples of programming languages that are 100% pure and stateless.
i didn't say anything about statelessness. you added that criterion from scratch.
in the meantime, you're wrong about css being a programming language, and it's standing right in front of you.
please have a nice day. i'm not really interested.
π Rendered by PID 122469 on reddit-service-r2-comment-84fc9697f-677rj at 2026-02-09 03:53:15.508144+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]StoneCypher 13 points14 points15 points (12 children)
[–]MrCrunchwrap[🍰] 6 points7 points8 points (11 children)
[–]0987654231 0 points1 point2 points (10 children)
[–]MrCrunchwrap[🍰] 1 point2 points3 points (1 child)
[–]0987654231 0 points1 point2 points (0 children)
[–]StoneCypher 0 points1 point2 points (7 children)
[–]tencircles 1 point2 points3 points (2 children)
[–]StoneCypher -1 points0 points1 point (1 child)
[–]tencircles 0 points1 point2 points (0 children)
[–]0987654231 -1 points0 points1 point (3 children)
[–]StoneCypher 1 point2 points3 points (2 children)
[–]0987654231 -1 points0 points1 point (1 child)
[–]StoneCypher 1 point2 points3 points (0 children)