lua-users home
lua-l archive

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

On Jun 22, 2011, at 10:50 AM, James Graves <> wrote:

> David Kastrup <> wrote:
>> Alexandre Rion <> writes:
>>> I also think that labels should be per block.
>> +1
>> Local variables are per block.  This makes it possible to have
>> self-contained syntactical entities with minimal outside interaction.
>> function-local labels break this concept, and it is not clear to me how
>> this would affect label/goto outside of functions.
> I think the one-label-per-function restriction is fine.
> If your function is soooo big that you're losing track of what labels
> you've been using, then you've got other problems.  Having unique
> labels in each function makes it easier for me to read and understand
> your code.
> I would like to encourage all developers to:
> A) Use 'goto' sparingly, of course.  Error handling and a 'continue'
> replacement are acceptable to me.  However, if a little
> re-organization would allow you to use some other control structure,
> that is preferred.
> B) Put as much thought into naming labels as you would naming local
> variables.  Please use descriptive names, such as ::retry_read::
> instead of just ::retry:: and ::skip_blank_line:: instead of
> ::continue::, to draw from some recent examples.
> James Graves

Your suggestions might be a good idea, but the language shouldn't enforce them; thats what coding standards and code reviews are for.  There is a good comment about this in PIL, something to the effect "Lua does not set policy.  Lua provides powerful mechanisms for developers to implement the policies that best suit them."