[sheepdog] [PATCH RFC] employ gnu99 style of GCC
Hitoshi Mitake
mitake.hitoshi at gmail.com
Mon Apr 29 16:17:04 CEST 2013
At Mon, 29 Apr 2013 21:43:05 +0800,
Liu Yuan wrote:
> > Dividing these switches into functoins and jump tables would be a
> > better way, but it cannnot be optimal always. Because the local
> > variables in original function should be passed as their
> > parameters. If there are many local variables, we have to implement
> > these functions which has many parameters, or declare them as global
> > variables.
> >
>
> I think it depends. Switch case is easier to write and concise enough to
> handle bundle of function return cases. We can even write helper
> functions for case handling if one is too big. But if we have more than
> 10 cases to handle and handling code is complex, it is always better to
> use jump table to get neater code.
>
> Speaking of too many local variables, I'd like to see it as a warn of
> unstructured big functions which does poor abstraction and layering,
> which is hard to understand and patch as more dependencies and
> assumptions added as time go by. If we have to pass many variable
> between functions, then it is better to group them as a struct rather
> than plainly sharing them in a big function as local variables, this is
> very much like sharing too many global variables between source files.
Yes. I agree with your opinion. If there are too many local variables
and too many cases, packing these variables into one struct + jump
table would be an optimal way.
Interleaving statements and declarations is not a radical way for
improving readability and keeping code clean. We should consider
employing more radical ways e.g. jump tables for keeping code simple.
Thanks,
Hitoshi
More information about the sheepdog
mailing list