DLint : Expert help writing Daml

For developers of all skill levels, it’s a constant challenge to keep in mind the myriad of ways the code we write could be better. For Daml developers it’s not different. We wish to produce programs that are elegant, efficient, readable by others ... the list goes on. With each PR, we look to our code reviewers to advise us on (at least) the most obvious improvements we could make. This is especially true for Daml newcomers.

One of our main goals with Daml is to make developers extremely productive, and to make it easy for them to build high quality and secure code. The faster a developer gets feedback, the more productive they are. Relying on code review has an unfavorable feedback latency and getting full value can be "hit and miss". Wouldn't it be ideal if, while programming, you had an expert at your shoulder offering advice?

With the linting features we are integrating into the Daml IDE, the developer gets that advice as they type. DLint analyzes your code while you’re typing it, looking for issues and making suggestions on how you might care to improve it. It’s highly configurable (you can turn warnings off and on with granular scope control). The suggestions are easy for programmers of all levels to understand and where it makes sense, provides suggested code. Taking advantage of it is very easy and its use improves code quality!

The image below shows DLint in action. The IDE is warning that it found a block of duplicated code (suggesting an improved version would “factor out” the common block into a function).

mainHere’s another example of the sort of thing it can do. Given this function,

negateDLint provides the following suggestion:

The suggestion here is that we replace our multi-equation recursive function with a one line version using the idiomatic standard library function foldr.

This is an engineering note, so now let’s get a little into how it's implemented.

DLint is achieved by the adaption and integration of Neil Mitchell's celebrated HLint package. HLint is a venerable program with over 15+ years of active development and HLint's use by the Haskell community is ubiquitous. The integration is made possible by the fact that we wrote the Daml IDE in Haskell and that the Daml compiler uses the GHC stack "under the hood".

We do a lot of cool open source work at DA. Part of getting this functionality into the IDE means submitting lots of updates to upstream hlint (to use the ghc-lib-parser package). Also, check out the ghcide project where we're contributing parts of this technology to the Haskell community! Daml itself is completely open source here.

We are super proud of how the Daml IDE is coming along. Try the new DLint features for yourself! You can download the Daml SDK here and this git repository will give you a quickstart exploring some of DLint’s capabilities.