[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Functional programming - Professor Frisby's Mostly Adequate Guide

beegee

1/6/2016 3:35:00 PM

I haven't visited this group in years but I credit it with really teaching me JavaScript (the good and bad parts). So it popped up today in my mail and I revisited. What has excited me lately is a way of developing programs in JavaScript that

a.) moves away from OOP
b.) moves away from JQuery
c.) moves towards planning architectures that are directional and have few side effects.

I am not going to advocate any frameworks. I am going to recommend a book: Professor Frisby's Mostly Adequate Guide to Functional Programming.

https://drboolean.gitbooks.io/mostly-adequate-guid...

The books examples are all JavaScript and subjects range from pure functions, currying, composing and functors among others. It's a short, dense book. The practical benefit of the book I have found is in finding new ways to think rather than new ways to program.

I'd be interested to know other's thoughts on functional programming now that there is at least one serious framework that encourages big app development in JavaScript using its principles.


Bob
3 Answers

Michael Haufe (\"TNO\")

1/7/2016 4:44:00 PM

0

On Wednesday, January 6, 2016 at 9:35:14 AM UTC-6, beegee wrote:
> I haven't visited this group in years but I credit it with really teaching me JavaScript (the good and bad parts). So it popped up today in my mail and I revisited. What has excited me lately is a way of developing programs in JavaScript that
>
> a.) moves away from OOP
> b.) moves away from JQuery
> c.) moves towards planning architectures that are directional and have few side effects.
>
> I am not going to advocate any frameworks. I am going to recommend a book: Professor Frisby's Mostly Adequate Guide to Functional Programming.
>
> https://drboolean.gitbooks.io/mostly-adequate-guid...
>
> The books examples are all JavaScript and subjects range from pure functions, currying, composing and functors among others. It's a short, dense book. The practical benefit of the book I have found is in finding new ways to think rather than new ways to program.
>
> I'd be interested to know other's thoughts on functional programming now that there is at least one serious framework that encourages big app development in JavaScript using its principles.

Scott Sauyet was walking down the same path. We discussed this some time ago:

https://groups.google.c...!topic/jsmentors/0Cj7AEH5Oic/discussion
https://groups.google.c...!topic/jsmentors/wH6X8SDPnbw/discussion
https://groups.google.c...!searchin/comp.lang.javascript/ANN$3A$20RAMDA/comp.lang.javascript/kajDUzrsHkQ/UVQkmnwpMCwJ
http://ramdajs.com/0.19.0/...

In regards to the referenced book, I'm not certain I'm a fan of its approach. It assumes far too much of the reader.

For example: under "Chapter 2: First Class Functions" it talks about Node "modules", MVC, and AJAX. That is only the beginning. It seems quite scatter brained.

Stefan Weiss

1/7/2016 6:05:00 PM

0

On 01/07/2016 17:44, Michael Haufe (TNO) wrote:

> Scott Sauyet was walking down the same path.

And now he's part of the book :)

| Exercises
|
| A quick word before we start. We'll use a library called ramda which
| curries every function by default.

<https://drboolean.gitbooks.io/mostly-adequate-guide/content/ch...

See https://www.npmjs.com...

> In regards to the referenced book, I'm not certain I'm a fan of its
> approach. It assumes far too much of the reader.

Yeah, it could definitely use some editing. For example, a function
named "reduce" is used without introduction or explanation in an example
that looks rather hard to figure out for beginners:

var head = function(x) { return x[0]; };
var reverse = reduce(function(acc, x){ return [x].concat(acc); }, []);
var last = compose(head, reverse);

last(['jumpkick', 'roundhouse', 'uppercut']);
//=> 'uppercut'

There is also pseudocode that looks like JavaScript, but isn't. At least
not with the results it claims:

// associativity
var associative = compose(f, compose(g, h)) ==
compose(compose(f, g), h);
// true

The two resulting functions will be equivalent, but they're not the same
function, so `==` will result in `false` instead.

Then again, this is the first book I've seen that tries to teach FP
using only JavaScript. It looks interesting enough that I'll probably
read the rest of it when I can find the time. I don't mind reading
between the lines a little or looking up features I'm not familiar with.

- stefan

Scott Sauyet

1/18/2016 8:10:00 PM

0

Stefan Weiss wrote:
> Michael Haufe (TNO) wrote:
>
>> Scott Sauyet was walking down the same path.
>
> And now he's part of the book :)
>
> | Exercises
> |
> | A quick word before we start. We'll use a library called ramda which
> | curries every function by default.
>
> <https://drboolean.gitbooks.io/mostly-adequate-guide/content/ch...


Strands of influence are getting a bit tangled. Reg Braithwaite's
_Javascript Allongé_ [1] was a major inspiration for the creation of
Ramda's predecessor. Since then he's talked of using Ramda for future
editions of the book. (He hasn't as of yet, which I think is a good
idea.) Brian Lonsdorf, aka Dr. Boolean taught a course [2] which the
other founder of Ramda and I attended. He was using our barely-known
library for his course, which made us feel it was was ready for wider
distribution. Now his book uses Ramda for many of its examples. Just
today he became a core member of the Ramda team, and added a new side
project to Ramda to expand our nascent Lenses implementation to deal
with things like Prisms and Isos.

I agree that this book still needs work. This has become a common
publishing model: create the book in the open, accepting feedback all
the while. I believe there is discussion of making a printed book from
this material, but perhaps more errors will be caught up front than is
typical with a few technical reviewers.

On the other hand, my feeling is that this is an excellent book. I had
been approached about writing a book about functional programming in
Javascript, and I thought that, while _Allongé_ was excellent, and
Michael Fogus' book [3] was reasonable, the only other book out on the
topic (Dan Mantyla's _Functional Programming in Javascript_ [4]) was
execrable, and so was really considering it. When the _Mostly Adequate
Guide_ came out, I realized that I didn't need to. It was doing
exactly what I wanted to do. So, yes, I'm mostly impressed.


>> In regards to the referenced book, I'm not certain I'm a fan of its
>> approach. It assumes far too much of the reader.

I'm curious as to how you'd like to see it changed. I'm so buried in
the same world he's promoting that I have a hard time seeing such
instances.



> Yeah, it could definitely use some editing. For example, a function
> named "reduce" is used without introduction or explanation in an example
> that looks rather hard to figure out for beginners:
>
> var head = function(x) { return x[0]; };
> var reverse = reduce(function(acc, x){ return [x].concat(acc); }, []);
> var last = compose(head, reverse);
>
> last(['jumpkick', 'roundhouse', 'uppercut']);
> //=> 'uppercut'

Absolutely. I'm sure he would appreciate an issue or pull request at
the Github repostitory for the book [5].



> There is also pseudocode that looks like JavaScript, but isn't. At least
> not with the results it claims:
>
> // associativity
> var associative = compose(f, compose(g, h)) ==
> compose(compose(f, g), h);
> // true
>
> The two resulting functions will be equivalent, but they're not the same
> function, so `==` will result in `false` instead.

Yes, he should have some better way to distinguish pseudo-code from
actual code, and again an issue or pull request would probably be
appreciated.

But there is something fundamental here too. Functional programming
will make little distinction between these two notions. Two functions
which always have the same results for the same inputs, really ARE the
same function from an FP point of view. So, while this is an incorrect
use of syntax, the underlying point is still important.


> Then again, this is the first book I've seen that tries to teach FP
> using only JavaScript. It looks interesting enough that I'll probably
> read the rest of it when I can find the time. I don't mind reading
> between the lines a little or looking up features I'm not familiar with.


What I appreciate about it is perhaps exactly what some don't like. It
doesn't try to build everything in excruciating detail with
mind-numbing definitions. It strikes a reasonable balance between
_how_ and _why_.


-- Scott


[1]: <https://leanpub.com/javascript-a...
[2]: <https://frontendmasters.com/courses/functional-javas...
[3]: <http://shop.oreilly.com/product/0636920028...
[4]: <https://www.packtpub.com/web-development/functional-programming-java...
[5]: <https://github.com/MostlyAdequate/mostly-adequate...