Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would one create a Clojure Lint?

One example of a common Clojure programming error is expecting a lazy expression to be evaluated for side-effects. On the surface it appears checking for unused lazy expressions would be helpful. What would be the best approach to identifying this and other common mistakes? Should the core compiler check for these situations, or should it be the domain of a lint program to detect? What would be a good way to start the implementation?

like image 771
Timothy Pratley Avatar asked Dec 21 '09 04:12

Timothy Pratley


2 Answers

How about:

  • Multimethods with no :default method
  • Missing documentation strings
  • In cases where the argument to a function is always the same type, suggesting type hints on arguments
  • Pointing out multiple copies of identical anonymous functions
  • Pointing out tail recursion and suggesting restructuring
  • Using a macro where a function would suffice
  • Unused arguments, especially & rest type arguments
  • Where a function will use BigNums instead of just ints or floating point

Not sure how these checks would be implemented, but they would sure save me from myself a lot of the time.

like image 117
clartaq Avatar answered Sep 28 '22 07:09

clartaq


A couple of ideas just to get things started; it could detect lazy code that can never be realized, or point out areas where reflection will be used. Though in general is clojure a little young as a language to express a common set of provable mistakes?

like image 38
Arthur Ulfeldt Avatar answered Sep 28 '22 09:09

Arthur Ulfeldt