[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Is better to subclass or to add methods to an existing class?
From: michael libby <x () ichimunki ! com>
Date: 2002-09-19 13:02:24
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thursday 19 September 2002 07:20, Vincent Foley wrote:
[example modification of existing class snipped]
> But my friend told me that Python didn't have that because it was not a
> good thing and it was not the proper way to do it. He said that the
> true way of doing it, is to subclass (since Python 2.2 can now subclass
> builtin types) the base class:
[python code removed... washing hands...]
> His main argument was just that, "It's the Wrong Way (TM) to do it". To
> me, it just seems like extra code and added complexity.
It is the Right Way To Do It if your code passes all its unit and
acceptance tests. It is the Wrong Way To Do It if your code fails to
perform as expected. Beyond that, who cares?
You might perform some trivial benchmark to compare the two on a variety of
base classes and a variety of common "extensions" and reach some overall
efficiency conclusion, though.
> Can you enligthen me and tell me if it's really that bad an idea to add
> methods to an existing class, or if he's just being a Python zealot?
Nope, can't say. ;)
Personally if I have a function that takes a string and only a string (like
the example Rot13) then I would extend the String class. Otherwise, while
programming, I have to remember if my strings (lowercase) are Strings or
MyStrings in order to remember which methods they have access to.
But it depends on the application. Maybe in some cases I want two separate
kinds of strings.... kind of like how we have lots of separate kinds of
numbers.
-michael
++++++++++++++++++++++++++++++++++++++++++
Michael C. Libby <x@ichimunki.com>
public key: http://www.ichimunki.com/public_key.txt
web site: http://www.ichimunki.com
++++++++++++++++++++++++++++++++++++++++++
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE9icn84ClW9KMwqnMRAuj1AJ0XBOJMnFZdB9FRrvCHHQ8ls4310QCgo7/c
5cwfBokSCtha2DjtQ6KdqcQ=
=uoZ/
-----END PGP SIGNATURE-----
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic