Re: Functional programming

Hisham <[email protected]>
Newsgroups gmane.linux.distributions.gobo.general
Message-ID <CAJpkDYdjWGNPJ8JuuQkhqdOwe=sB2uu1jbZmgYFZsVeY+KGA9Q@mail.gmail.com>
On 6 September 2015 at 18:47, Liam Proven <[email protected]> wrote:
> On 6 September 2015 at 19:16, Sergio Tortosa Benedito
> <[email protected]> wrote:
>> Anyone has tried it?

Yes, currently I'm a PhD student in a Programming Languages research
lab, and I've done a bit of functional programming, so here's my two
cents:

>> I've been looking at it for some days (thought I
>> already knew it), and has anyone tried it? Specially since my main point of
>> interest are "stateful" apps (such as GUI and games),

This is hard in the beginning, but there is one a-ha moment when you
realize that the difficulty there is because we're not used to
"taming" state, and we just scatter it all over in our imperative
programs. After doing functional programming, having implicit state
everywhere feels a bit like programming with global variables: you're
not compartmentalizing the impact of an important aspect of your
program. The feeling that "the contents of this function don't affect
the code anywhere else than its return value" is pretty good.

Imperative programming still beats functional programming in terms of
writing high-performance/low-memory code easily, though, but we often
overestimate which parts of our programs need to be optimized, anyway.
I also find debugging FP code harder, but then I have a lot more
experience with imperative.

>> it's worth the change
>> in style of thinking?

Yes. Getting some experience with it affects even the way you write
code in imperative languages. You become more atuned to the
relationships of data, and manipulating functions as first-class
objects becomes second-nature, and not an "advanced feature", often
leading to very elegant code.

>>  And it ends up being easy to kniw what it's written?

Like any other language, that depends more on the writer than the
language. When I write Haskell, I tend to split my code in a gazillion
short functions, so that makes me come up with lots of names, for each
bit of the code. With good names, the code becomes easy to follow.

But it's as easy to write hard-to-read Haskell as any other language
(it has an extensive standard library and code that uses it a lot can
be hard to follow if you don't know what all those functions do).

> Haskell is more of an academic plaything:

It might still be _more_ of an academic plaything than an industry
language, but this has been changing in recent years. Major companies
such as Facebook have been using Haskell in the development of some
parts of their infrastructure.

-- Hisham
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.