[BangPypers] Object Oriented Programming in python

Dhananjay Nene dhananjay.nene at gmail.com
Mon Oct 21 04:39:45 CEST 2013


On Fri, Oct 18, 2013 at 5:58 PM, s|s <supr.e.etsethi at gmail.com> wrote:
> On Fri, Oct 18, 2013 at 11:31 AM, Dhananjay Nene
> <dhananjay.nene at gmail.com>wrote:
>
>> On Tue, Oct 15, 2013 at 4:44 PM, s|s <supr.e.etsethi at gmail.com> wrote:
>> > Hi Pranav,
>> >
>> > I would pose a counter question regarding object oriented programming.
>> How
>> > did you learn OOP concepts? I am assuming like most of us, probably
>> through
>> > a C++ or Java course. These courses ingrain a certain expectation of what
>> > OOP should "look like". Which to me seems to be a dis-service to
>> > underpinnings of Object Oriented Paradigm itself.
>>
>> How so ?
>>
>>
> To me, OO Paradigm is not about having a keyword **class** in a language
> but the sense of constructing an ensemble of programmed units which makes
> sense together. To illustrate, GObject in Gtk+ is as much a first rate OO
> implementation as any other. In fact some of the new breed of languages
> like Golang do not follow conventional structure of OOP popularized by C++
> and Java.

Not really sure what you mean by constructing an ensemble of
programmed units which makes sense together. In a lay reading that to
me is what module systems are for.

I haven't looked at GObject. So can't analyse the rest of what you
say. But an interesting definition for me always has been "OP to me
means only messaging, local retention and protection and hiding of
state-process, and extreme late-binding of all things." - Dr. Alan Kay
(http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay_oop_en).
Some commentators believe open recursion is necessary (though I myself
haven't subscribed to that yet).

>> >
>> > Python implements OOP differently from imperative languages of C family
>> > like C++ and Java. The reason, I think is C++ and Java are very much
>> driven
>> > towards machine code efficiency whereas Python is very much about
>> > developers productive.
>>
>> Can you cite an example ?
>>
>>
> Lets look at integer as an example in Python (int)
>
> class int(object)
>    int(x[, base]) -> integer
>
> which is unlike java where int is a "basic" non-class type. An explicit
> upgrade to **Integer** class is required to use OOP features. This is done
> with sole purpose of machine efficiency.

Ahh, the primitives. But in most cases primitives have their OO
counterparts, so you can pick and choose. Fair enough. Java in the
late 1990s and early 2000s was very very very slow. A lot of it had to
do with how it used memory, the garbage collections the late binding
as compared to C++, the JVM etc. etc. It was later that the JVM got
well tuned enough for the performance it shows off now. I don't think
I would ever imagine java itself was "ever" designed towards machine
code efficiency .. though it did work out that way eventually.

>
>
>> >  To this end Python developers must have thought of
>> > data hiding as not an important language goal.
>>
>> The traceability of the above "to this end" to "data hiding as not an
>> important language goal" is very unclear. Could you clarify
>>
>>
> Python, to me, seems to lean towards reducing development time. To "this
> end" simple implementation is used instead of grand frameworks. Data hiding
> with public, private, protected is just one of these frames. Yes again I am
> critiquing Java.

Hmm ... there's boiler plate and there's frames of additional
capabilities. I think Java and C++ suffered from more boilerplate,
which was co-incidental. I can't imagine how just prefixing with a
public / private / ... reduces developer productivity - in fact by
promoting information hiding it can help hunt down bugs faster. And
modern languages like Scala don't require you to do getX / setX - they
can give you that capability - even switching from attributes to
functions and back with a simple change of a word. So, as yet I remain
unconvinced about the link between data hiding and developer
productivity.

>> > Mind you Python does allow data hiding through slots but it is not as
>> > straight forward as C++ or Java.

How so ?

class Foo(object):
    __slots__ = ["val"]
    def __init__(self, val) :
        self.val = val


f = Foo(5)
print(f.val)

Dhananjay
e


More information about the BangPypers mailing list