Mmrnmhrm 0.1 released

Ingo Oeser ioe-news at rameria.de
Tue Aug 21 11:03:23 PDT 2007


Robert Fraser wrote:

> Bruno Medeiros Wrote:
>> However I find that
>> Walter's code is very unstructured and user-unfriendly (to put it in
>> nice terms ;p), and trying to use it in it's original form for IDE
>> features is not the best approach.
> 
> It wasn't meant for extensibility or user consumption at all. But the
> gotos and #defines are making me very sad ;(.

The gotos are OK, since they are usually forward, which reduces code 
duplication. I will always favour goto over code duplication. So I had
no problems following the DMD-FE here (1.020).

But those big monster functions scare me much more. Many other projects
in the D community have the same problem. Maybe screens with 1000 lines
or editors with lots of folding are common, so people don't notice :-/

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;
                }
        }
}

Important: special_case() is module local, invisible outside and may    
        therefore be inlined by the compiler at will.

But defining new methods in C++ is quite a churn and I'm happy, that D makes
that easy be doing it directly in the class scope.


Best Regards

Ingo Oeser



More information about the Digitalmars-d-announce mailing list