views:

391

answers:

2

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?

+1  A: 

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?

Arthur Ulfeldt
+2  A: 

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.

clartaq