[patch 4/3] Header file reduction - Tools for contrib
David Malcolm
dmalcolm@redhat.com
Thu Oct 8 16:31:00 GMT 2015
On Tue, 2015-10-06 at 14:02 +0200, Bernd Schmidt wrote:
[...]
> > No commenting on the quality of python code... :-) I was
> > learning python on the fly. Im sure some things are QUITE awful.,
[...]
> > + def ii_base (iinfo):
> > + return iinfo[0]
> > +
> > + def ii_path (iinfo):
> > + return iinfo[1]
> > +
> > + def ii_include_list (iinfo):
> > + return iinfo[2]
> > +
> > + def ii_include_list_cond (iinfo):
> > + return iinfo[3]
> > +
> > + def ii_include_list_non_cond (iinfo):
> > + l = ii_include_list (iinfo)
> > + for n in ii_include_list_cond (iinfo):
> > + l.remove (n)
> > + return l
> > +
> > + def ii_macro_consume (iinfo):
> > + return iinfo[4]
> > +
> > + def ii_macro_define (iinfo):
> > + return iinfo[5]
> > +
> > + def ii_src (iinfo):
> > + return iinfo[6]
> > +
> > + def ii_src_line (iinfo):
> > + return iinfo[7]
>
> That's a lot of little functions with pretty much no clue for the reader
> what's going on. It looks like maybe there's an array where a struct
> should have been used?
FWIW, this kind of thing is often made a lot neater and easier to debug
by using "namedtuple" from within the "collections" module in the
standard library:
https://docs.python.org/2/library/collections.html#collections.namedtuple
which lets you refer e.g. to field 5 of the tuple as a "define"
attribute.
iinfo.define
and avoid all these accessor functions (and you can add methods and
properties, giving e.g. a "list_non_cond").
Not that I'm asking you to rewrite it; merely that namedtuple is one of
many gems in the python stdlib that are worth knowing about.
[...]
Hope this is constructive
Dave
More information about the Gcc-patches
mailing list