[ABE.pm] Seeking comments re OOP (Continuing my series of dumb questions)

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Tue Dec 28 16:52:41 CST 2004


* Randy Kramer <rhkramer at gmail.com> [2004-12-28T14:16:21]
> It seems that in Ruby and Python, those numbers (all numbers) are
> objects, but, at least in the context of a banking application, I
> don't see the value of having those numbers be objects vs. simply
> being "values" without representing objects.  Instead, it seems like
> having those numerical values be objects rather than values (not
> objects) just adds some extra overhead.
> 
> Of course, if your programming in a language that treats all numbers
> as objects, that's what you live with, it just seems like overkill or
> something.
> 
> Comments?

If fixed numbers are objects, they gain methods.  If they have methods,
they have a morphology that other objects can emulate, and they begin a
class hierarchy from which other classes can descend.

Given fixed number 2, I can do things like:

	2.times { shake_it }

Which helps reinforce the rest of Ruby's loop types -- that it, methods
on objects that define the loop.  Or, conversely, because everything
/else/ is an object, like a Range, the programmer gets used to having
methods on objects for doing useful things like loop and get related
values.

	Range.each { |x| puts x }
	Range.max

So, by making every type an object, this metaphor works everywhere.  It
makes things more homogenous.  In fact, this is one of the places where
Ruby trumps Python.  Python acts as if all values are objects and have
methods, but a number of methods don't exist in "public" space.  To
delete a list element, for example, you must use the delete function, or
some private method like __delete__.

You said this seems like overkill.  I don't understand that criticism.
Does it slow your program down in some way that you can measure or
prove?  Does it result in having to write more code?  (Presumably it
actually means you need to write less.)

-- 
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/abe-pm/attachments/20041228/8aab3e6d/attachment.bin


More information about the ABE-pm mailing list