News for hackers. Stuff that matters.
Re:What's worked in Computer Science (2015) by raiflip on Wednesday November 29, 2017 @09:32AM (#15807020)
I'm confused as to why he doesn't put functional programming as a yes. He writes "Functional languages are still quite niche, but functional programming ideas are now mainstream, at least for the HN/reddit/twitter crowd."

While purely Functional languages are definitely not mainstream, as he puts functional programming ideas are pretty mainstream. At the same time major OO languages like java have incorporated functional programming ideas, so arguably even Java is not purely Object Oriented anymore. It seems to me by his criteria that would also put OO as a no too.

If he comes from OO languages I think this is a bias because it is easy to take OO for granted and put strict requirements on foreign Functional Programming before accepting it as successful. However it seems to me the only criteria that should be needed to call either paradigm successful is if their ideas are are mainstream, which is true for both languages.

Basically if Function Programming ideas have gained currency then it should be regarded as successful.

Re:What's worked in Computer Science (2015) by Tomis02 on Wednesday November 29, 2017 @11:34AM (#15808110)
I think it's important to make the distinction between a successful idea and a good one. For example OO as a paradigm in mainstream languages (C++, Java) has been very successful, despite it being more often than not a bad idea (e.g. horrible inheritance hierarchies are still implemented in this day and age, with dire consequences on code quality).

In OP's article, OO is filed under "what works", which I strongly disagree with. If anything, software development works DESPITE OO, which in my experience constantly hinders progress because of rigid architectures.

Re:What's worked in Computer Science (2015) by raiflip on Wednesday November 29, 2017 @12:15PM (#15808605)
As much as FP has made my life easier, have to disagree with you on OO. Any language/paradigm is capable of producing bad code. In my first job a high up manager brought in Clojure to a department filled with Java and OO acolytes. While the language was amazing, the Clojure code base was filled with gigantic let statements simulating imperative code, functional spaghetti, and given the lack of a good IDE difficult to debug (had to throw exceptions just to see variable values... shudders). The point is not that FP is bad, just that any tool in unskilled hands can produce bad code.

Not sure what it is like for the industry at large, but from what I've seen a dominant paradigm in Java is to separate out model classes that are basically just structs with Service or Workflow classes that manipulate the data. It's questionable how much of that is still OO (at least when I started learning it the narrative was to put your code where your data is. POJOs are the opposite of that). Given say having a high level service that calls low level services and external system while returning a result produces code thats very easy to trace and provides solid abstraction to the calling code. Also if you've read Uncle Bob's data structure vs. Object dichotomy you'll see how Objects are objectively better in some scenarios, and OO languages give you powerful tools for objects.

That said 100% agree with you on horrible inheritance hierarchies. What I think would be best is some course on how to combine OO and FP paradigms to get the best of both worlds (though tbh it'd probably be 90% FP with some OO).

Re:What's worked in Computer Science (2015) by charlysl on Wednesday November 29, 2017 @12:54PM (#15809072)
"What I think would be best is some course on how to combine OO and FP paradigms to get the best of both worlds"

If you want to find out, read "Concepts, Techniques, and Models of Computer Programming". It's mindblowing. It answers that question exactly.

This is a dense but exceptionally written 1000 page book, but maybe you can just read section 4.8.5 to get an idea [1]. However, I think you will take more than just reading this bit, to understand the different models (many more than the 2 everybody talks about).

Section 4.8.7 is actually "Using different models together", with the key "impedance matching" concept.

The author sort of summarizes it here [2]

There is also a mooc in edx, but it just scratches the surface of what's in the book [3]

[1] https://books.google.com.vn/books?id=_bmyEnUnfTsC&pg=PA322&l...

[2] http://lambda-the-ultimate.org/node/4698

[3] http://lambda-the-ultimate.org/node/4842

Re:What's worked in Computer Science (2015) by raiflip on Wednesday November 29, 2017 @01:29PM (#15809409)
Cool, thanks! Checking it out.
Re:What's worked in Computer Science (2015) by charlysl on Wednesday November 29, 2017 @11:54AM (#15808338)
I don't believe that the problem is OO in itself, but the way in which it is often used. You can write a bad program in any paradigm, and a good one too.

FP is less popular and tends to attract a more curious crowd, who is more willing to learn how to use it well, whereas OO languages are used by everyone.

On top of that, OO is build on top of a more expressive computation model, the stateful one, which because of its power is much more difficult to use well (and easier to abuse) than the much simpler functional/declarative model.

Re:What's worked in Computer Science (2015) by Tomis02 on Wednesday November 29, 2017 @12:01PM (#15808434)
> I don't believe that the problem is OO in itself, but the way in which it is often used.

That's similar to what proponents of communism have been saying - "it does work if you do it right". The problem is that things start breaking down as soon as the project scale. For small programs a pure OO model can work, but increased complexity means people will definitely switch to a hybrid OO-(procedural|functional) style, simply because pure OO is untenable in large codebases.

Re:What's worked in Computer Science (2015) by charlysl on Wednesday November 29, 2017 @12:32PM (#15808854)
Haha, communism. Communism failed in Russia. But democracy failed in Russia too. Was communism the problem? I am half kidding, but I have wondered sometimes ...
Re:What's worked in Computer Science (2015) by fhood on Wednesday November 29, 2017 @10:12AM (#15807334)
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.
Re:What's worked in Computer Science (2015) by paulddraper on Wednesday November 29, 2017 @11:04AM (#15807821)
What makes Scala decidedly functional and JavaScript or Ruby not?
Re:What's worked in Computer Science (2015) by SatvikBeri on Wednesday November 29, 2017 @11:54AM (#15808348)
I 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

Re:What's worked in Computer Science (2015) by charlysl on Wednesday November 29, 2017 @12:12PM (#15808580)
Interesting points well put, thank you.
Re:What's worked in Computer Science (2015) by mateo411 on Wednesday November 29, 2017 @04:48PM (#15811166)
What is a strong lambda?
Re:What's worked in Computer Science (2015) by SatvikBeri on Wednesday November 29, 2017 @09:53PM (#15813091)
Not 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.
Re:What's worked in Computer Science (2015) by zjarek_s on Thursday November 30, 2017 @01:37PM (#15818260)
I 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
Re:What's worked in Computer Science (2015) by jerf on Wednesday November 29, 2017 @12:41PM (#15808966)
Also 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.

Re:What's worked in Computer Science (2015) by leshow on Wednesday November 29, 2017 @03:24PM (#15810510)
JS 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.

Re:What's worked in Computer Science (2015) by jerf on Thursday November 30, 2017 @09:11AM (#15815782)
I 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.

Re:What's worked in Computer Science (2015) by leshow on Friday December 08, 2017 @04:11PM (#15882073)
That'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).
Re:What's worked in Computer Science (2015) by fhood on Wednesday November 29, 2017 @11:13AM (#15807906)
Well, 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.
Re:What's worked in Computer Science (2015) by charlysl on Wednesday November 29, 2017 @11:42AM (#15808189)
Sure, 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.

Re:What's worked in Computer Science (2015) by fhood on Wednesday November 29, 2017 @01:01PM (#15809152)
I 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.
Re:What's worked in Computer Science (2015) by charlysl on Wednesday November 29, 2017 @09:11PM (#15812880)
I 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?

Re:What's worked in Computer Science (2015) by charlysl on Wednesday November 29, 2017 @11:09AM (#15807879)
JavaScript 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.
Re:What's worked in Computer Science (2015) by ape4 on Wednesday November 29, 2017 @09:48AM (#15807147)
You need good garbage collection for functional programming. Now we have good garbage collection.
Re:What's worked in Computer Science (2015) by throwawayjava on Wednesday November 29, 2017 @11:08AM (#15807865)
Not to mention, these languages actually work for many, many domains. A shit-load of C# could just as well be F#. In fact, lots and lots of people do use F#/Scala/OCaml/etc. to build real systems.

Just because something isn't "the most popular" doesn't mean that thing doesn't work.

Re:What's worked in Computer Science (2015) by charlysl on Wednesday November 29, 2017 @10:57AM (#15807757)
Java has been multi-paradigm since the beginning, although it favours a stateful style for sure.

FP is by no means restricted to purely functional languages. My impression is that the ideal approach is to use the paradigm most suitable for the problem/component at hand (principle of least expressivity), so I prefer multi-paradigm languages over pure ones, although of course I understand that there are domains where one can benefit from the optimizations made possible by purity.

Understanding how to do this requires much more of a learning effort, learning more concepts, techniques and idioms, which I suspect is why FP is still lagging; I don't believe it is for any fundamental reason.

The other thing is that there are many more programming paradigms than just functional and stateful.

Re:What's worked in Computer Science (2015) by twblalock on Wednesday November 29, 2017 @01:38PM (#15809498)
The Java 8 lambda syntax is all objects under the hood, and the Haskell "do" notation is all functional under the hood. It's impressive that both languages are able to accommodate other programming paradigms while remaining pretty much the same under the hood.
Re:What's worked in Computer Science (2015) by moron4hire on Wednesday November 29, 2017 @01:51PM (#15809623)
Not really? It's turing complete turtles all the way down.

I leave this article out whenever people start talking "OOP vs FP": https://eli.thegreenplace.net/2016/the-expression-problem-an...

Re:What's worked in Computer Science (2015) by eternalban on Wednesday November 29, 2017 @02:00PM (#15809703)
"It's impressive that both languages are able to [efficiently/effectively] accommodate other programming paradigms while remaining pretty much the same under the hood."
Re:What's worked in Computer Science (2015) by bryanlarsen on Wednesday November 29, 2017 @09:34AM (#15807034)
You can't get much more mainstream than Javascript, and it's fairly functional.
Re:What's worked in Computer Science (2015) by zaarn on Wednesday November 29, 2017 @09:37AM (#15807054)
JS is multi-paradigm, it's functional but it's also 3 other things that muddy the water a bit.

Especially considering most programming languages have those neat helper methods or stdlib implementations that basically bring functional programming without changing the language much.

Re:What's worked in Computer Science (2015) by jackhack on Wednesday November 29, 2017 @10:28AM (#15807486)
JS may be capable of a pure functional programming style, but from 20 years of observing it's use (and misuse), functional JS is an exceptionally rare occurrence; an edge case.
Re:What's worked in Computer Science (2015) by maze-le on Wednesday November 29, 2017 @09:43AM (#15807117)
Javascript may have some functional concepts (mainly, functions as first order objects) but the programming style of most common javascript projects is not functional. This is with the notable exception of event-driven frameworks and precompiled languages like purescript.