mystilleef said:
This is a __baseless__ statement.
Please explain what's wrong ? The "bad naming" part is your own
statement, the "27000 lines" is your own statement too, and I don't see
what's wrong with the assumption that producing 27000 lines of Python
took some time.
For all you know I could have used
the attribute twice in those 27000 lines of code.
How does this make my statement wrong ? Did I imply that you used this
attribute in each and any of the 27000 lines ?
Even then searching
for and replacing the attribute is tedious and error prone.
Indeed, and whether you believe it or not, I do share your pain here. I
had to face similar problem, and without even find and grep (a dumb
'CASE Tool' that stored it's proprietary language code in a
non-documented binary format and was missing decent, reliable
search/replace utilities). And the project was actually more than
50KLOC, forms description excluded.
Yes, the same way many programmers suddenly realize their class,
function, method, project, etc is poorly designed even after using it
for months and proceed to fix the problem. Shit happens.
Agreed. I don't pretend to be better than anyone else at this.
I wouldn't have started the topic if I did. Apparently the only
solution is to rereference the attribute with a better name and pray
and hope third party developers will use the better name. Or search and
replace!
Is actually this code already published ? If yes, you have the option of
making the 'tmp' accessor a computed attribute pointing to the better
named one, have the hidden getter/setter code emit a warning (including
useful informations about where the attributes is accessed - this is
opened to inspection), and officialy deprecate the badly named attribute
so you can definitively get rid of it in a near release.
I did no such thing, you are making that up.
Sorry, that's what I understood. If it's me being guilty of
overreaction, please accept my apologies.
Do you really think I used the name 27000 times in 27000 lines of code?
Of course not. But since 27KLOC is far from trivial for a Python
application, one can think that you had time to notice something wrong
with the naming/use of this attribute.
Maybe I'm not making myself clear. Having to search 27000 lines of code
to replace an identifier name is tedious and error prone.
Yes. You can of course encapsulate access to the attribute in a property
and have that property either emit a warning, raise an exception, log
the access etc, so if you missed some use of it, chances are you'll find
out pretty soon. Unit tests may help too - they can be great for
reporting broken code. You may also want to look if lint-like tools
(pylint etc) can help you there.
You are quoting me out of context. I was speaking with respect to real
accessors, not Python's latent implementation mechanisms.
This I had understood. My point is that if you *see* a public attribute
name as really being an accessor with automagical default
getters/setters (FWIW, look at the __getattribute__ method and Python's
name lookup rules - you'll notice that it's really how it works), then
your "compare that to accessors" doesn't stand.
No I'm not. Naming attributes and naming methods are entirely different
situations.
Why ?
In Python, a "method" is nothing else than a descriptor (attribute)
returning a callable. I agree that there's a small difference between a
callable and a non-callable object, in that you can apply the __call__
operator only to callables, but this doesn't make such a difference
here. In Python, methods are attributes. And naming is naming.
(snip)
I never complained about either languages. You are making that up.
I may be misunderstanding your point about "Java having a clear
distinction between attributes and methods" and overinterpreting it as
implying "Python doesn't and it led me into a bad situation, hence Java
is Good(tm) and Python is Bad(tm)". If so, once again, I do apologize.
Yes, I fixed it then. Which was 27000 lines of code later.
Not exactly a garden party.
Can you point me to exactly where I blamed Python for anything?
Point addressed above.
There is a dichotomy between data and methods. Yes even in Python.
The only dichotomy, from a technical POV, is that methods are callable -
but so are classes, and any object that has a '__call__' attribute that
is itself a callable. The 'dichotomy' here is the same as the dichotomy
between iterable and non iterable objects. Of between file-like and
non-file like objects. IOW, the difference amounts to supported
interface, not to the very nature of the concerned objects.
Yes, agreed. My fault. Let's take it back and not start fighting because
of a misunderstanding.
(snip)
I know. Many people still think the private/public classification is
unpythonic.
I'd rather say that many people thinks that language-enforced access
restrictors and the "public methods/private data" scheme are unpythonic.
And that if you're not sure wether a given name should be API or
implementation then make it part of the API - but then choose a
meaningful name for it !-)
Yes, a getter is a behavior. It instructs the object to perform an
action. All methods are message channels to an object.
Ok. Python's name lookup all go thru the __getattribute__ accessor. So
obj.value
is a synonym for
obj.__getattribute__('value')
which, according to your definition, is behaviour. Hence, there's *no*
"data attribute" in Python.
A data attribute
does not perform any action. It just holds data for an object.
The attribute itself may not perform any action, but looking up the name
is an action.
Even
though methods are attributes, attributes aren't necessarily methods.
Indeed.
This is basic OO, I don't see anything semantically complex about it.
It becomes complex when the languages sees functions as first-order
objects supporting the Callable interfaces and let you define your own
callable objects, and sees attribute-access as call to an hidden (well,
not that much hidden) getter/setter mechanism that one as all lattitude
to customize in many ways. Seeing that way really takes you out of the
Java semantic/mindset (well, at least it did to me, and I guess for at
least a few others).
This isn't an issue about object models and semantics, this is a
design/architecture issue with regards to eliminating the chances of
errors in large source code.
I was talking about the way you IMHO try to force-fit the common
"private data/public method" scheme (and it's associated dichotomy
between data and functions) into Python. Of course callable and
non-callable attributes usually have different usages, but we're really
far from the Java model where's the dichotomy between "data" and "code"
is irremediable.
Now wrt/ your naming problem, I think that you would not have done the
mistake if you had apply has much care to the naming of a non-callable
attribute as you assert (and I don't doubt you on this) you would have
for a callable one. You explain that you failed to do so because of you
viewing "data attributes" (ie non-callable attributes) as fundamentally
different from "methods" (ie callable attributes), so I try to share the
POV that Python is really different here, hoping this will help you
detect similar errors sooner.
The fact that I did, means I should have.
Then if you felt it finally had to be part of the API *and* was badly
named, you should have renamed it immediatly.
But granted, it's easier to say so afterward than to make the right
choice in the moment.
And how did you come up with that?
By understanding "evolved" as a process (implying a timeline), and
"important part of the system" as widely used.
(snip fighting part)
That doesn't mean I get it right.
(snip, idem)