lua-users home
lua-l archive

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


On 2/16/06, Klaus Ripke <paul-lua@malete.org> wrote:
Hi Chris

On Thu, Feb 16, 2006 at 04:35:08PM -0500, Chris wrote:
>    The problem with string error messages can be pointed at in your own
>    example:
>
>         elseif problem == "radiu failure"
how is this different from any typo in a number?
In that you can tell the error in the string, no?

True but a list of "constant" error codes is better than random strings.  The strings will generally be much more descriptive than "radio failure" because error strings are meant for human debugging.  It's all about the amount of data required.  A long string is harder to manage (programatically) than a short error code.  Shorter codes mean less mistakes typing them in also.
 
>    Numeric error codes (or other "fixed" types like an exception) are much
>    more useful for error handling in code.  The strings are good for the end
>    user for sure but code needs a little more.
which is what exactly?

See above and below.

>    This is especially true when dealing with multiple languages like I am.  I
>    have a Lua backend interfacing to C, XML-RPC, and _javascript_.  The text
>    messages are just not reliable enough with all these systems in play
>    (versus numeric codes which would be easy to deal with in all those
>    systems).
obviously you either depend on some constants of whatever type,
which is reliable, or you don't.
How is it easier to use numeric constants cross language than strings?

I see it is nice to use a switch or some bitmasking on numbers in C,
but in Lua, extracting some substring is better supported than bit ops.

Very often the error message describes much more than just a short error.  It's meant for the user to understand what happened.  Code doesn't need such verbosity.  Often you may return different error messages for the same error code.  For instance, you may want to tell the user what happened in a specific way but you want the code to handle the error like some certain class of error.

--
// Chris