[Tutor] Objects C++ vs Python
Corey Richardson
kb1pkl at aim.com
Thu Jun 9 21:33:54 CEST 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 06/09/2011 07:03 AM, Ashwini Oruganti wrote:
> On Thu, Jun 9, 2011 at 3:32 PM, Walter Prins <wprins at gmail.com> wrote:
>
>> Object Oriented code in e.g. a procedural language like C, which obviously
>> doesn't support the notion of objects explicitly in the language, although
>> then it's up to you to come up with conventions and infrastructure to
>> support the concept of object orientation in your program.
>
>
>
> Didn't know that! It's interesting that GObject is itself written in C,
> which is a procedural laguage..
>
(The Python interpreter you're probably using is written in C too)
Well, anything object-oriented will get executed on a processor, which
is procedural, and stored in RAM, which is essentially just a giant
array of numbers. It should come with no surprise that OO can be and is
written in a procedural language.
An object is just data+behaviour, take this snippet of C:
struct address_book_entry {
char *name;
char *address;
char *extra;
};
void
printPerson(struct address_book_entry d) {
/* d is a pointer so we could modify it */
printf("%s, age %d\n", d.name, d.age);
printf("Address: %s", d.address);
}
Encapsulate that, and you have yourself an object. OO isn't hard to do,
even (single!) inheritance isn't too great of a challenge. It's getting
things dynamic instead of static that's the biggest challenge.
- --
Corey Richardson
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
iQEcBAEBAgAGBQJN8SAiAAoJEAFAbo/KNFvpi/oIAJfSwifBQzilopoZTS3gEggT
4ekhhW1ao8XOcmgEBSrCLL5rWwQeYDGF1USkdeSQSpUfqEb6g7ua3HuhvOimRGKs
KQx7t5jhI3AvWKE/mXslXD4nCq+vRf0q4AvGngnnAByEeQfbeZPg3huLeo6/SzXn
QLHAbKKhcHWAXwmbhx4EbTkTEgyQocVNkjYj8z9bMxRcW0IMcj+ePDsPs0IQUALO
D2T4xwjb7QwDC1OgQoGbMwTEGWup2ULxAOpMpFVwgyz2BgY7rm1PkQ2NTJuYSGIE
TYhQ4HtyevMfORjPyfvq/JJG+QYBXseucAev4PizQkCgxuA++6JF7/VHJDXJPVw=
=LXLl
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list