lua-users home
lua-l archive

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


Fabien wrote:
On Nov 7, 2007 3:05 PM, Jeremy Darling <jeremy.darling@gmail.com <mailto:jeremy.darling@gmail.com>> wrote:

    I like the fall through abilities of C and wish that they existed in
    pascal without having to
    hack them into place.


I think most C developers will agree that unwanted fall-through are a dangerous cause of bugs, so if it were really required it should at least require a dedicated keyword, so that it doesn't happen by accident.

I've just gone over some C code I wrote to see what tradeoffs I could
see in switch and if/else useage.

One of the interesting outcomes was that I was able to consolidate
a lot of tests in one function that was essentially a big if/else
statement that returned one value indicating the state of the structure.

The result was used in a case statement in other functions, and I
ended up using (and commenting like crazy) the fallthrough feature
quite a bit.

In my experience, it doesn't happen very often, and when there are shared parts between cases, there is no case ordering in the switch that satisfy all sharing constraints simultaneously.

Agreed. Once you get beyond more than a handful of cases things get
complicated very quickly...

I'm not sure there's a really compelling argument for switch in Lua.

Most C programmers are unaware of what the compiler is really doing
when it implements switch. In some cases, the result is a big nested
if/else, other times it does some range reduction and lookup.

In some ways, switch is just syntactic sugar for lookup tables or
a nested if as far as the compiler is concerned....

Ralph