read


read
or learn more

fun.js

Mar 20, 2013

A few years ago I got the idea that it would be fun to implement a variant of Scheme targeting the JVM. During my search for different ways to implement numerics I looked deeply at the implementation of two languages: JScheme and a little-known language Clojure. During my explorations with these two languages and the ways that they handled and implemented numerics I quickly came to a humbling realization: there was no possible way that I could make a language as good as either, and along the way I happened to fall in love with Clojure. So as a result I completely abandoned my piddly Scheme and adopted Clojure outright.

However, over the months that followed the time that I had spent in the interpreter nagged at me. It seemed that perhaps I could use what I learned to good effect. Rather than attempt to complete the Scheme for the purposes of use, I instead put together a draft of a single book to introduce two different topics:

  1. Functional programming
  2. Programming language interpretation and compilation

This book was intended to use JavaScript to implement a variant of Scheme piecewise; building a more capable interpreter as the book progressed. I got as far as re-implementing much of the original language in JavaScript and completed a fairly detailed outline and a couple of chapters. However, along the way I got sidetracked on writing another book called The Joy of Clojure and my JS-Scheme book was derailed.

During my research for the The Joy of Clojure I happened upon a book called Lisp In Small Pieces that simply blew my mind. Aside from the powerful content itself, the very premise was… wait for it…

to implement a variant of Scheme piecewise; building a more capable interpreter as the book progressed.

— me, in this blog post, like 7 seconds ago

As you can imagine, I completely abandoned my JS/Scheme book idea.

However, over the months that followed the time that I had spent on the interpreter, outline and chapters nagged at me. It seemed that perhaps I could use what I learned to good effect. Rather than attempt to complete the Scheme for the purposes of a book, I instead put together drafts of two different books to introduce two different topics:

  1. Functional programming
  2. Programming language interpretation and compilation

Instead of creating a language for the purposes of building an understanding of functional programming, I could instead write one book introducing functional programming for a language that could use such a book and another introducing how and why languages are created the way that they’re created. About a year and a half ago I started both of these books, but as it stands only one has managed to come to fruition so far.

Introducing Functional JavaScript

Through an odd set of circumstances my name, via Jeremy Ashkenas, found its way onto the desk of Mary Treseler at O’Reilly and I inked a contract to complete my book as an O’Reilly venture:

funjs

When

As of a month ago the book was effectively complete and is now making its way through the internal review process.1 The expected release date is June 2013, but the book is available for pre-order from Amazon now.

Why

There are many good books on JavaScript that cover, to varying degrees, functional programming. However, there is a surprising lack of JavaScript books that tackle the topic full-on. I am an advocate of functional programming and functional programming techniques, so I think that there are many lessons from functional programming languages like Clojure and Haskell that are directly applicable to JavaScript. While I’m am advocate, I’m fairly non-dogmatic and pragmatic about functional programming, so I think there is room for a book on the topic that takes a realistic and fun, yet principled perspective.

What

The book uses and builds on the Underscore library to highlight and explain functional programming techniques. It’s not intended as a full reference to Underscore.js, but is instead about functional programming in JavaScript. You have to wait for the release to see it all, but a high-level outline of the chapters is as follows:

  • Chapter 1: Getting started
  • Chapter 2: First-class functions and applicative programming
  • Chapter 3: Variable scope and closures
  • Chapter 4: Higher-order functions
  • Chapter 5: Function building functions
  • Chapter 6: Recursion
  • Chapter 7: Purity, immutability and policies for change
  • Chapter 8: Flow-based programming
  • Chapter 9: Programming without class

This book has been a long time in the works in some form or another and I think that despite all of the setbacks getting here, now is the best time for it to see the light.

I hope that you’ll enjoy.

hacker news discussion

:F


  1. Additionally my good friend Rob Friesel has taken some of his precious time to provide valuable feedback along the way. 

17 Comments, Comment or Ping

  1. WTF, dude — that is great! Pre-ordered.

  2. Also, I love the question mark on the Amazon version of the title. It makes it so much more intriguing.

  3. Thanks Clinton, I really appreciate your support.

  4. F_D

    It’s been (and continues to be) fun to review this book. I can’t wait to see it hit the shelves. (Also: better to link to blog.founddrama.net and not so much to founddrama.netwhich just reminds me how badly I need to update that Random Eye-Spy Generator…)

  5. Nice! I don’t even like going near JS these days, when I can help it. Nonetheless, I will be buying a copy of this book, knowing that when I do have to enter those murky waters, I will be all the better prepared with functional tools in hand. ;~)

  6. You should touch on other javascript functional libraries like oliver steele’s or fancy https://github.com/anfurny/Fancy

  7. Hey Michael, how funny, we are just in the review process of our book (also at O’Reilly) covering functional programming techniques in JavaScript! It is in German, and with lots of tasty Curry recipes we explore currying in programming and cooking at the same time. :)

    Our book is called “Das Curry-Buch” (the curry book) and you can find it here: http://is.gd/currybuch

    Check it out, I think there cannot be enough books on functional programming! :)

  8. david karapetyan

    When is the one about interpretation coming out? That sounds way more interesting.

  9. Hey Michael, how funny, we are just in the review process of our book (also at O’Reilly) covering functional programming techniques in JavaScript! It is in German, and with lots of tasty Curry recipes we explore currying in programming and cooking at the same time. :)

    Our book is called “Das Curry-Buch” (the curry book) and you can find it on the German Amazon.

    Check it out, I think there cannot be enough books on functional programming! :)

    PS: My other comment is stuck in your moderation queue, because of a link I guess, sorry about that.

  10. @Alex

    Underscore takes center stage but I plan to talk about other FP.js libraries including Steele’s.

  11. @Stefanie

    Although I cannot read nor speak German, I’m seriously considering your book for the title alone. Best of luck with your release.

  12. Wow. I just released a Python book (Treading on Python Vol 2) that could be considered “functional” Python. A whole third of it is devoted to functional programming, and the rest to decorators and iteration (which could be considered functional as well).

    I think it is wonderful that what most people consider non-functional programming languages are being introduced to this powerful programming paradigm. (Especially with the number of programmers these days that weren’t required to study languages in school and have some exposure to functional constructs).

    Best of luck with your book! (Also, I’d love to see a writeup comparing different publishers and their styles).

  13. This is Paul Krill, a reporter for InfoWorld.com. I would like to speak with you about functional JavaScript. I can be reached at paul_krill@infoworld.com.

  14. Tony aka pixelBender67

    I can’t wait to read your Functional JavaScript and the Joy of Clojure, both of which I just purchased :p

  15. I think this book is a great idea. Too much received wisdom in educational Javascript deals with obscure meta-aspects of the language and prescribes rules on what to avoid or deals with very specific examples of how to construct larger patterns — and as a result those of intermediate level tend to get stuck in an ignorant dogma of externalised learning, unable to understand or learn from the great frameworks that currently lead the way in JS app development.

    Have you read Javascript Allongé? (https://leanpub.com/javascript-allonge) This is a book that, while ideal for the absolute beginner, does a power of good in dealing first and foremost with functions — var is only brought in a tenth of the way through. I’d be interested to know how Functional Javascript compares in scope (haha!) and focus.

  16. I’m looking forward to this. I’ve added it to my wishlist. Chapters 7 and 8 sounds especially interesting. Thanks for writing this!

  17. fogus: fun.js

Reply to “fun.js”