Thread: Python Inline

    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    Python Inline


    Okay well in C++ there is normal functions and "inline" functions, my question is: are there inline functions in python?
    Those people who think they know everything are a great annoyance to those of us who do.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I havn't heard of them being in Python yet. However, it may be possible to create your own.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    How would that be possible
    Those people who think they know everything are a great annoyance to those of us who do.
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    610
    Rep Power
    65

    Smile


    Maybe you could let us know what the differences of a normal and an inline function in C++ are.
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Dietrich, you can also find that out by looking on MSDN. monkeyman, I don't know much C++, so I probably couldn't help you with this. You would probably have to edit the source, which would most likely be a lot of work.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    ya so i better don't try because it was just an idea
    Those people who think they know everything are a great annoyance to those of us who do.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    In C or C++ an inline function is one where the body of the function is placed directly at the place it is called, instead of being a separate subroutine. This is marginally faster, since there is no overhead of jumping to a new address, pushing registers on the stack, and returning at the end.

    There is no equivalent in Python, but you could simulate it by using a pre-processor to define macros - this is what C did (and often still does, although the inline keyword was introduced in C99), and would be pretty simple to implement. You could either write a custom pre-processor in Python or use an existing one such as cpp or M4.

    Alternatively you could write an inline optimiser that reads python bytecodes (.pyc files) or ASTs and inlines functions where possible. This would be much harder to do, but closer to what C++ inlining does.

    Dave - The Developers' Coach
    Last edited by DevCoach; June 4th, 2005 at 05:54 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    well it just was a question
    nothing i really need
    Those people who think they know everything are a great annoyance to those of us who do.
  16. #9
  17. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    610
    Rep Power
    65

    Smile


    Thanks Coach,

    so lambda wouldn't do it.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25
    lamda is more of a unnamed function, not really an inline one, even though it is kinda in the same place and such. However being how python is interprited, it wont matter with using inline compared to none inline functions. Unless you rewrite the interpriter to do so.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    I don't understand the point of lambda functions in months I have not even seen them
    Those people who think they know everything are a great annoyance to those of us who do.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25
    there really isn't anything that is really "needed" by them. Everything you can do with lamda you can with a ruglar function. It just lets you put more things in one line instead of a few. With python 3.0 it is plained to be taken out. Personly, i have never seen them used in any large projects and I have never used one. Mainly because I think they are ugly
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    I agree they are ugly:P And me too I have never used one
    Those people who think they know everything are a great annoyance to those of us who do.

IMN logo majestic logo threadwatch logo seochat tools logo