A side quest on Crystal and Marten

Created: by Pradeep Gowda Updated: Feb 22, 2024 Tagged: crystal · marten · ruby

This week, I’ve been on a little tweeting frenzy about OCaml and how the developer experience leaves much to be desired.

Earlier today, I saw Zed Shaw’s tweeet from 2022 about Marten web framework. It is a web framework for Crystal Programming Language. Crystal is a compiled Ruby-esque language.

I had been aware of Crystal for a while, but I didn’t feel the need to try it as a regular Pythonista, and when I did try, I had run into issues.

But, Zed’s comment about Marten – “Looks a lot like old school original RoR with that classic Model-View-Controller setup.” piqued my interest, because Rails really nails the developer experience for MVC based CRUD application development. But, switching to Ruby from my typical Python (Django, Flask) based setup doesn’t make much sense given I’m already familiar here, plus there are no other gains especially speed. Crystal is faster than both Python and Ruby and that does count for something.

Anyway, the docs for Marten were quite pleasant, and I was able to breeze through a few pages of the tutorial without much friction. Yes, without much friction. I think this matters. A lot.

Crystal’s dependency manager is Shards. It also acts as a project scaffolding tool via the shards init sub command.

shards init app happier results in a dev dir like this:

➜  happier git:(main) ✗ tree .
.
├── LICENSE
├── README.md
├── bin
│ ├── happier
│ └── happier.dwarf
├── lib
├── shard.lock
├── shard.yml
├── spec
│ ├── happier_spec.cr
│ └── spec_helper.cr
└── src
    └── happier.cr

5 directories, 9 files

Subsequently guesses at shards install, shards build, and shards run did pretty much what I expected.

Coming back to Marten, the project appears to be mostly the work of it’s creator. The typical developer fear of “bus factor” is often an unexamined one. There are many critical libraries (famously SSL) that have handful of developers. I think it might make sense to embrace a framework that you can learn by reading the code yourself, and possibly fix it.

I have pretty much soured on using slow (runtime) languages for building compute heavy, long-lived services. Languages like crystal, nim, golang, ocaml are worth learning, and more importantly learn by building something small and useful and not get sucked into the FOMO of “a large ecosystem”.

Today I also installed mojo, and it does produce small, standalone executables! and famously can be faster than Rust. But, that’s for another day! Till then, I plan to build something ordinary but fun in Crystal+Marten like a bookmarking service when I find time. Also, OCaml and friends, I think you are already mostly here in terms of developer experience, but doesn’t feel like it.