4 ms·
Well for comparison, GC was a yes right. And basically every popular (modern) language incorporates garbage collection. Functional programming, or at least fair
by fhood 9y ago
Well for comparison, GC was a yes right. And basically every popular (modern) language incorporates garbage collection. Functional programming, or at least fairly strict functional programming, still hasn't really caught on. Of the juggernaut languages, C/C++, python, Ruby, Java, JavaScript none are truly functional (I don't use JavaScript but the code I have seen in it doesn't often look functional). Until something like Scala cracks the top 5 I agree with calling it a maybe.
- paulddraper 9y agoWhat makes Scala decidedly functional and JavaScript or Ruby not?
- charlysl 9y agoJavaScript and Ruby are functional too. Scala supports other paradigms than FP too. They are all multi-paradigm. The difference is that certain programming styles might be more natural in some languages than in others.
- fhood 9y agoWell, the first listed paradigm for Scala on wikipedia is functional, JavaScript and Ruby both have OO followed by imperative. And anyways supporting functional programming and being designed for it are not the same thing. Yeah, I can right functional Ruby, but that isn't going to be by initial inclination when writing a Ruby script. It would be for Scala.
- charlysl 9y agoSure, this is what I meant by natural. Just one thing: when you write that Ruby script, could one of the reasons why you don't use a FP style be not only that maybe it wouldn't be natural to do so in Ruby, but also that it's unsuitable for the kind of problem you are trying to solve with that script to begin with? I mention this, because I have the impression that people tend to believe that to solve a programming problem you should use whatever paradigm is perceived as the main one for the language at hand. However, I believe that it's the problem that should dictate the paradigm.
- fhood 9y agoI agree in principle, but rather than the problem dictating the paradigm, I would say it usually dictates the language. If a problem is well suited to a functional implementation then I'll probably break out Scala to solve it.
- charlysl 9y agoI agree, that would be the right to do. But the thing is, what if you are stuck with a given language, and/or its a biggish complex project where different aspects are better solved with different paradigms?
- SatvikBeri 9y agoI don't think there's any one knock-down criterion, but there are several small things that add up: -Scala was intended to have strong FP and OO support from day 1 -Scala has very strong support for immutable values and persistent data structures. It's hard to do FP efficiently without these -Similarly, Scala has built in support for laziness to a significantly greater extent than most languages. This is arguably important because it supports immutability, there are some important mutable algorithms that have no efficient immutable equivalent without laziness -Strong lambdas (unlike, e.g., Python) -Many of the major Scala libraries are either written in a heavily functional style or support highly functional APIs, while libraries in most languages do not
- charlysl 9y agoInteresting points well put, thank you.
- mateo411 9y agoWhat is a strong lambda?
- SatvikBeri 9y agoNot a standard term – I'm just referring to the ability to do anything in a lambda that you can do in the body of a function, such as defining intermediate values, which is not possible in Python.
- zjarek_s 9y agoI think this is nitpicking. In python you can do everything you want in inner functions, they just have to be named. Additionaly there is simple syntax for single expressions, that don't need names. Lack of TCO is a lot bigger obstacle to using more functional style
- jerf 9y agoAlso interesting in addition to the other fine replies is that Javascript qua Javascript hasn't actually moved all that much in the past 15 years, and in 2002 JS would definitely not have been a "functional language". I'd say it's a language whose issues are sometimes something that FP is best at papering over, but as an FP language, it is quite lacking if you're used to something like Haskell, Erlang, or Lisp. I actually put it in the category of OO-FP languages, languages that have a lot of the FP constructs (especially from when Lisp was the epitome of FP) but are primarily object-oriented languages. It's a pretty decent paradigm, but it really ought to be distinguished from FP languages where there are no OO features in them at all, or much more rarely, where they are clearly second-class.
- leshow 9y agoJS had first class functions from the beginning, which I think is one of the major things necessary for FP. Compare that with a language like Java, which did not, and I think still doesn't (lambda's aren't quite the same). JS doesn't really support traditional inheritance either, so describing it as OO seems odd to me.
- jerf 9y agoI consider anything that binds data to methods and has a concept of "data.method()" to be OO. In the OO religion I'm an ecumenicist. And even within my ecumenicalism, I consider inheritance in the strictly C++/Java sense of relatively little importance, and dropping. Rather than being essential, it turns out to have been accidental, and also arguably a mistake, even on purely OO grounds.
- leshow 9y agoThat's a silly distinction. It's also wrong. Rust 'binds data to methods and has a concept of "data.method()"' and is not OO by any meaningful definition. It's simply sugar for Trait::method(&data).