lua-users home
lua-l archive

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

My very own trouble with 'switch' is that I'm never sure how exactly it works. I keep forgetting whether this particular language's switch has falltrough, rules for the types of guards, whether stuff can change mid selection, etc. I bet once you're confident with some particular switch it all falls into place, but spend some time not using them, or worse yet using them in another language, and they get ugly again. I have no problem with big amounts of "design" in specialist features, say "goto", but for an alternative of a bunch of if-then-else or a table indexing seems like to much stuff to have doubts about.


On 12/06/14 03:33, Sean Conner wrote:
It was thus said that the Great Coroutines once stated:
On Wed, Jun 11, 2014 at 10:51 PM, Andrew Starks <> wrote:

I find myself using multiple lines with Lua, very often. It's almost a style
of programming, especially for obvious things, like passing a function
literal as an argument.
Before I say more I just want to say that I rarely need the
fallthrough behavior of a C-like switch.  I only need it when handling
exception-like code using pcall() -- I feel the handling is similar.
   I've found that I don't really miss switch in Lua.  The cascading if/else
doesn't bother me all that much [1] and I've also used a table where others
might have used a switch statment [2].

While this looks concise and is easy to skim for me, it goes against
the style preferences of others I show my Lua with.
   As long as you are semi-consistent, it's all good [8].



[2] [3]

[3]	That module, [4] and lzlib and you can read ZIP
	files.  If you want to write ZIP files, you'll need [5][6].  This is the result of my working on
	LEM [7] files.



[6]	Encryption not supported, nor is all the various extra file data,
	but what I do have can pretty much deal with a lot of ZIP files.


[8]	I have a highly idiosyncratic C and Lua coding style myself.