I’ve been thinking a lot recently about the methodology behind functional programming, not least because of my contributions to the Essential Scala book I’m writing with Noel.
I decided to make this the subject of my talk at Scala Exchange this year, and I used the design of a data validation library as an example.
Here’s the abstract, a link to the slides and code samples, and a link to a video of the talk:
Sooner or later, all developers have to deal with data validation: reading input from the user, checking it, and reporting errors back to the UI. For such a ubiquitous task, validation is surprisingly subtle and complex. Fortunately it also serves as an excellent demonstration of using a functional approach to library design.
In this talk, aimed at beginner-to-intermediate Scala developers, Dave will build a simple, powerful, composable data validation library from the ground up, explaining at each stage the design choices made and the benefits gained from the Scala programming language.
The talk will cover such topics as:
- How do we model errors and warnings?
- How do we bind validation to our data and the user interface?
- How do we make validation modular and composable?
- How do we deal with cross-cutting concerns such as async and dependency injection.
You may be asking the question: why data validation? There are two reasons:
First, I have been asked “How should we write validation code in Scala?” by clients on at least three occasions this year.
These were all companies who were new to Scala, and perhaps they were looking for a library to do things for them. Data validation is a subtle problem, though. Everyone has their own set of bespoke requirements, making general-purpose libraries difficult to write, which brings me to my second point…
Writing a validation library is actually very straightforward in a functional language. Rules are functions, results are algebraic data types, and everything else is just composition.
Updated 1st January 2015: A video of the talk is now online at the Skills Matter web site (free registration required).