lua-users home
lua-l archive

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


On Fri, Aug 12, 2011 at 2:46 PM, Dirk Laurie <dpl@sun.ac.za> wrote:
I don't use interactive debuggers, I put statements like

   print (function_name.." parameters ", ...)
   assert(x, "x not defined yet?  This is a bug")

in the code right from the start and gradually comment them out with
--[[
--]]


Likewise.  I code far more defensively, testing values and failing as early as possible:

function doStuff (mandatory_param)
  if not mandatory_param then error ("Missing param") end
  local foo = whatever() or error ("That wasn't expected")
... etc.

Secondly, there are all sorts of bugs that would be spotted at compile time in C but are only discovered at run time in a language like Lua.  For example, making a typo in the name of a function call, or changing the structure of some data and failing to spot every place it is used.  This can be depressing, because if you made such a change in C(++) you could just work your way through the error list from the compiler and when you'd reached the end you could be reasonably sure your program would do what you want.

To emulate this, write tests that cover as much of the code as possible, and run those tests in place of running the compiler. (i.e. after every small change)

Bringing both these habits back into C++ (where I spend most of my time) has made me a better programmer and I spend far less time in the debugger than I used to.

Peter Pimley