3 ms·
Honestly I think JavaScript is about as good as any other mainstream dynamic language, save the Lisps, for FP. I'm currently writing a functional language and c
by thinkpad20 13y ago
Honestly I think JavaScript is about as good as any other mainstream dynamic language, save the Lisps, for FP. I'm currently writing a functional language and compiling to JavaScript, for the precise reason that it's a very straightforward translation. It's certainly much better at it than Python, although I consider Python vastly superior in almost every other respect. However, I think that FP in a dynamic language is very difficult because of the lack of typing. In Haskell you can write incredibly intricate and expressive single-liners that would be 10 lines in another language (if you could do them at all), and are only really feasible because of the typing system (as in, it would require almost a miracle to get them right without a type system backing you up). I suppose Lisp people manage to get away with it, but on the other hand Lisp isn't really functional the way the ML family of languages are.
As far as the data structures not being there, well, keep in mind that JavaScript is based on imperative languages; hence its focus on arrays and hash tables (both of which are almost always implemented mutably). Also, mutability is baked into the DOM, and short of doing everything in a monad, that looks to be the way it's going to be, so again, it makes sense that JS was written as it was. When immutability is needed, use a library -- or just don't use JavaScript.
- kevingadd 13y agoAs long as you ignore the tremendous maintainability and performance hurdles preventing you from using FP javascript in production, yeah, it's 'about as good'. Other than the fact that it's incredibly poorly designed and has a shitty standard library. Blaming JavaScript's awful standard library on imperative languages is lazy. Almost every imperative language I've used has a standard library vastly superior to JS's, in breadth, depth and quality.
- thinkpad20 13y agoI didn't blame its standard library on imperative languages; I blamed its use of mutable data structures on that. I think the main reason it has a crappy minimal standard library is because for most of its lifetime it wasn't used for anything resembling "real programming." JS is a terrible language in many ways; don't get me wrong on that. However, I don't think it's any worse specifically at functional programming than any of the other mainstream dynamic languages (python, ruby, PHP, perl, etc), most or all of which are also founded on mutable data structures, lack of TCO, etc.