Four reasons that PureScript is your best choice to build a server in 2020
4th Sep 2020
Today, on the #purescript channel of the functional programming Slack, I wrote "I think PureScript is the best choice for anyone building a server in 2020." To that, Peter Andersen asked:
Wow! What are the key things in your eyes that make it the best?
Now if that's not an incitation to blog, I don't know what is!
So, here are four reasons that PureScript is the best way to build a server in 2020. I'll tl;dr them here, but you should stick around for the bonus reason at the end as well!
- Hello world
The time it takes to get a server up and running in PureScript is as fast as a
Then mosy on over to
src/Main.purs and paste:
Then, in bash:
curl http://localhost:3000/hello, get back
spago run in your
package.json for the run command.
Then you just need a
Main.js in the same folder:
And PureScript automatically links them up.
PureScript is in the same category of languages as Haskell, Idris, Agda and Coq. Because these languages lend themselves well to proving things, really smart people tend to flock to them, which means the discussion is usually pretty heady and newbs can get easily lost.
However, this discussion masks the reality that functional languages are no more difficult to get started in than other ones. Imagine that you need to write a function that increments positive integers and returns some nullish value for anything less than 0. Compare an implementation in Python to the same in PureScript.
I've shown these "Rosetta stone" examples before many-a-coder and have yet to find someone that feels one is inherently more difficult than the other.
If I were a betting person, I'd bet that the type safety and clean, readable code that come with the Haskell family of languages will save you many-a-bug in production and cause you to never work with anything else. But alas, I don't bet. The only point I'll make here is that you don't need to have ten years of software development under your belt to grok PureScript. Getting up and running is no different than learning Python.
...a quick aside to those of you who are into FP and swear up and down by it. PureScript is not as full featured as Haskell, and doesn't have out-of-the-box dependent types like Idris/Agda, but it has a minimalistic feature set that allows you to do most of the stuff you'd actually want to do in a real-world app. Plus, it is way easier to ship than Idris.
The PureScript community has an active, non-toxic Discourse and Slack populated by helpful people that answer each others' questions and share resources. Additionally, most libraries you'd ever need for a basic server have already been written with ample documentation on Pursuit, and novel ideas are being explored all the time.
A lot of PureScript coders also use dhall as an alternative to JSON for configuration. If you use
spago as I did above, you're using
dhall and you'll see
dhall files in your directory. For anyone that has ever been hit by a configuration bug, you know the importance of getting config right early on in a project. PureScript+Dhall is an unbeatable combo in this regard.
I promised you a bonus, and here it is. While Meeshkan is an equal-opportunity tester, we have additional bells and whistles in our service that we use if you provide us with certain assets like an OpenAPI spec or GraphQL schema. We also have tools that use the types of certain languages to create even more powerful tests, and PureScript is on the list. So by going with PureScript, your service will be more testable by Meeshkan. As our stack becomes more mature, we regularly open-source PureScript libraries to help folks build better servers and write more powerful tests.
PureScript is still in early-adopter mode, and the community is tiny. I personally was reluctant to try it out at first because I didn't see the point over using Haskell. However, the velocity of development/deployment, the limited feature set one can wrap one's head around, and the portability won me over. The next time you're building a server, or even in your current server if it is in a language to which PureScript compiles, give PureScript a shot!
Don’t miss the next post!
Absolutely no spam. Unsubscribe anytime.