Point-Free is a video series about functional programming and the Swift programming language. Each episode covers a topic that may seem complex and academic at first, but turns out to be quite simple. At the end of each episode we’ll ask “what’s the point?!”, so that we can bring the concepts back down to earth and show how these ideas can improve the quality of your code today.
We’ve got so much we want to talk about, but just a quick overview of the things we have planned:
Side effects are one of the greatest sources of complexity in an application, and every program has this in common. After giving a proper definition of side effects and pure functions, we will show how to push the effects to the boundary of your application, leaving behind an understandable, testable and pure core.
The most basic unit of code reusability comes in the form of simple function composition. We will show how that by focusing on small atomic units that compose well, we can build large complex systems that are easy to understand.
You’ve already seen how the type system helps prevent bugs by making sure you don’t accidentally add an integer to a string, or call a method on a “null” value, but it can do so much more. You can encode invariants of your application directly into the types so impossible application states are not representable and can never compile.
Algebraic problems are nice because they carry structure that can be manipulated in predictable
and understandable ways. For example, if you have ever simplified a complicated boolean
expression that looked like
a && b || a && c to look like
a && (b || c), you were exploiting
the algebraic stucture that
&& have. Many programming problems can be given an
algebraic structure that allows one to manipulate the problem in the same way you factored out
a && from that expression.
And so much more…
When we open-sourced the entire iOS and Android codebases at Kickstarter, we saw that it was one of the best resources to show people how to build a large application in the functional style. It transcended any talks about the theoretical benefits or proposed simplifications. We could just show directly how embracing pure functions allowed us to write code that was understandable in isolation, and enabled us to write tests for every subtle edge case.
We wanted to be able to do that again, but this time we’d build an entire website in server-side Swift, all in the functional style! This meant we had to build nearly everything from scratch, from server middleware and routing to HTML views and CSS.
We discovered quite a few fun things along the way, like using Swift Playgrounds to design pages in an iterative fashion, and came to the conclusion that server-side Swift will soon be a viable backend language rivaling almost every other language out there.
You can view the entire source code to this site on our GitHub organization, https://github.com/pointfreeco.