[Scons-users] conventions for AddMethod

Mats Wichmann mats at wichmann.us
Sun Dec 10 09:15:49 EST 2017


Is there a best-known convention for the use of AddMethod, as in "use
same name as function" or "use different name than function"?

The docs render no opinion on this as both ways obviously work:

When called with the AddMethod() form, adds the specified function to
the specified object as the specified method name. When called with the
env.AddMethod() form, adds the specified function to the construction
environment env as the specified method name. In both cases, if name is
omitted or None, the name of the specified function itself is used for
the method name.

The reason I ask is that if the names are different, it is what you
might call an "IDE confuser" (including IDE-like helpers like ctags)
where it is expected you can associate a call reference in the code with
a function defined somewhere in the code but you don't have that
relationship.  No environment I know of understands the scons AddMethod
to make the binding.

Many places in the scons code itself use the same name:

src/engine/SCons/Tool/javac.py:
    env.AddMethod(Java)

src/engine/SCons/Tool/docbook/__init__.py:
    env.AddMethod(DocbookPdf, "DocbookPdf")


But some do not:

src/engine/SCons/Tool/gettext_tool.py:
    env.AddMethod(_translate, 'Translate')

src/engine/SCons/Tool/xgettext.py:
    env.AddMethod(_POTUpdateBuilderWrapper, 'POTUpdate')


naturally, my project has chosen the second style, where the function
def uses some "hidden" (underscore-prefixed) name and then adds it with
a different public name. Thus leaving me occasionally frustrated.  I'll
try to change these, but was looking for ammunition I might use in the
discussion if there is pushback :)   Pros or cons of one form over the
other?



More information about the Scons-users mailing list