# Which of these two equivalent macro definitions should be preferred?

Consider the following two macro definitions:

\def\setmacro#1{\def\macro{#1}}

\def\setmacro{\def\macro}


Although the two variants of \setmacro have a different \meaning they are equivalent in what they eventually do (if used correctly). In my opinion, the former definition is easier to read while the latter is more flexible and, possibly, more efficient. So which one should be preferred?

-
When such a decision is being made, it is worth thinking about using \let. It's not always possible to use \let in this case, but if it is, it might be the best compromise between efficiency and error checking (see Martin Scharrer's answer). –  Patrick Häcker Oct 7 '12 at 12:07

Note that the second form would still allow a parameter text like \setmacro#1{foo #1 bar} which would expand to \def\macro#1{foo #1 bar}. In most cases you don't want that. Also it requires braces afterwards: \setmacro\foo would lead to \def\macro\foo which would read everything up to the next { as parameter text and then causes problems with error messages which are difficult to understand for an end-user. This case would work with the first definition.
If you define \setmacro as part of a class or package (like \title etc.) I would use the first version. The overhead is not meaningful on modern systems, especially if the set-macro is only used once or twice, but you are avoiding issues if the set-macro is used in a wrong or unexpected way.
Does your note about avoiding issues hold when \def\setmacro#{\def\macro}? –  morbusg Jun 19 '12 at 8:57
@morbusg: This would still cause an error if a user uses \setmacro\foo. Now you get a better error message, but still it doesn't work like some LaTeX users would expect it. –  Martin Scharrer Jun 19 '12 at 9:00