Objects in Python
lipska the kat
lipskathekat at yahoo.co.uk
Thu Aug 23 05:19:36 EDT 2012
On 22/08/12 22:31, Evan Driscoll wrote:
> On 08/22/2012 02:45 PM, lipska the kat wrote:
>> On 22/08/12 20:03, Evan Driscoll wrote:
>>> Second, this concept isn't *so* unfamiliar to you. If I give you the
>>> following Java code:
>>>
>>> void foo(Object o) { ... }
>>>
>> looking at this method declaration I can see that the method takes an
>> argument of type Object (and just FYI class Object is not abstract and
>> you can do Object o = new Object()) and does not return a value.
>> I know that for the lifetime of this JVM, whatever o turns out to be it
>> will always be an Object. I can't assign a primitive to o as ints chars
>> floats etc are certainly not Objects. There are certain invariants that
>> give me a warm and comfortable feeling inside.
>
> I'm not saying it's nothing, but "can't assign a primitive" isn't much
> of an invariant in the broad scheme of things
Well we don't want to turn this into a language comparison thread do we,
that might upset too many people but I can't remember ever writing a
method that took an Object as argument, you just can't do that much with
an Object. I do however often write methods that take an interface as
argument knowing that in future, any classes I write that implement this
interface would just work thanks to subtype polymorphism
A method 'declaration' such as this in an interface
Product getProductByBarcode(Barcode b) throws CrappyProductException;
tells me a whole lot about what the 'definition' in an implementing
class might do, in fact I might well get away with just reading the
interface and using the method without having to delve into the code.
And I think this is the nub of the problem at the moment. I'm in a
particular mindset, almost 'locked in' you might say and when I see a
Python function that doesn't give me what I need straight away I get
annoyed.
I will get over it.
> when you can pass items as
> diverse as lists, GUI buttons, files, etc. I would say it's more like if
> you see 'int x' then *that* imposes a pretty big invariant, but passing
> 'Object' imposes almost nothing.
Well you may be able to pass them in but you couldn't really do anything
meaningful with them as you are restricted to operations on Object, I
suppose you could pepper your code with tests to check the runtime type
of a reference but it all gets a bit messy.
[snip]
> Thus *all*
> Python variables are essentially references.)
That makes sense
Thanks for taking the time to reply. It really is most valuable to me.
lipska
--
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
More information about the Python-list
mailing list