How to write Inline Functions in Python?
Mark Charsley
mark.charsley at REMOVE_THIS.radioscape.com
Mon Nov 25 08:32:00 EST 2002
In article <mailman.1037254879.20737.python-list at python.org>,
tdelaney at avaya.com (Delaney, Timothy) wrote:
> I assume you're coming from C++. In that case, I suggest you take a good
> hard look at why you want to write inline functions/methods anyway. If
> you're doing it for performance reasons, your compiler is almost
> certainly
> going to be better at deciding what to inline, and has the option to do
> so
> unless you explicitly tell it not to. If you're doing for any other
> reason
> (such as putting code in header files) I strongly advise against it.
>
> Inline was developed when computers were slower and compilers were more
> stupid. These days I see no need to inline whatsoever.
While blatantly off-topic, inlining in C++ has two advantages:
- saves the expense of a function call
- gives the compiler visibility into the function giving it vastly greater
optimisation opportunities.
The first is usually insignificant even in C++, so if performance is that
important, one shouldn't use Python (ooh look: briefly on-topic). The last
is of major importance and is more important with today's smart compilers
than it was years ago with dumb optimisers.
Mark
More information about the Python-list
mailing list