Live data from Hacker News

Disadvantages of purely functional programming

flyingfrogblog.blogspot.com

61–70 of 70 posts

Re: Disadvantages of purely functional programming

#61
post #55
post #53

Earlier quoted context omitted.

Have you ever learned Smalltalk? Thanks to support for blocks (lambda), Smalltalk collections already had LINQ style programming, aka algorithm.h support, for example. Nice link.

I actually haven't ever used SmallTalk, although I understand Ruby is considerably influenced by it (blocks, as far as I understand). Any pointers are appreciated though. I'm more of a Python person, and Python doesn't really use blocks. I like the duality mentioned this post: http://journal.stuffwithstuff.com/2013/01/13/iteration-insid... (In summary it's for item in L: f(item) vs L.each(|item| ...) I don't really t…

There are lots of Smalltalk books here, including the original ones from Xerox PARC.

http://stephane.ducasse.free.fr/FreeBooks.html

The best free implementations to play around are Squeak and Pharo.

http://squeak.org/

http://squeak.org/

Or if you want to avoid installing anything, Amber gives some taste of it.

http://amber-lang.net/

Now, regarding the LINQ like stuff, in Smalltalk doing this type of stuff was already possible back in those days.

    |a|
    vec := #(1 2 3 4 5 6). 
    sumPairs := (vec select: [:x | (x \\ 2) = 0]) inject: 0 into: [:l :r | l + r].
Yes, that is what I was thinking of. The other part, immutable data and such, isn't that possible to practice in large teams. But I do make use of it in personal projects.

Re: Disadvantages of purely functional programming

#62
post #59
post #57

Earlier quoted context omitted.

In Common Lisp it is easy to return multiple closures. Emacs Lisp now has lexical closures, too. Common Lisp has no problems with 'polymorphic print'.

Fair enough, but the appeal of Lisp to me is that it's a small axiomatic core, something that not only fits in your head, but the whole implementation fits in your head too. I wanted to use it to bootstrap languages, with no dependencies. But it turns out that this axiomatic core is too impoverished for a lot of programming. You DO need something like Common Lisp on top. And I'm not really willing to open that can of…

> whole implementation fits in your head too

Of the axiomatic core. But not of any programming language.

> But it turns out that this axiomatic core is too impoverished for a lot of programming.

It's not even a programming language. It's just an axiomatic core. If you try to use it for programming you must be doing something wrong.

> is writing a lexer. I don't see anything that Lisp offers you in that respect.

Lisp is a language family, not language implementation with a library, which happens to include a lexer library.

If you mean Common Lisp as a programming language with implementations, there are portable lexers.

http://www.cliki.net/LEXER

https://github.com/drewc/smug

https://github.com/lispbuilder/lispbuilder

Writing your own lexer in Lisp shouldn't be too hard. People have written applications in Lisp which includes lexer functionality.

Re: Disadvantages of purely functional programming

#63
post #62
post #59

Earlier quoted context omitted.

Fair enough, but the appeal of Lisp to me is that it's a small axiomatic core, something that not only fits in your head, but the whole implementation fits in your head too. I wanted to use it to bootstrap languages, with no dependencies. But it turns out that this axiomatic core is too impoverished for a lot of programming. You DO need something like Common Lisp on top. And I'm not really willing to open that can of…

> whole implementation fits in your head too Of the axiomatic core. But not of any programming language. > But it turns out that this axiomatic core is too impoverished for a lot of programming. It's not even a programming language. It's just an axiomatic core. If you try to use it for programming you must be doing something wrong. > is writing a lexer. I don't see anything that Lisp offers you in that respect. Lisp…

I don't think your opinion about the axiomatic core matches that of all, or even most, Lisp programmers.

And I'm not saying it's not possible to write lexers in Scheme or Common Lisp. I'm saying that there's no real benefit to doing so over C or even Python. You're using the exact same algorithms and just transliterating it into a different language with more awkward syntax for that problem. The code isn't any shorter.

Related to the other commenter as well, the production quality Julia parser in Lisp doesn't use parser combinators. It uses recursive descent. It's C code written in Lisp syntax.

Re: Disadvantages of purely functional programming

#64
post #6

Earlier quoted context omitted.

First, functional programming is an umbrella term. This paper talks about strict FP, which is basically "no mutation", so I'll talk about that. It's clear that some other aspects of FP, such as first-order functions, closures, etc are very useful in practice. Immutability does have its advantages in that it supplies strong guarantees about what your code does. It avoids spaghetti code where everything can and does mu…

I agree that immutability is very useful, but you don't really need any kind of FP to use immutability, do you?

Indeed, it's more of a pattern.

Re: Disadvantages of purely functional programming

#65
post #63
post #62

Earlier quoted context omitted.

> whole implementation fits in your head too Of the axiomatic core. But not of any programming language. > But it turns out that this axiomatic core is too impoverished for a lot of programming. It's not even a programming language. It's just an axiomatic core. If you try to use it for programming you must be doing something wrong. > is writing a lexer. I don't see anything that Lisp offers you in that respect. Lisp…

I don't think your opinion about the axiomatic core matches that of all, or even most, Lisp programmers. And I'm not saying it's not possible to write lexers in Scheme or Common Lisp. I'm saying that there's no real benefit to doing so over C or even Python. You're using the exact same algorithms and just transliterating it into a different language with more awkward syntax for that problem. The code isn't any shorte…

> I don't think your opinion about the axiomatic core matches that of all, or even most, Lisp programmers.

I have never seen anyone developing software with the 'axiomatic core'. But I see Emacs Lisp, Common Lisp, Scheme, etc. developers.

> And I'm not saying it's not possible to write lexers in Scheme or Common Lisp. I'm saying that there's no real benefit to doing so over C or even Python.

Depends on what level you program. With Lisp it is possible to develop a compact syntax, which expresses domain-level concepts, very easily. Interactive development is many times more convenient than in C.

> You're using the exact same algorithms and just transliterating it into a different language with more awkward syntax for that problem. The code isn't any shorter.

I have a surprise for you: it's perfectly legal to write imperative code in Lisp. Lisp is at its heart a multi-paradigm language with the option to add many other paradigms.

With Python you develop mostly object-oriented and in C it's mostly imperative. With something like Common Lisp you can do what you want.

Re: Disadvantages of purely functional programming

#66
post #7

Harrop is known in the Haskell community for being a hater. Most of his remarks here are opinion, which is fine. Lots of people don't like Haskell - that's also fine, but pieces like these hurt the community because it will both push away newcomers and make industrial use more difficult. Also, I've never needed an unsorted dictionary, and parallelism is actually great in Haskell. http://chimera.labs.oreilly.com/books…

I like Haskell, and I use it once in a while. The thing is, I like knowing what my tools are capable of. That includes wanting to know their limits. This piece, to me, seems well-researched and factual. It's not perfect, but it's good. It has plenty of good citations for areas that aren't simply opinionated. A piece that is honest about the shortcomings of a piece of software can only help that software's community.…

Some of the author's claims are correct, however point 3 for example doesn't have citations and is complete bollocks.

An immutable collection isn't a place to be mutated, a bucket to fill, so saying that immutable collections don't support concurrent updates is really stupid, because not allowing concurrent updates is the point of immutable collections.

But then, I challenge the author to show me concurrent dictionary implementations that have the non-blocking, lock-free property. Such implementations exist, mind you, but they are an area of active research and not usually part of standard libraries. And there goes the author's argument about the established industry. One such implementation is the TrieMap [1], a new and interesting implementation of a lock-free Map that actually relies on techniques used in persistent data-structures ;-)

On the other hand, shove a persistent data-structure into an AtomicReference and you get a non-blocking concurrent collection for free, which of course includes any kind of persistent Map implementation you want. And lo and behold, the layman can achieve non-blocking concurrent data-structures without a PhD.

There are of course gotchas. The real strength of mutable concurrent data-structures is that they can distribute the contention over multiple nodes, whereas with an immutable data-structure you end up driving that contention to a single root. That can be really, really bad for writes. But then again, concurrent reads for immutable data-structures come basically for free. This means such a data-structure is bad for storage, but really good for message passing (like from producers to consumers). Hence actual databases making use of FP techniques, like for example Cognitec's Datomic, are implemented in a mixed style, best tool for the job and all that.

But instead the author's argument is just a rant that doesn't delve into any interesting details.

A similar weak point is number 7. First of all, what the author understands about parallelism isn't parallelism and I don't really understand his ramblings on performance and absolute performance, but that's not the goal of parallelism. The goal of parallelism is scalability (i.e. the ability to throw hardware at a problem in order to decrease processing time). But this will naturally tax the number of operations per second that a single core can achieve, which can be acceptable if you can make up for it with hardware. And for example his linked benchmark uses at most 8 cores, which is too few to come up with a sweeping generalization like that. That conclusion simply doesn't follow from this benchmark, being basically just Amdahl's law in action, which he fails to recognize.

[1] http://lampwww.epfl.ch/~prokopec/ctries-snapshot.pdf

Re: Disadvantages of purely functional programming

#67

Earlier quoted context omitted.

> Huge body of problems can be handled by simple recursion but I've yet to see non-functional programmers use it. I don't know why. Stack overflows.

"Functional" languages typically have tail-call optimization and heap-allocated frames. Maybe OOP is a workaround for these missing features...

Why doesn't your language have TCO?

"Nobody uses recursion."

Why doesn't anybody use recursion?

"No TCO."

Re: Disadvantages of purely functional programming

#68
post #6

Earlier quoted context omitted.

First, functional programming is an umbrella term. This paper talks about strict FP, which is basically "no mutation", so I'll talk about that. It's clear that some other aspects of FP, such as first-order functions, closures, etc are very useful in practice. Immutability does have its advantages in that it supplies strong guarantees about what your code does. It avoids spaghetti code where everything can and does mu…

I agree that immutability is very useful, but you don't really need any kind of FP to use immutability, do you?

If your data is immutable, in what sense is your code not 'Functional Programming?'

"It's OO, and it can't be both OO and FP."

Hmmm.

Re: Disadvantages of purely functional programming

#69
post #6
post #2

I don't get why people would use functional programming for anything. It's both more difficult and slower.

First, functional programming is an umbrella term. This paper talks about strict FP, which is basically "no mutation", so I'll talk about that. It's clear that some other aspects of FP, such as first-order functions, closures, etc are very useful in practice. Immutability does have its advantages in that it supplies strong guarantees about what your code does. It avoids spaghetti code where everything can and does mu…

You're confusing first-class and higher-order functions.

Re: Disadvantages of purely functional programming

#70

Earlier quoted context omitted.

At least point 4 seems to be about algorithms, not data structures? That is, there's nothing up front that says graph algorithms must be faster using mutable data structures, but that is apparently the case, so far.

Any imperative algorithm / data-structure, e.g. union-find, can be implemented purely by using an IntMap for memory and a State monad, with roughly equivalent performance: https://hackage.haskell.org/package/union-find As to whether that actually counts as "purely functional programming", I can't say. Honestly the whole term seems quite misleading. https://chadaustin.me/2015/09/haskell-is-not-a-purely-functi...

The reason he cites union-find is that it is one of the only significant data structures where sustained research hasn't either produced an immutable version with the same performance as the mutable one or demonstrated that one can't exist.

It's a great puzzle, but it's not a huge drawback because subbing in IntMap or something really _does_ give adequate performance for typical union-find cases (unification or the like). Which is to say, the performance gap left to be closed is almost certainly _not_ where the important improvements to unification algorithms are made (which have to do with being able to impose a lot more particular structure on the types of things being unified, etc).

Post reply on HN