How to write Inline Functions in Python?

David Brown david at no.westcontrol.spam.com
Thu Nov 14 03:20:33 EST 2002


"Delaney, Timothy" <tdelaney at avaya.com> wrote in message
news:mailman.1037254879.20737.python-list at python.org...
> > From: arivu at qmaxtest.com [mailto:arivu at qmaxtest.com]
>
> > Can any one please explain how to write a Inline Function in Python?
>
> No. See below.
>
> > Is Inline Functions available in python?
>
> No.
>
> 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.
>
> Tim Delaney
>

While what you write is technically correct, inline functions are still
important in C and C++ because computers are still slow (depending on the
task, of course) and compilers are still stupid.  As long as C(++) compilers
still generate seperate completed object code modules that are only
collected by a linker, then you are going to get a performance hit whenever
a small function from one module is used by a function in another module.
The only way around that (until C compilers and linkers really do become
smarter) is to put inlined functions in headers.  It's ugly, it's a
maintanance problem, but it's the only way.






More information about the Python-list mailing list