Re: skipping __init__ and using exploiting a class member instead

2013-10-21 Thread Neil Cerutti
On 2013-10-20, Ben Finney wrote: > Roy Smith writes: > >> Scott Meyers is an incredibly smart C++ wizard. His books are amazing. >> The fact that it takes somebody that smart, and books that amazing, to >> teach you how not to shoot yourself in the foot with a C++ compiler says >> a lot abou

Re: skipping __init__ and using exploiting a class member instead

2013-10-21 Thread feedthetroll
Am Montag, 21. Oktober 2013 06:31:36 UTC+2 schrieb Peter Cacioppi: > That sound you hear is Roy Smith hitting the nail on the head. PLONK: The sound you hear, when a context-less troll is hitting the bottom of my killfile. -- https://mail.python.org/mailman/listinfo/python-list

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Peter Cacioppi
That sound you hear is Roy Smith hitting the nail on the head. -- https://mail.python.org/mailman/listinfo/python-list

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Peter Cacioppi
That sound you here is Roy Smith hitting the nail on the head re: C++ and Scott Meyers. -- https://mail.python.org/mailman/listinfo/python-list

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Ben Finney
Roy Smith writes: > Scott Meyers is an incredibly smart C++ wizard. His books are amazing. > The fact that it takes somebody that smart, and books that amazing, to > teach you how not to shoot yourself in the foot with a C++ compiler says > a lot about the language. +1 QotW -- \ “[W]

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Roy Smith
In article , Peter Cacioppi wrote: > I read Scott Meyers books on C++ and STL a couple of times > each and helped design the protocol that kept us reasonably safe. Scott Meyers is an incredibly smart C++ wizard. His books are amazing. The fact that it takes somebody that smart, and books t

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Peter Cacioppi
At the risk of sounding like a fogey, I actually think I did, at one time, know the distinctions between "our projects protocol" and "the language proper" for C++. I read Scott Meyers books on C++ and STL a couple of times each and helped design the protocol that kept us reasonably safe. But t

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Chris Angelico
On Mon, Oct 21, 2013 at 4:57 AM, Peter Cacioppi wrote: >> You certainly don't have to write a constructor for a subclass in C++. > > Ahh, this message board is so collectively well informed (once you get past > the trolls) > > The C++ project I worked on was religious about always overwriting pa

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Roy Smith
In article <0e9b51a9-bd78-4d34-b277-c463347e8...@googlegroups.com>, Peter Cacioppi wrote: > > You certainly don't have to write a constructor for a subclass in C++. > > Ahh, this message board is so collectively well informed (once you get past > the trolls) > > The C++ project I worked on

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Peter Cacioppi
> You certainly don't have to write a constructor for a subclass in C++. Ahh, this message board is so collectively well informed (once you get past the trolls) The C++ project I worked on was religious about always overwriting parent class constructors. I had assumed this was because the lan

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Devin Jeanpierre
On Sat, Oct 19, 2013 at 2:44 PM, Peter Cacioppi wrote: > Is the following considered poor Python form? > > class Foo (object) : > _lazy = None > def foo(self, x) : > self._lazy = self._lazy or self.get_something(x) > def get_something(self, x) : > # doesn't really matte

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Mark Lawrence
On 20/10/2013 08:09, Peter Cacioppi wrote: Personally, I find the ability of Python to subclass without overriding the constructor very elegant. __new__ is the constructor which to my knowledge you've not mentioned, __init__ is the initialiser as mentioned by Ben Finney. -- Roses are red,

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Roy Smith
In article , Peter Cacioppi wrote: > Personally, I find the ability of Python to subclass without overriding the > constructor very elegant. I don't believe the other languages I've worked in > can do this (C++, C#, Java)... I'm not sure what point you're trying to make here. You certainly d

Detecting whether a value was passed for a parameter (was: skipping __init__ and using exploiting a class member instead)

2013-10-20 Thread Ben Finney
Peter Cacioppi writes: > I was laboring under some misconception that there was Python magic > that allowed __init__ and only __init__ to add class attributes by > setting their values. Good to know this piece of magic isn't part of > Python, and thus lazy eval can be handled more cleanly than I

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Peter Cacioppi
> Why not simply have one, and use it to initialize your attributes, > even if it is to None? Think about it this way. None here really means "not yet initialized". It is a value that cannot occur naturally and thus functions as a not-initialized flag. But for different contexts, this value co

Re: skipping __init__ and using exploiting a class member instead

2013-10-20 Thread Peter Cacioppi
>The use of getattr here seems unfortunate Unfortunate how? It's a perfect for what I want here ... remember the context is such that the lazily stored value is always truthy (I assert this elsewhere). > I'm not sure why you want to avoid an __init__ method. Why do you want to keep it? The

Re: skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Ned Batchelder
On 10/19/13 8:42 PM, Peter Cacioppi wrote: To be clear, my original post had a goof. So my original, de-goofed, idiom was class Foo (object) : _lazy = None def foo(self, x) : self._lazy = self._lazy or self.get_something(x) def get_something(self, x) : # doesn'

Re: skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Peter Cacioppi
To be clear, my original post had a goof. So my original, de-goofed, idiom was class Foo (object) : _lazy = None def foo(self, x) : self._lazy = self._lazy or self.get_something(x) def get_something(self, x) : # doesn't really matter, so long as it returns truthy res

Re: skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Peter Cacioppi
Yes, I see the light now. My idiom works, but Steven has shown me the droids I am looking for. Thanks! -- https://mail.python.org/mailman/listinfo/python-list

Re: skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Steven D'Aprano
On Sat, 19 Oct 2013 14:44:55 -0700, Peter Cacioppi wrote: > Is the following considered poor Python form? > > class Foo (object) : > _lazy = None > def foo(self, x) : > _lazy = _lazy or self.get_something(x) > def get_something(self, x) : > # doesn't really matter > >

Re: skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Robert Kern
On 2013-10-19 22:55, Ned Batchelder wrote: On 10/19/13 5:44 PM, Peter Cacioppi wrote: Is the following considered poor Python form? class Foo (object) : _lazy = None def foo(self, x) : _lazy = _lazy or self.get_something(x) def get_something(self, x) : # doesn't

Re: skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Peter Cacioppi
On Saturday, October 19, 2013 2:44:55 PM UTC-7, Peter Cacioppi wrote: > Is the following considered poor Python form? > > > > class Foo (object) : > > _lazy = None > > def foo(self, x) : > > _lazy = _lazy or self.get_something(x) > > def get_something(self, x) : > >

Re: skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Ned Batchelder
On 10/19/13 5:44 PM, Peter Cacioppi wrote: Is the following considered poor Python form? class Foo (object) : _lazy = None def foo(self, x) : _lazy = _lazy or self.get_something(x) def get_something(self, x) : # doesn't really matter I like this idiom for certai

skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Peter Cacioppi
Is the following considered poor Python form? class Foo (object) : _lazy = None def foo(self, x) : _lazy = _lazy or self.get_something(x) def get_something(self, x) : # doesn't really matter I like this idiom for certain situations, just wondering if it will raise the