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

Switch function

On 2/3/19 5:40 PM, Avi Gross wrote:

> Bottom line, does anyone bother using anything like this? It is actually a
> bunch of hidden IF statements matched in order but may meet many needs.

I sure don't.  In the rare case that I might use a switch
statement in another language, I just use a series of elifs,
or maybe a dictionary I build once and use over and over (a
habit left over from the old days of extremely constrained
systems, when medium-to-large lookup tables and simple logic
was better than many kinds of runtime computation).

If it gets unweidly, I think harder about how to isolate the
"switching" from the results, and usually end up with a
collection of smaller functions to do the work, or high order
functions, or maybe some sort of object oriented polymorphism
as a last resort.