lua-users home
lua-l archive

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



On Wed, Jun 11, 2014 at 3:29 AM, Axel Kittenberger <axkibe@gmail.com> wrote:
But a switch statement in most script languages (like in _javascript_) is syntactic sugar for if/else! That has always been the argument from the Lua team to why there is no switch statement in Lua. Not like for example in C where it is in fact a computed goto.

Well, i don't like to nitpick either, but words do mean something and I think it is at least somewhat useful to define this term.

That the Lua team rejected the switch statement because "if/elsif" took care of enough of the use cases for `switch` does not make it sugar. A switch statement often (not always) has fall-through, or has some other kind of unique behavior that justifies its existence, even though it's largely duplicative.

However, by the logic you're following, are closures sugar for objects? I'd think you'd say 'no', but then where do you draw the line?

When something does exactly the same thing as something else, but in a less verbose (and usually more obfuscated) way, then it is sugar. Sugar is syntactic. That's why it's called "syntactic sugar"


--Andrew