Bad form to access a *private variable* like _foo?

S

seberino

Bad form to access a *private variable* like _foo?

The reason I'm asking is that TurboGears/SQLObject mobel objects have
an attribute called "_connection" that must be used to manually commit
database stuff....

e.g. MyObject._connection.commit()

It bugs me. I don't know if it is a stylistic faux pas or not.

Is it?

Chris
 
B

Bruno Desthuilliers

(e-mail address removed) a écrit :
Bad form to access a *private variable* like _foo?

In this case, this would be spelled "protected" - or even better
"implementation". And the contract is: nothing prevent you to access
implementation attributes, but then you're on your own if anything breaks.
The reason I'm asking is that TurboGears/SQLObject mobel objects have
an attribute called "_connection" that must be used to manually commit
database stuff....

e.g. MyObject._connection.commit()

It bugs me. I don't know if it is a stylistic faux pas or not.
>
Is it?

The way you wrote it here, yes. If there's no official way to do the
same operation and you have a real use case for it - in which case you
may want to add a commit() method to SQLObject's model base class and
submit the patch to SQLObject's maintainer. But I strongly suspect
there's a better way to handle this case in SQLObject's API.
 
D

Diez B. Roggisch

The way you wrote it here, yes. If there's no official way to do the
same operation and you have a real use case for it - in which case you
may want to add a commit() method to SQLObject's model base class and
submit the patch to SQLObject's maintainer. But I strongly suspect
there's a better way to handle this case in SQLObject's API.

There are other ways. For example,

sqlobject.sqlhub.threadingLocal.connection

if your system is using multiple threads correctly. Generally speaking,
sqlhub could/should be used.


Diez
 
S

seberino

There are other ways. For example,

sqlobject.sqlhub.threadingLocal.connection

if your system is using multiple threads correctly. Generally speaking,
sqlhub could/should be used.

That's actually quite involved. You must first get a reference to a
PackageHub object, then invoke connectionToURI, etc. lots of steps!

cs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top