lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


| About disabling code blocks, depending on the situation I use "if nil then
| ... end" or an editor macro like Nick describes.  I think the fact that code
| inside "if nil then ... end" gets parsed is useful.  For the same reason I
| use "if (false) {}" in C++ instead of "#if 0 ... #endif" whenever possible.
| The reason is that code not parsed gets stale.  Just because you chose not
| to execute some code doesn't mean it should no longer be maintained.  It
| would be nice if Lua didn't generate bytecode for such blocks however.


As you say, it depends on solution. A good C compiler should optimise out blocks
that are never entered (if (0)..) but Lua doesnt - I think. If it did this may
be an acceptable solution but the size of the code generated and the speed hit
of all the "if nil" tests is unacceptable. Its bad enough that you cant turn
asserts off in release code, you have to go and comment them out (or global
replace "assert" with "--assert"). Conditional compilation and macros are very
useful for debugging. Most of the time you'd want to use "if flag..." to comment
stuff out and since values arent known until execution (or 2nd pass?) I'm not
sure how easy optimisation like this would be without preprocessor directives.

As Philippe points out: "_=[[ comment ]] _=nil" can be used. In Python you could
use """comment""" strings which have no reference and are disposed of. Perhaps
[[comment]] should be made valid (ie. no assignment) for multiline comments.

Nick