[Scons-users] conventions for AddMethod
Bill Deegan
bill at baddogconsulting.com
Sun Dec 10 14:11:18 EST 2017
I have not strong opinions on this one.
Pythonically the _ should represent functions which shouldn't get called
(or called directly) from outside the module.
I'm not sure in any case calling any of the methods added via AddMethod
outside of the env, or DefaultEnvironment make sense.
So you could argue _ should be used for all of them.
That said, I don't think it's worth changing all the existing code from one
to the other.
(Lots of other tasks to be done would provide more utility for the project).
-Bill
On Sun, Dec 10, 2017 at 9:15 AM, Mats Wichmann <mats at wichmann.us> wrote:
>
> 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?
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20171210/b96139ea/attachment.html>
More information about the Scons-users
mailing list