peerreynders

peerreynders

[Functional Programming] An Outsider's Guide to Statically Typed Functional Programming (self-published/Leanpub)

An Outsider's Guide to Statically Typed Functional Programming

An Outsider’s Guide to Statically Typed Functional Programming
by Brian Marick

This book is about using statically typed functional programming in messy domains. It’s written by someone who found the typical arguments for static FP unpersuasive, both because they focus on overly tidy domains and also because they emphasize principles at the expense of practice (the idioms and habits programmers use).


Dynamically typed functional languages like Clojure and Elixir are now at the point where I feel comfortable basing a commercial application on them. If you use Clojure instead of Java, or Elixir and Phoenix instead of Ruby on Rails, you’ll be fine. Your app might still fail, but it won’t be because of the technology stack.

Statically typed functional languages like Elm, Purescript, Haskell, or Idris are definitely becoming more popular, but (in my opinion) are not clearly safe bets for mainstream applications. By “mainstream”, I mean:

  • Applications that require only “ordinary” reliability. I sometimes see HTTP 500 errors on websites. I shrug and try again. Netflix via my Amazon Fire media player occasionally gets stuck loading a TV show. I shrug, back out, click on the show again, and it works. This restriction to ordinary reliability matters, because the static FP languages are much more obviously useful in cases where runtime errors can kill people.
  • Applications that work in messy domains. Messy domains are ones like payroll systems that have to deal with decades of special cases negotiated by unions. Or enterprise applications with a long history of salespeople making special deals to close big sales–deals that require special-case code somewhere in the system. Or, generally, any application in direct contact with people who can’t be forced to behave in a consistent, “lawful” way.
  • Applications that are continuously growing new features. Sometimes one of those features forces a rethink of a domain model, and a major challenge is getting the architecture to a state where such rethinking doesn’t have a ripple effect that makes every change hugely expensive.

The programmers who work on mainstream applications are rarely the target audience of the static FP literature. They are exactly the target audience for this book. My goal is to make the most compelling case I can that static FP will give you new abilities, especially new abilities for modeling a messy domain riddled with exceptions to the rules. I aim to do that by teaching you idioms, habits, and design patterns that can make this style of programming an ordinary practice for you to perform–rather than a pile of ideas for you to connect.

(For early readers, I should note that I am not yet myself convinced the case is compelling, and I don’t yet know nearly enough of the idioms and patterns. I’m learning as I write, something I’ve always found very effective (but grotesquely inefficient). I warn you of this because I might decide the case is not strong enough. Which will leave this book in an interesting place: “Here’s many pages of explanation of something that turns out not to be good enough. Sorry!”)

As far as the mechanics go, I’m taking what I think is an interesting approach. I’m beginning with Elm, the friendliest but least powerful of the common static FP languages. I’ll then move on to Purescript, a more mainstream, more powerful, but more difficult language. I think learning Purescript as an “add-on” to Elm will be simpler than learning Purescript alone. Both Purescript and Elm are languages that aim to be production-ready alternatives to JavaScript. Finally (but tentatively), I’ll cover Idris, a cutting-edge language that adds new ideas onto Purescript.

https://leanpub.com/outsidefp

https://twitter.com/mfeathers/status/867197676823117825

Most Liked

peerreynders

peerreynders

Well, if we’re only listing Books that can be classified “learning Elixir” books then maybe it’ll have to go. But to be perfectly honest when I selected “Books” it wasn’t clear to me that it was a subcategory of “Learning Resources” - frankly it belongs more in the realm of “other Books of potential interest related to functional programming”.

gregvaughn

gregvaughn

It’s interesting to see this book here. I’ve been following the author, Brian Marick, on blogs and twitter for many years. He’s got some great insights, but as he admits in the blurb above, he’s learning as he writes and is not sure he’ll have a compelling enough case in the end for static typing. This book is more about static typing in functional languages than about functional languages in general.

I’ll likely read the book once he’s finished depending on whether he convinces himself the case for static typing is strong enough or not. At this point, I would only recommend it for those really wanting to explore the implications of static typing in general because I don’t think it’ll teach much that is applicable to Elixir.

peerreynders

peerreynders

My suspicion is that he will get to “it depends” - i.e. there are circumstances where the rigor of static typing is valuable but there are cases where it overcomplicates matters leading to lots of accidental complexity. In the case of Elm and Purescript you can always decide to push functionality into the JavaScript realm and simply interface with it as needed.

However I’m also hoping that another conclusion will emerge: designing / thinking in types is always valuable - regardless whether you are forced to do so by a static type system or whether you are merely disciplined enough to consistently use typespecs in a dynamic language as a way to explicitly express the shape of data that you expect to be handling (even if the guarantees of success typing are rather weak compared to strong static typing).

Dabbling with Elm code really pushed me to use typespecs much more in Erlang/Elixir simply to demonstrate to myself that I had thoroughly considered the shape of data that I’m dealing with.

Where Next?

Popular in Books Top

PragmaticBookshelf
Bruce A. Tate @redrapids and Sophie DeBenedetto @SophieDeBenedetto edited by Jacquelyn Carter @jkcarter The days of the traditional requ...
New
PragmaticBookshelf
Bruce Tate @redrapids edited by Jacquelyn Carter @jkcarter Elixir is a functional language that crosses many boundaries. With a syntax b...
New
AstonJ
by Ben Marx, José Valim, Bruce Tate Bring Elixir into your company, with real-life strategies from the people who built Elixir and use i...
New
AstonJ
by by Fred Hebert Erlang is the language of choice for programmers who want to write robust, concurrent applications, but its strange ...
New
Eiji
The Ecto recipes were originally written for the “What’s new in Ecto 2” ebook and then made open-source by Plataformatec. Since then, the...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27861 124
New
tristan
Adopting Erlang is a collaborative effort between myself (Tristan), Fred Hebert and Evan Vigil-McClanahan. It is an ongoing effort to gat...
New
kokolegorille
https://www.packtpub.com/application-development/mastering-elixir A new resource, it seems… I did not read it (yet?). Anyone?
New
PragmaticBookshelf
Ellie Fairholm and Josep Giralt D’Lacoste edited by Nicole Tache The days of separate dev and ops teams are over—knowledge silos and the...
New
AstonJ
https://github.com/happi/theBeamBook A short and personal history of the book I, Erik Stenman (Happi), started writing this book back ...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

We're in Beta

About us Mission Statement