6 ms·
In this context, C and JavaScript would not be considered functional. They have functions, but that's not what most people mean by "functional". While it's po
by civility 7y ago
In this context, C and JavaScript would not be considered functional. They have functions, but that's not what most people mean by "functional". While it's possible to restrict yourself to a functional subset in both of them, they would typically fall into the "imperative" category.
Imperative programming languages (like C and JavaScript) don't generally impose any discipline on the users.
- james-mcelwain 7y agoI think this might be a little unfair to JavaScript. No doubt it's a multi-paradigm language, but there's a huuuge FP community in JS, and loads of code bases (esp. in React) are written in a very functional style. Definitely not comparable to passing function pointers around in C.
- dmix 7y agoAlmost everyone I've come across who writes JS in a "functional style" has done it because they've had prior experience using a FP language and are applying those lessons to JS. I believe the OP is talking about those FP languages, such as Haskell and Clojure, which have a very different programming experiences. While JS supports it in many ways, it's still not a style inherent in a multi-paradigm language like Javascript nor is it (really) the primary style in popular frameworks - despite the fact inspiration from FP languages/libraries has been increasingly common in popular frontend frameworks. Additionally, even if you go full-bore FP on JS, it's still not the same. Almost no one goes full-bore FP in JS because it really doesn't make sense to nor is it an easy thing to do. (And I say all of this as a frequent user of https://ramdajs.com https://ramdajs.com)
- cdaringe 7y agoYup. So many good FP => JS langs too.
- james-mcelwain 7y agoDefinitely don't disagree with anything you say, just don't think the characterization of JS as a strictly imperative language is fair -- especially when compared with C.
- AlexCoventry 7y agoYou can get maybe 80% of the way there, but non-FP dependencies can still hurt you. That's also a problem with clojure dependencies on Java libraries, but less so because at least the clojure ecosystem mostly buys into the FP paradigm.
- civility 7y agoFP is different things to different people. For me, it's pure functions and a preference for purely functional data scructures (Okasaki style). Also to me, FP has an emphasis on avoiding mutating state. The second example on the React front page shows how to mutate state, and then they just build from there. I don't use React, but looking at those examples, it all looks very OO to me.
- revvx 7y agoReact with class-components is very OOP. Hooks are closer to functional programming, though (but were released only a couple months ago)
- nikita2206 7y agoIf we are talking languages of certain paradigms imposing discipline then JS not being a language conceived or further developed with FP in mind is not one of those, regardless of how folks use it.
- fnrslvr 7y ago> Imperative programming languages (like C and JavaScript) don't generally impose any discipline on the users. I think this view disrespects history a little. C was one of the earliest languages to be conceived upon a foundation of structured programming principles, i.e. block structure, sequence/selection/repetition, subroutining. (Okay the language still has goto, hopefully we can agree to not make a big deal out of that.) The kind of discipline proposed by structured programming was far from universally well-received at the time, and I think it's fair to say that it lead to huge improvements in the quality of codebases everywhere, and is one of the great successes of programming language thinking of the '70s. C is also statically typed. It's obviously easy to blow all sorts of holes in C's type system, but if you'd go so far as to say that C's types impose no discipline at all, I'd ask you to try teaching C to a room full of compsci students who have been raised on something like Python.
- pjmlp 7y agoKind of true, however C's type system is very weak versus what 60's Algol and PL/I variants were capable of.
- civility 7y ago> I think this view disrespects history a little. I love C, but I'm hard pressed to think of any language other than assembly which is more willing to get out your way if you so much as nudge in an undisciplined direction. C certainly does not impose much discipline on programmers, but it allows them to bring some if they walk the line. > Okay the language still has goto, hopefully we can agree to not make a big deal out of that. > It's obviously easy to blow all sorts of holes in C's type system Yes, I'm willing to politely ignore evidence which refutes your point. I mean you were kind enough to make my case for me. :-) > I'd ask you to try teaching C to a room full of compsci students who have been raised on something like Python. Dynamic vs static typing seems orthogonal to what we're talking about here, but maybe I'd have to think about that more. Python just waits to catch your type errors until runtime. Comparing that to JavaScript in a browser which silently ignores your errors (or happily performs crazy type conversions), Python seems disciplined in comparison.