Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: The Accessor Heresy

by QM (Parson)
on Nov 28, 2005 at 17:04 UTC ( [id://512282]=note: print w/replies, xml ) Need Help??


in reply to Re: The Accessor Heresy
in thread The Accessor Heresy

I already created the damn thing - why should I have to tell it how big it is??
(My comment here may be too specific for the general question. If I'm off base, someone poke me gently.)

Suppose you have a circle, and now its area needs to be changed. Do you compute the corresponding radius, or do you just set the area, and let the circle compute the radius?

Suppose it's not Euclidean geometry, but spherical. The circle object should already be instantiated with the geometry parameters (degree of space curvature). You can set the area, and the radius and circumference are updated for you. (Note that in spherical geometry, you can have a radius and circumference of zero and still have a positive area.)

I guess it depends on what the object's capabilities are, and whether you want to derive the settable attribute yourself (radius based on area), or have the object tell you.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^3: The Accessor Heresy
by dragonchild (Archbishop) on Nov 28, 2005 at 18:52 UTC
    Suppose you have a circle, and now its area needs to be changed.

    That's a requirement that would mean a new feature. Something like:

    # Perl: sub set_area_to { my $self = shift; my ($area) = @_; $self->{radius} = sqrt( $area / $PI ); return; } # Ruby def area= (new_area) @radius = Math.sqrt( new_area / @@PI ) end # Note, this means that the Ruby version allows for: # circle.area = 22 # And it will DWIM

    I fail to see the problem.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://512282]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found