In praise of ocaml

Big +1. I would like to share a similar experience.

I am an OCaml/ML “veteran”, learning ML as my first programming language about 20 years ago.
However, I have not used OCaml since finishing my PhD mid 2019.

I decided a few days ago to see how far OCaml has come by using it for this year’s Advent of Code (my repo, in case you’re curious). The delta in tooling & documentation vs 2019 is INCREDIBLE.

I’m getting ahead of myself, but

dune runtest --watch --autopromote

together with inline/expect tests is a game changer[1], and perhaps the single nicest workflow I have seen, in any programming language, ever.

Other big, notable changes since 2019:

  • Setting up OCcaml 5.1.0 with a local opam switch following the first search result on Google was perfectly smooth and pain free.
  • Similarly for VS Code + Ocaml Platform Plugin.
  • ocamlformat + integration into VS Code (format on save comes by default!) is another game changer. How did we ever live without auto formatting?
  • No more opam and oasis files, thank the lord! In fact, no more manual boilerplate altogether: dune init proj aoc_2023 did the trick!
  • Having documentation right on OCaml Packages · Browse Community Packages is another game changer! Again, how did we live without this?
    • Having the documentation rendered in such an aesthetically-pleasing way certainly makes for a much more joyful experience, too! :slight_smile:
  • It’s become noticably easier to Google random stuff & best practices for OCaml. Big shoutout to https://ocaml.org/, https://ocamlverse.net/, https://realworldocaml.org/, https://cs3110.github.io/textbook, and https://dune.readthedocs.io/, which were the resources I came across and which, without exception, have all have seen HUGE improvements since 2019.
  • API discovery with Merlin auto-completion worked beautifully, right out-of-the-box. (This may have been the case in 2019 already, but I never bothered with Merlin back in the day since I knew the OCaml libraries in-and-out in those days.)

Wow, just wow! All the work that so many people have been pouring into the language and its ecosystem has really paid off.

One more point. I always felt that the JaneStreet libraries were of very high quality, but it seems to me that the story here has improved even further. Basically, base, stdio, ppx_jane, and pxx_inline_test are an incredible foundation that is all I need in 95% of cases:

(library
 (inline_tests)
 (name my_library)
 (libraries base stdio)
 (preprocess
  (pps ppx_inline_test ppx_jane)))

In particular., no need for experimenting with random ppxes unless you need something niche.


  1. Once you set (env (dev (flags (:standard -warn-error -A)))) in your dune-workspace, that is! Since I have given so much praise, allow me one word of criticism: dune’s choice to fail the build on warnings, by default, struck me as really unfortunate. I agree with the “strict by default” mantra that probably drove this decision, but the outcome is bad. Interactive development with dune runtest --watch --autopromote in the way I described is hardly useful with the default, because as little as an unused identifier (which you have all the time during development!) will fail the build and prevent the --autopromote feature I praised so much. Perhaps the dune folks could consider adding a fastdev profile that is dev withouw -warn-error? ↩︎

24 Likes