Tuesday, January 27, 2009

Do you practice hygiene (with your macros)?

No. God no.

Hygienic macro systems are a sign of weakness and a false crutch. If you can't write a macro that doesn't inadvertently capture a variable, you shouldn't be writing programs that write programs.

(Been a while since I've ranted. Hasn't it?)

2 comments:

  1. Principally with closures you don't have to use macros at all. This is theoretical assumption. I found, that most of macros I used to use I can write as functions and for performance I can force in-line it. (When used in .hrl -compile({nowarn_unused_function, [...]}).) Macros I'm using only in guards and some very rare cases (fun()-> end is too much verbose for some usage or subtle expansions), but most of this can be solved by parse transformations. In conclusion I found macros are still useful for some subtle performance reasons but I'm using it less often. Impossibility to use own function in guards force macros where I would not like to see one.

    ReplyDelete
  2. Pichi, I agree that you usually want to avoid macros in Erlang. The ugliness of the question-mark prefix just emphasizes this.

    But in Scheme/Lisp there is a long tradition of sugaring the syntax, and there is no cultural prejudice against defining macros. Provided, of course, that your macros don't suck, and that you don't over-do it.

    ReplyDelete