Newbie Q: Class Privacy (or lack of)

2006-07-24 Thread Steve Jobless
Hi, I just started learning Python. I went through most of the tutorial at python.org. But I noticed something weird. I'm not talking about the __private hack. Let's say the class is defined as: class MyClass: def __init__(self): pass def func(self): return 123 But from th

Re: Newbie Q: Class Privacy (or lack of)

2006-08-02 Thread Antoon Pardon
On 2006-07-28, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> >> class MyClass(object): >> >> __slots__ = ('bar',) >> >> def func(self): >> return 123 >> >> x = MyClass() >> x.instance_var_not_defined_in_the_class = 456 >> ==> >> AttributeError: 'MyClass' object has no a

Re: Newbie Q: Class Privacy (or lack of)

2006-08-02 Thread Diez B. Roggisch
> I find that a strange purpose because when you are working on a class, > you don't necessarily know if you will ever know many instance of that > class. So should I use __slots__ in all my classes, just to be sure > for when someone wants many instances of one? I find that a strange reasoning b

Re: Newbie Q: Class Privacy (or lack of)

2006-08-02 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Antoon Pardon wrote: > On 2006-07-28, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> This avoids the problem but you get others in return. And it's an >> abuse of `__slots__` which is meant as a way to save memory if you need >> really many objects of that type an

Re: Newbie Q: Class Privacy (or lack of)

2006-08-02 Thread Antoon Pardon
On 2006-08-02, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >> I find that a strange purpose because when you are working on a class, >> you don't necessarily know if you will ever know many instance of that >> class. So should I use __slots__ in all my classes, just to be sure >> for when someone w

Re: Newbie Q: Class Privacy (or lack of)

2006-07-24 Thread Jean-Paul Calderone
On Tue, 25 Jul 2006 02:49:06 GMT, Steve Jobless <[EMAIL PROTECTED]> wrote: >Hi, > >I just started learning Python. I went through most of the tutorial at >python.org. But I noticed something weird. I'm not talking about the >__private hack. > >Let's say the class is defined as: > > class MyClass:

Re: Newbie Q: Class Privacy (or lack of)

2006-07-24 Thread Kevin Watters
See: http://redhanded.hobix.com/inspect/monkeypytching.html Shouldn't be done unless you have a really cool reason for doing so. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Q: Class Privacy (or lack of)

2006-07-24 Thread John Machin
Steve Jobless wrote: > Hi, > > I just started learning Python. I went through most of the tutorial at > python.org. But I noticed something weird. I'm not talking about the > __private hack. > > Let's say the class is defined as: > > class MyClass: > def __init__(self): > pass > def

Re: Newbie Q: Class Privacy (or lack of)

2006-07-25 Thread Bruno Desthuilliers
Steve Jobless wrote: > Hi, > > I just started learning Python. I went through most of the tutorial at > python.org. But I noticed something weird. I'm not talking about the > __private hack. Actually this is __ultra_private. For normal privacy, _private is enough !-) > Let's say the class is def

Re: Newbie Q: Class Privacy (or lack of)

2006-07-25 Thread Steve Jobless
Steve Jobless wrote: > > Hi, > > I just started learning Python. I went through most of the tutorial at > python.org. But I noticed something weird. I'm not talking about the > __private hack. > > Let's say the class is defined as: > > class MyClass: > def __init__(self): > pass >

Re: Newbie Q: Class Privacy (or lack of)

2006-07-26 Thread Simon Brunning
On 7/26/06, Steve Jobless <[EMAIL PROTECTED]> wrote: > If I was working on a large project with many engineers, I'd assume > someone will do things like this sooner or later. I've seen many > horrendous code in my life and I have no control over who I work with. If you work with cowboys, not P

Re: Newbie Q: Class Privacy (or lack of)

2006-07-26 Thread bearophileHUGS
Steve Jobless: > I'm hearing that "they are features, but don't use them." You can use them if you know why you are doing it. You can also take a look at PyChecker and PyLint, they may help you. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Q: Class Privacy (or lack of)

2006-07-26 Thread Steve Jobless
Sybren Stuvel wrote: > > Steve Jobless enlightened us with: > > The first case can be just a typo, like: > > > > x.valeu = 5 > > > > I make typos all the time. Without a spell checker, this message > > would be unreadable :). > > Then learn to read what you type, as you type it. Typing without

Re: Newbie Q: Class Privacy (or lack of)

2006-07-26 Thread Ray
Hey Steve, Yes, I agree with you. The lack of checking can get confusing fast. It's not about typing without errors. Regardless of how you train as long as you're human you WILL make typos. Also having to check whether a name has already existed can be a major pain in the butt with Python. With J

Re: Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Ray
Sybren Stuvel wrote: > Ray enlightened us with: > > Also having to check whether a name has already existed can be a > > major pain in the butt with Python. With Java you always know when a > > name has already existed, and what type is bound to the name. I > > consider this to be a Good Thing (tm

Re: Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Bruno Desthuilliers
Ray wrote: Ray, please, don't top-post (snip) > Also having to check whether a name has already existed can be a major > pain in the butt with Python. assert 'somename' not in dir(someObject) (snip) > Regarding the lack of privacy, s/privacy/language-inforced access restriction/ > --I guess

Re: Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread John Machin
Ray wrote: > The argument against this is that since development with Python is so > rapid, you're supposed to always equip your code with extensive unit > tests. I like Python but I've never really bought that argument--I > guess I've been doing Java too long :) > In Java, if you don't always e

Re: Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Bruno Desthuilliers
Steve Jobless wrote: > Sybren Stuvel wrote: > >>Steve Jobless enlightened us with: >> >>>The first case can be just a typo, like: >>> >>> x.valeu = 5 >>> >>>I make typos all the time. Without a spell checker, this message >>>would be unreadable :). >> >>Then learn to read what you type, as you ty

Re: Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Ray
Sybren Stuvel wrote: > Ray enlightened us with: > > Huh? No. The compiler will always tell you. Have you ever tried Java > > before? > > I know what I'm talking about, I've got a degree in Computer Science > from the University of Amsterdam. Then how come you didn't know that the Java compiler wi

Re: Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Ray
John Machin wrote: > Ray wrote: > > > The argument against this is that since development with Python is so > > rapid, you're supposed to always equip your code with extensive unit > > tests. I like Python but I've never really bought that argument--I > > guess I've been doing Java too long :) > >

Re: Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Ray
Bruno Desthuilliers wrote: > Ray wrote: > Ray, please, don't top-post Um, top-post? I'm using Google News and it looks like it is placed correctly in the thread... or you're referring to a different thing? Ray -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Ben Sizer
Steve Jobless wrote: > Sybren Stuvel wrote: > > > > Steve Jobless enlightened us with: > > > The first case can be just a typo, like: > > > > > > x.valeu = 5 > > > > > > I make typos all the time. Without a spell checker, this message > > > would be unreadable :). > > > > Then learn to read what

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Steve Jobless
Bruno Desthuilliers wrote: > > Steve Jobless wrote: > > Sybren Stuvel wrote: > > > >>Steve Jobless enlightened us with: > >> > >>>The first case can be just a typo, like: > >>> > >>> x.valeu = 5 > >>> > >>>I make typos all the time. Without a spell checker, this message > >>>would be unreadable :

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ray
Bruno Desthuilliers wrote: > > I'd rather let a machine to do that. Wasn't computer created for tasks > > like this? (No, not really. But...) > > There's obviously a trade-off between 'security' and flexibility. As I > said, I do make lots of typo too, but OTOH the edit/test cycle in Python > is u

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Steve Jobless wrote: > Bruno Desthuilliers wrote: >> >> Steve Jobless wrote: >> > But what about adding a method to the class? Am I supposed to ask "Is >> > anyone using name xxx?" >> >> assert 'xxx' not in dir(SomeClassOrObject) >> >> > The class may be used by develop

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ben Sizer
Ray wrote: > Actually Bruno, don't you think that the notion of flexibility in > Python comes at the expense of "security" is simply due to the fact > that the syntax of "screw up" is exactly the same as the syntax of "I > mean it this way and I do want it"? > > Perhaps if we use a different synta

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ray
Ben Sizer wrote: > Ray wrote: > > Actually Bruno, don't you think that the notion of flexibility in > > Python comes at the expense of "security" is simply due to the fact > > that the syntax of "screw up" is exactly the same as the syntax of "I > > mean it this way and I do want it"? > > > > Per

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Timo
Steve Jobless kirjoitti: > Let's say the class is defined as: > > class MyClass: > def __init__(self): > pass > def func(self): > return 123 > > But from the outside of the class my interpreter let me do: > > x = MyClass() > x.instance_var_not_defined_in_the_class = 456 >

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ben Sizer
Steve Jobless wrote: > Unfortunately, I don't see a way > to separate interface from implementation in Python. So, it may not make > much difference whether you subclass it or hack it from the outside. Documentation. (And name-mangling, underscore prepending, all the stuff the others said.) Whenev

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Bruno Desthuilliers
Steve Jobless wrote: > Bruno Desthuilliers wrote: >> Steve Jobless wrote: >>> Sybren Stuvel wrote: >>> Steve Jobless enlightened us with: > The first case can be just a typo, like: > > x.valeu = 5 > > I make typos all the time. Without a spell checker, this message >>

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Bruno Desthuilliers
Ray wrote: > Bruno Desthuilliers wrote: >>> I'd rather let a machine to do that. Wasn't computer created for tasks >>> like this? (No, not really. But...) >> There's obviously a trade-off between 'security' and flexibility. As I >> said, I do make lots of typo too, but OTOH the edit/test cycle in P

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Timo wrote: > Steve Jobless kirjoitti: > >> Let's say the class is defined as: >> >> class MyClass: >> def __init__(self): >> pass >> def func(self): >> return 123 >> >> But from the outside of the class my interpreter let me do: >> >> x = MyClass()

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ray
Bruno Desthuilliers wrote: > Ray wrote: > > Bruno Desthuilliers wrote: > > Actually Bruno, don't you think that the notion of flexibility in > > Python comes at the expense of "security" is simply due to the fact > > that the syntax of "screw up" is exactly the same as the syntax of "I > > mean it

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ben Sizer
Ray wrote: > Yeah, I know... but the thing is that it's easy to "do it". Say in C++, > you can rebind the method of a class to another function if you want > to, you can muck around with the vtable and stuff, but you've gotta do > something different than, say, a normal assignment. But remember, a

Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ray
Ben Sizer wrote: > Ray wrote: > But remember, at no point did they think to make that stuff > deliberately hard so that it would give you safety. It's hard because > the implementation is relatively complex. The flipside of that is > writing function objects in C++, which are an ugly hack to get a

Re:[OT] Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Bruno Desthuilliers
Ray wrote: > Bruno Desthuilliers wrote: > >>Ray wrote: >>Ray, please, don't top-post > > > Um, top-post? I'm using Google News and it looks like it is placed > correctly in the thread... or you're referring to a different thing? http://en.wikipedia.org/wiki/Top-posting -- bruno desthuilliers

Re: Re:[OT] Newbie Q: Class Privacy (or lack of)

2006-07-27 Thread Ray
Bruno Desthuilliers wrote: > Ray wrote: > > Bruno Desthuilliers wrote: > > > >>Ray wrote: > >>Ray, please, don't top-post > > > > > > Um, top-post? I'm using Google News and it looks like it is placed > > correctly in the thread... or you're referring to a different thing? > > http://en.wikipedia.