I don't think that there is any deeper reason for using Module[{},body]
instead of just (body)
. Technically you are only adding overhead, as small as it might be. From the stylistic point of view I think it just adds complexity, increases what has to be read and -- as your question clearly indicates -- raises questions and adds uncertainty. I don't see any reason to use it and find it somewhat unlucky to appear in a book about Mathematica programming, especially if there is no explanation why it is there (I don't know the book, maybe there is an explanation?).
As it is one of the rare cases where I disagree with Leonids answer some words about his answer: I don't think that the use of Module
is an indication of whether side effects occur or not in general code. Of course you can, as Leonid does, make it a convention in your code to use a Module
with no local variables to indicate side effects, but without declaring that somewhere, it doesn't mean anything to "foreign" readers of the code.
Your example from Sal Manganos books looks like he doesn't use that convention, as Lookup
only has one expression and most probably is side effect free (of course depending on how $bindings
actually looks).
I would even think that the most common use of Module
with local variables is to combine a set of expressions as these:
f[x_]:=(y=x^2;Exp[y]+y)
which have an (observable) side effect in such a way that they are effectively "side effect free", (combined to one side-effect free expression), e.g.:
f[x_]:=Module[{y},y=x^2;Exp[y]+y]
Of course this will generate a local variable and set it to a value (which are side effects) but that are to some extent implementation details and are of temporary and local nature only: to be able to create local variables without observable side effects to the outside world is the reason for scoping constructs to exist in the first place. So you could just as well argue it would be an obvious convention to indicate that a function is (effectively) side effect free if it does use a Module
wrapper...
If I would write code for others to read, I'd probably rather use a comment or usage message or naming convention to document whether a function has side effects or not. Other than that, I prefer to not read any boilerplate code that actually doesn't do anything -- I usually find it hard enough to understand the code that does do something...
Block[{},someExpression]/;True
in question 25522. That's a new level of no-op-ed-ness, the/;True
at the end. It's by the respected @Rojolalalalalalalalalalalalala, so I'm inclined to believe there is something more going on that I don't understand. $\endgroup$