Mmrnmhrm 0.1 released
BCS
BCS at pathlink.com
Tue Aug 21 13:03:26 PDT 2007
Ingo Oeser wrote:
Many switch statements used could be separated into module local
> (e.g. static) functions/methods. The code reuse could happen with many
> smaller functions (e.g. each implementing a case) then. But maybe some
> non-gcc compilers used are bad at inlining.
>
> This is very hard to do with C++ classes, but more easy with D or plain C.
>
> static retval_t special_case(context_t context, params...)
> {
> /* handle complex special case with about 10-30 lines */
> }
>
> retval_t big_red_switch(params...)
> {
> context_t context;
> foreach(param in params)
> {
> switch (param)
> {
> case easy_one:
> return foo;
> case easy_two:
> context.bar = param;
> context.boo = xyz;
> break;
> case hard_one:
> context.bar = special_case(context, param, xyz);
> break;
> case hard_two:
> context.bar = special_case(context, param + 3, xizzy);
> break;
>
> default:
> break;
> }
> }
> }
>
funny I known a guy who, in c#, has taken to writing function as class
constructors so that he can have "nested" functions. Sounds a lot like
what you are suggesting.
More information about the Digitalmars-d-announce
mailing list