Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28927

Re: Double sided double underscored variable names

References (1 earlier) <CAPTjJmqh8V9kZm3bQ-BHGDc-qsEuxykh8DCg4s3z5x+JcxW-WA@mail.gmail.com> <CAN1F8qUuXho43hPdGKyh3sAyZHx7JegFfSEU+JhqwyA552a=DA@mail.gmail.com> <mailman.526.1347403933.27098.python-list@python.org> <504fe1e7$0$29981$c3e8da3$5496439d@news.astraweb.com> <CAN1F8qW_3r5X9cDC_CF3QSTL0zRn4S9YX=30vduU8aU+aSN-3A@mail.gmail.com>
Date 2012-09-12 14:12 +1000
Subject Re: Double sided double underscored variable names
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.536.1347423143.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Sep 12, 2012 at 11:38 AM, Joshua Landau
<joshua.landau.ws@gmail.com> wrote:
> On 12 September 2012 02:14, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>>
>> And again, Joshua's original post is not available from my provider.
>> Joshua, I suspect that something about your post is being seen as spam
>> and dropped by at least some providers.
>
> I am sorry to ask this, but in the meantime can someone who isn't
> spam-filtered repost my messages? I'll give them a cookie!
> To repeat my previous post, I'm using GMail and posting to
> python-list@python.org. If that is what I'm meant to be doing, I'll try
> another email address.

Mailing to python-list@python from Gmail is exactly what I do, and far
as I know, none of my posts are getting lost. But then, I'm seeing all
your posts, too, so maybe I just don't know when my posts don't go
through.

>> On Wed, 12 Sep 2012 08:52:10 +1000, Chris Angelico wrote:
>>
>> > Inline functions? I like this idea. I tend to want them in pretty much
>> > any language I write in.
>>
>> What do you mean by in-line functions? If you mean what you literally
>> say, I would answer that Python has that with lambda.
>>
>> But I guess you probably mean something more like macros.
>
> No, just multi-line lambda. Macros, if my knowledge of lower-level languages
> is valid, would be sorta' silly in Python.

Ah, okay. I was thinking more along the lines of what you call macros,
but in the C++ sense of inline functions. In C, macros are handled at
precompilation stage, and are dangerous. Classic example:

#define squared(x) x*x

x_squared = squared(6+7)

So your macros end up littered with parentheses, and it still doesn't
solve anything, as the argument still gets evaluated twice. (A problem
if it has side effects - eg if it's a function call.)

What I'm thinking of, though, is like C++ functions. You can put the
'inline' keyword onto any function, and the compiler will do its best
to inline it (in fact, a good optimizing compiler will inline things
regardless, but that's a separate point). I can write:

inline int squared(int x) {return x*x;}

and C++ will add no function overhead, but will still do all the
proper evaluation order etc.

Of course, C++ doesn't allow monkeypatching, so you'll never have
semantic differences from inlining. It's just a performance question.
But I use inline functions like constants - for instance, I could
create a function that converts a database ID into an internal
reference number, and I can change the definition of that function in
one place and have it apply everywhere, just like if I wanted to
change the definition of math.PI to 3.142857 for fun one day. Of
course I can use a normal (out-of-line) function for this, but that
has overhead in most languages. Hence, wanting inline functions.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Double sided double underscored variable names Chris Angelico <rosuav@gmail.com> - 2012-09-12 08:52 +1000
  Re: Double sided double underscored variable names Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-12 01:14 +0000
    Re: Double sided double underscored variable names Chris Angelico <rosuav@gmail.com> - 2012-09-12 14:12 +1000
    Re: Double sided double underscored variable names Joshua Landau <joshua.landau.ws@gmail.com> - 2012-09-12 10:55 +0100

csiph-web