Re: object.enable() anti-pattern

2013-05-13 Thread Fábio Santos
On 13 May 2013 00:22, Greg Ewing greg.ew...@canterbury.ac.nz wrote: Wayne Werner wrote: On Fri, 10 May 2013, Gregory Ewing wrote: f = open(myfile.dat) f.close() data = f.read() To clarify - you don't want a class that has functions that need to be called in a certain order with

Re: object.enable() anti-pattern

2013-05-13 Thread Chris Angelico
On Mon, May 13, 2013 at 4:32 PM, Fábio Santos fabiosantos...@gmail.com wrote: On 13 May 2013 00:22, Greg Ewing greg.ew...@canterbury.ac.nz wrote: The same argument can be applied to: foo = Foo() foo.do_something() foo.enable() # should have done this first You're passing an

Re: object.enable() anti-pattern

2013-05-13 Thread Fábio Santos
On 13 May 2013 08:40, Chris Angelico ros...@gmail.com wrote: On Mon, May 13, 2013 at 4:32 PM, Fábio Santos fabiosantos...@gmail.com wrote: On 13 May 2013 00:22, Greg Ewing greg.ew...@canterbury.ac.nz wrote: The same argument can be applied to: foo = Foo() foo.do_something()

Re: object.enable() anti-pattern

2013-05-13 Thread Wayne Werner
On Mon, 13 May 2013, Greg Ewing wrote: Wayne Werner wrote: On Fri, 10 May 2013, Gregory Ewing wrote: f = open(myfile.dat) f.close() data = f.read() To clarify - you don't want a class that has functions that need to be called in a certain order with *valid input* in order to not

Re: object.enable() anti-pattern

2013-05-12 Thread Wayne Werner
On Fri, 10 May 2013, Robert Kern wrote: On 2013-05-10 12:00, Steven D'Aprano wrote: But either way, that's fine. You've found an object where it does make sense to have an explicit make it go method: first one entity has permission to construct the object, but not to open the underlying file.

Re: object.enable() anti-pattern

2013-05-12 Thread Wayne Werner
On Fri, 10 May 2013, Gregory Ewing wrote: Wayne Werner wrote: You don't ever want a class that has functions that need to be called in a certain order to *not* crash. That seems like an overly broad statement. What do you think the following should do? f = open(myfile.dat) f.close()

Re: object.enable() anti-pattern

2013-05-12 Thread Terry Jan Reedy
On 5/12/2013 1:14 PM, Wayne Werner wrote: On Fri, 10 May 2013, Gregory Ewing wrote: Wayne Werner wrote: You don't ever want a class that has functions that need to be called in a certain order to *not* crash. That seems like an overly broad statement. What do you think the following should

Re: object.enable() anti-pattern

2013-05-12 Thread Terry Jan Reedy
On 5/12/2013 12:48 PM, Wayne Werner wrote: I'll share the anti-pattern that I've seen many times (not actually in Python) class CoolPresenter: def __init__(self): self.view = None self.some_property = None self.other_property = None

Re: object.enable() anti-pattern

2013-05-12 Thread Greg Ewing
Wayne Werner wrote: On Fri, 10 May 2013, Gregory Ewing wrote: f = open(myfile.dat) f.close() data = f.read() To clarify - you don't want a class that has functions that need to be called in a certain order with *valid input* in order to not crash. Exactly what does happen - a

Re: object.enable() anti-pattern

2013-05-11 Thread Steven D'Aprano
On Fri, 10 May 2013 17:59:26 +0100, Nobody wrote: On Thu, 09 May 2013 05:23:59 +, Steven D'Aprano wrote: There is no sensible use-case for creating a file without opening it. What would be the point? Any subsequent calls to just about any method will fail. Since you have to open the

Re: object.enable() anti-pattern

2013-05-11 Thread Steven D'Aprano
On Fri, 10 May 2013 18:20:34 +0100, Robert Kern wrote: According to Steven's criteria, neither of these are instances of the anti-pattern because there are good reasons they are this way. He is reducing the anti-pattern to just those cases where there is no reason for doing so. But isn't

Re: object.enable() anti-pattern

2013-05-11 Thread Mark Janssen
In the old days, it was useful to have fine-grained control over the file object because you didn't know where it might fail, and the OS didn't necessarily give you give good status codes. So being able to step through the entire process was the job of the progammers. I don't know what you

Re: object.enable() anti-pattern

2013-05-11 Thread Mark Janssen
Steven, don't be misled. POSIX is not the model to look to -- it does not acknowledge that files are actual objects that reside on a piece of hardware. It is not simply an integer. Please disregard this (my own) flame bait. -- MarkJ Tacoma, Washington --

Re: object.enable() anti-pattern

2013-05-11 Thread Roy Smith
In article 518df898$0$29997$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I never intended to give the impression that *any* use of a separate enable method call was bad. I certainly didn't intend to be bogged down into a long discussion

Re: object.enable() anti-pattern

2013-05-11 Thread André Malo
* Serhiy Storchaka wrote: Another example is running a subprocess in Unix-like systems. fork() open/close file descriptors, set limits, etc exec*() For running a subprocess, only fork() is needed. For starting another executable, only exec() is needed. For running the new

Re: object.enable() anti-pattern

2013-05-11 Thread Chris Angelico
On Sun, May 12, 2013 at 1:33 AM, André Malo ndpar...@gmail.com wrote: * Serhiy Storchaka wrote: Another example is running a subprocess in Unix-like systems. fork() open/close file descriptors, set limits, etc exec*() For running a subprocess, only fork() is needed. For

Re: object.enable() anti-pattern

2013-05-11 Thread Robert Kern
On 2013-05-11 08:51, Steven D'Aprano wrote: On Fri, 10 May 2013 18:20:34 +0100, Robert Kern wrote: According to Steven's criteria, neither of these are instances of the anti-pattern because there are good reasons they are this way. He is reducing the anti-pattern to just those cases where

Re: object.enable() anti-pattern

2013-05-11 Thread Chris Angelico
On Sun, May 12, 2013 at 5:55 AM, Robert Kern robert.k...@gmail.com wrote: Another example of temporal coupling is json_decode in PHP: you must follow it by a call to json_last_error, otherwise you have no way of telling whether the json_decode function succeeded or not.

Re: object.enable() anti-pattern

2013-05-10 Thread Dan Sommers
On Fri, 10 May 2013 05:03:10 +, Steven D'Aprano wrote: There is no sensible use-case for creating a file OBJECT unless it initially wraps an open file pointer. So far the only counter-examples given aren't counter-examples ... Well, sure, if you discount operations like create this file

Re: object.enable() anti-pattern

2013-05-10 Thread Steven D'Aprano
On Fri, 10 May 2013 01:50:09 -0400, Roy Smith wrote: In article 518c7f05$0$29997$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: there is no way to create a C file descriptor in a closed state. Such a thing does not exist. If you have a file

Re: object.enable() anti-pattern

2013-05-10 Thread Steven D'Aprano
On Fri, 10 May 2013 06:22:31 +, Dan Sommers wrote: On Fri, 10 May 2013 05:03:10 +, Steven D'Aprano wrote: There is no sensible use-case for creating a file OBJECT unless it initially wraps an open file pointer. So far the only counter-examples given aren't counter-examples ...

Re: object.enable() anti-pattern

2013-05-10 Thread Robert Kern
On 2013-05-10 12:00, Steven D'Aprano wrote: But either way, that's fine. You've found an object where it does make sense to have an explicit make it go method: first one entity has permission to construct the object, but not to open the underlying file. Another entity has permission to open the

Re: object.enable() anti-pattern

2013-05-10 Thread Roy Smith
In article 518cc239$0$29997$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: int fd = 37; I've just created a file descriptor. There is not enough information given to know if it corresponds to an open file or not. No, you haven't

Re: object.enable() anti-pattern

2013-05-10 Thread Roy Smith
In article mailman.1527.1368188358.3114.python-l...@python.org, Robert Kern robert.k...@gmail.com wrote: I'd be curious to see in-the-wild instances of the anti-pattern that you are talking about, then. I think everyone agrees that entirely unmotivated enable methods should be avoided, but

Re: object.enable() anti-pattern

2013-05-10 Thread Oscar Benjamin
On 10 May 2013 15:01, Roy Smith r...@panix.com wrote: In article mailman.1527.1368188358.3114.python-l...@python.org, Robert Kern robert.k...@gmail.com wrote: I'd be curious to see in-the-wild instances of the anti-pattern that you are talking about, then. I think everyone agrees that

Re: object.enable() anti-pattern

2013-05-10 Thread Roy Smith
In article mailman.1530.1368196163.3114.python-l...@python.org, Oscar Benjamin oscar.j.benja...@gmail.com wrote: It's not just because of exceptions. In C++ virtual method calls in a constructor for a class A will always call the methods of class A even if the object being constructed is

Re: object.enable() anti-pattern

2013-05-10 Thread Chris Angelico
On Sat, May 11, 2013 at 12:37 AM, Roy Smith r...@panix.com wrote: I suppose, if I had a class like this, I would write a factory function which called the constructor and post-construction initializer. And then I would make the constructor protected. That sounds like a reasonable plan, with

Re: object.enable() anti-pattern

2013-05-10 Thread Roy Smith
In article mailman.1531.1368197225.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Sat, May 11, 2013 at 12:37 AM, Roy Smith r...@panix.com wrote: I suppose, if I had a class like this, I would write a factory function which called the constructor and post-construction

Re: object.enable() anti-pattern

2013-05-10 Thread Chris Angelico
On Sat, May 11, 2013 at 12:54 AM, Roy Smith r...@panix.com wrote: In article mailman.1531.1368197225.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Sat, May 11, 2013 at 12:37 AM, Roy Smith r...@panix.com wrote: I suppose, if I had a class like this, I would write a

Re: object.enable() anti-pattern

2013-05-10 Thread Roy Smith
In article mailman.1532.1368198547.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: Each language has its own set of best practices. Trying to write C++ code using Python patterns is as bad as trying to write Python code using C++ patterns. Agreed, in generality. But

Re: object.enable() anti-pattern

2013-05-10 Thread Robert Kern
On 2013-05-10 15:01, Roy Smith wrote: In article mailman.1527.1368188358.3114.python-l...@python.org, Robert Kern robert.k...@gmail.com wrote: I'd be curious to see in-the-wild instances of the anti-pattern that you are talking about, then. I think everyone agrees that entirely unmotivated

Re: object.enable() anti-pattern

2013-05-10 Thread Chris Angelico
On Sat, May 11, 2013 at 1:21 AM, Roy Smith r...@panix.com wrote: In article mailman.1532.1368198547.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: Agreed, in generality. But what is actually gained by hiding data from yourself? You're not hiding it from yourself.

Re: object.enable() anti-pattern

2013-05-10 Thread Nobody
On Thu, 09 May 2013 05:23:59 +, Steven D'Aprano wrote: There is no sensible use-case for creating a file without opening it. What would be the point? Any subsequent calls to just about any method will fail. Since you have to open the file after creating the file object anyway, why make

Re: object.enable() anti-pattern

2013-05-10 Thread Serhiy Storchaka
10.05.13 15:19, Robert Kern написав(ла): I'd be curious to see in-the-wild instances of the anti-pattern that you are talking about, then. Many (if not most) GUI frameworks use this pattern. button = Button(text) button.setForegroundColor(...) button.setBackgoundColor(...)

Re: object.enable() anti-pattern

2013-05-10 Thread Robert Kern
On 2013-05-10 16:44, Serhiy Storchaka wrote: 10.05.13 15:19, Robert Kern написав(ла): I'd be curious to see in-the-wild instances of the anti-pattern that you are talking about, then. Many (if not most) GUI frameworks use this pattern. button = Button(text)

Re: object.enable() anti-pattern

2013-05-10 Thread Chris Angelico
to be a lightweight fork). I would say that the deprecation of vfork in favour of fork is a strong indication that the object.enable() anti-pattern can come up in kernel APIs too, and isn't liked there either. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: object.enable() anti-pattern

2013-05-10 Thread Roy Smith
In article pan.2013.05.10.16.59.31.512...@nowhere.com, Nobody nob...@nowhere.com wrote: However: there are situations where it is useful to be able to separate the simple task of creating an object from more invasive actions such as system calls. Particularly in multi-threaded or real-time

Re: object.enable() anti-pattern

2013-05-10 Thread Cameron Simpson
On 10May2013 09:22, Roy Smith r...@panix.com wrote: | In article 518cc239$0$29997$c3e8da3$54964...@news.astraweb.com, | Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: | int fd = 37; | | I've just created a file descriptor. There is not enough information | given to know if

Re: object.enable() anti-pattern

2013-05-10 Thread Mark Janssen
There is no sensible use-case for creating a file OBJECT unless it initially wraps an open file pointer. So far the only counter-examples given aren't counter-examples ... Well, sure, if you discount operations like create this file and queries like could I delete this file if I wanted to?

Re: object.enable() anti-pattern

2013-05-10 Thread Mark Janssen
| No, I've created a file descriptor, which is, by definition, an integer. | It has nothing to do with C. This is all defined by the POSIX | interface. For example, the getdtablesize(2) man page says: | | The entries in the descriptor table are numbered with small integers | starting at 0.

Re: object.enable() anti-pattern

2013-05-10 Thread Thomas Rachel
Am 10.05.2013 15:22 schrieb Roy Smith: That's correct. But, as described above, the system makes certain guarantees which allow me to reason about the existence or non-existence os such entries. Nevertheless, your 37 is not a FD yet. Let's take your program: #include unistd.h #include

Re: object.enable() anti-pattern

2013-05-09 Thread Terry Jan Reedy
On 5/9/2013 1:23 AM, Steven D'Aprano wrote: Besides, this is not to denigrate the idea of a read() function that takes a filename and returns its contents. But that is not an object constructor. It may construct a file object internally, but it doesn't return the file object, so it is

Re: object.enable() anti-pattern

2013-05-09 Thread Gregory Ewing
Steven D'Aprano wrote: There is no sensible use-case for creating a file without opening it. What would be the point? Early unix systems often used this as a form of locking. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: object.enable() anti-pattern

2013-05-09 Thread Cameron Simpson
On 09May2013 19:54, Greg Ewing greg.ew...@canterbury.ac.nz wrote: | Steven D'Aprano wrote: | There is no sensible use-case for creating a file without opening | it. What would be the point? | | Early unix systems often used this as a form of locking. Not just early systems: it's a nice

Re: object.enable() anti-pattern

2013-05-09 Thread Wayne Werner
On Wed, 8 May 2013, Steven D'Aprano wrote: I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as turning it on, or enabling it, or similar. For

Re: object.enable() anti-pattern

2013-05-09 Thread Steven D'Aprano
On Thu, 09 May 2013 18:23:31 +1000, Cameron Simpson wrote: On 09May2013 19:54, Greg Ewing greg.ew...@canterbury.ac.nz wrote: | Steven D'Aprano wrote: | There is no sensible use-case for creating a file WITHOUT OPENING | it. What would be the point? | | Early unix systems often used this

Re: object.enable() anti-pattern

2013-05-09 Thread Steven D'Aprano
On Thu, 09 May 2013 06:08:25 -0500, Wayne Werner wrote: Ah, that's it - the problem is that it introduces /Temporal Coupling/ to one's code: http://blog.ploeh.dk/2011/05/24/DesignSmellTemporalCoupling/ Good catch! That's not the blog post I read, but that's the same concept. Temporal

Re: object.enable() anti-pattern

2013-05-09 Thread Roy Smith
In article 518b32ef$0$11120$c3e8...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: There is no sensible use-case for creating a file without opening it. Sure there is. Sometimes just creating the name in the file system is all you want to do. That's why, for

Re: object.enable() anti-pattern

2013-05-09 Thread Oscar Benjamin
On 9 May 2013 14:07, Roy Smith r...@panix.com wrote: In article 518b32ef$0$11120$c3e8...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: There is no sensible use-case for creating a file without opening it. Sure there is. Sometimes just creating the name in

Re: object.enable() anti-pattern

2013-05-09 Thread Steven D'Aprano
On Thu, 09 May 2013 09:07:42 -0400, Roy Smith wrote: In article 518b32ef$0$11120$c3e8...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: There is no sensible use-case for creating a file without opening it. Sure there is. Sometimes just creating the name

Re: object.enable() anti-pattern

2013-05-09 Thread MRAB
On 09/05/2013 19:21, Steven D'Aprano wrote: On Thu, 09 May 2013 09:07:42 -0400, Roy Smith wrote: In article 518b32ef$0$11120$c3e8...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: There is no sensible use-case for creating a file without opening it. Sure

Re: object.enable() anti-pattern

2013-05-09 Thread Roy Smith
In article 518be931$0$29997$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: There is no sensible use-case for creating a file OBJECT unless it initially wraps an open file pointer. OK, I guess that's a fair statement. But mostly because a

Re: object.enable() anti-pattern

2013-05-09 Thread Chris Angelico
On Fri, May 10, 2013 at 4:59 AM, Roy Smith r...@panix.com wrote: It's not hard to imagine a file class which could be used like: f = file(/path/to/my/file) f.delete() That would be a totally different model from the current python file object. And then there would be plenty of things you

Re: object.enable() anti-pattern

2013-05-09 Thread Greg Ewing
Cameron Simpson wrote: You open a file with 0 modes, so that it is _immediately_ not writable. Other attempts to make the lock file thus fail because of the lack of write, I don't think that's quite right. You open it with O_CREAT+O_EXCL, which atomically fails if the file already exists. The

Re: object.enable() anti-pattern

2013-05-09 Thread Cameron Simpson
On 09May2013 11:30, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: | On Thu, 09 May 2013 18:23:31 +1000, Cameron Simpson wrote: | | On 09May2013 19:54, Greg Ewing greg.ew...@canterbury.ac.nz wrote: | | Steven D'Aprano wrote: | | There is no sensible use-case for creating a file

Re: object.enable() anti-pattern

2013-05-09 Thread Gregory Ewing
Wayne Werner wrote: You don't ever want a class that has functions that need to be called in a certain order to *not* crash. That seems like an overly broad statement. What do you think the following should do? f = open(myfile.dat) f.close() data = f.read() -- Greg --

Re: object.enable() anti-pattern

2013-05-09 Thread Cameron Simpson
On 10May2013 10:56, Greg Ewing greg.ew...@canterbury.ac.nz wrote: | Cameron Simpson wrote: | You open a file with 0 modes, so | that it is _immediately_ not writable. Other attempts to make the | lock file thus fail because of the lack of write, | | I don't think that's quite right. You open it

Re: object.enable() anti-pattern

2013-05-09 Thread Michael Speer
By his reasoning it simply shouldn't exist. Instead you would access the information only like this: with open(myfile.dat) as f: data = f.read() Which is my preferred way to work with resources requiring cleanup in python anyways, as it ensures I have the least chance of messing things up, and

Re: object.enable() anti-pattern

2013-05-09 Thread Roy Smith
In article mailman.1514.1368145123.3114.python-l...@python.org, Michael Speer knome...@gmail.com wrote: By his reasoning it simply shouldn't exist. Instead you would access the information only like this: with open(myfile.dat) as f: data = f.read() The problem with things like file

Re: object.enable() anti-pattern

2013-05-09 Thread Steven D'Aprano
On Thu, 09 May 2013 19:34:25 +0100, MRAB wrote: There is no sensible use-case for creating a file OBJECT unless it initially wraps an open file pointer. You might want to do this: f = File(path) if f.exists(): ... This would be an alternative to: if os.path.exists(path):

Re: object.enable() anti-pattern

2013-05-09 Thread Chris Angelico
On Fri, May 10, 2013 at 12:30 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I must admit I am astonished at how controversial the opinion if your object is useless until you call 'start', you should automatically call 'start' when the object is created has turned out to be. I

Re: object.enable() anti-pattern

2013-05-09 Thread Roy Smith
In article 518c5bbc$0$29997$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I must admit I am astonished at how controversial the opinion if your object is useless until you call 'start', you should automatically call 'start' when the object

Re: object.enable() anti-pattern

2013-05-09 Thread Mark Janssen
I think where things went pear shaped is when you made the statement: There is no sensible use-case for creating a file OBJECT unless it initially wraps an open file pointer. That's a pretty absolute point of view. Life is rarely so absolute. In the old days, it was useful to have

Re: object.enable() anti-pattern

2013-05-09 Thread Chris Angelico
On Fri, May 10, 2013 at 1:19 PM, Mark Janssen dreamingforw...@gmail.com wrote: I think where things went pear shaped is when you made the statement: There is no sensible use-case for creating a file OBJECT unless it initially wraps an open file pointer. That's a pretty absolute point of

Re: object.enable() anti-pattern

2013-05-09 Thread Steven D'Aprano
On Thu, 09 May 2013 23:09:55 -0400, Roy Smith wrote: In article 518c5bbc$0$29997$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I must admit I am astonished at how controversial the opinion if your object is useless until you call 'start',

Re: object.enable() anti-pattern

2013-05-09 Thread Steven D'Aprano
On Fri, 10 May 2013 09:36:43 +1000, Cameron Simpson wrote: On 09May2013 11:30, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: | On Thu, 09 May 2013 18:23:31 +1000, Cameron Simpson wrote: | | On 09May2013 19:54, Greg Ewing greg.ew...@canterbury.ac.nz wrote: | | Steven

Re: object.enable() anti-pattern

2013-05-09 Thread Roy Smith
In article 518c7f05$0$29997$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: there is no way to create a C file descriptor in a closed state. Such a thing does not exist. If you have a file descriptor, the file is open. Once you close it, the

object.enable() anti-pattern

2013-05-08 Thread Steven D'Aprano
I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as turning it on, or enabling it, or similar. For example, we don't do this in Python: f =

Re: object.enable() anti-pattern

2013-05-08 Thread Christian Heimes
Am 08.05.2013 10:52, schrieb Steven D'Aprano: Basically, any time you have two steps required for using an object, e.g. like this: obj = someobject(arg1, arg2) obj.enable() you should move the make-it-work functionality out of the enable method and into __init__ so that creating the

Re: object.enable() anti-pattern

2013-05-08 Thread Robert Kern
On 2013-05-08 09:52, Steven D'Aprano wrote: I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as turning it on, or enabling it, or similar. I

Re: object.enable() anti-pattern

2013-05-08 Thread Steven D'Aprano
On Wed, 08 May 2013 11:13:33 +0100, Robert Kern wrote: On 2013-05-08 09:52, Steven D'Aprano wrote: I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a resource ought to be the

Re: object.enable() anti-pattern

2013-05-08 Thread Roy Smith
In article 518a123c$0$11094$c3e8...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a

Re: object.enable() anti-pattern

2013-05-08 Thread Duncan Booth
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as turning it on, or enabling it,

Re: object.enable() anti-pattern

2013-05-08 Thread Dan Sommers
On Wed, 08 May 2013 14:27:53 +, Duncan Booth wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a

Re: object.enable() anti-pattern

2013-05-08 Thread Dan Sommers
On Wed, 08 May 2013 08:52:12 +, Steven D'Aprano wrote: This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as turning it on, or enabling it, or similar. For example, we don't do this in Python: f = file(some_file.txt) f.open() data = f.read()

Re: object.enable() anti-pattern

2013-05-08 Thread Mark Janssen
I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as turning it on, or enabling it, or similar. For example, we don't do this in Python: I

Re: object.enable() anti-pattern

2013-05-08 Thread Mark Janssen
This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as turning it on, or enabling it, or similar. For example, we don't do this in Python: I would call it user-mediated resource allocation as distinct from object-mediated resource allocation. I should

Re: object.enable() anti-pattern

2013-05-08 Thread Steven D'Aprano
On Wed, 08 May 2013 14:27:53 +, Duncan Booth wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a

Re: object.enable() anti-pattern

2013-05-08 Thread Steven D'Aprano
On Thu, 09 May 2013 02:42:01 +, Dan Sommers wrote: On Wed, 08 May 2013 08:52:12 +, Steven D'Aprano wrote: This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as turning it on, or enabling it, or similar. For example, we don't do this in

Re: object.enable() anti-pattern

2013-05-08 Thread Steven D'Aprano
On Thu, 09 May 2013 02:38:36 +, Dan Sommers wrote: Think of spinning off a thread: initialize it synchronously, and then let it execute asynchronously. We tend towards that pattern even when we know that execution will be synchronous, because we also that it could be asynchronous one

Re: object.enable() anti-pattern

2013-05-08 Thread Chris Angelico
On Thu, May 9, 2013 at 3:37 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I can see use-cases for separating make it go from initialisation. It all depends on what you might want to do to the object before making it go. If the answer is Nothing, then there is no reason not to