From: "Shot (Piotr Szotkowski)" Date: 2009-12-02T03:52:14+09:00 Subject: Re: Class variables, instance variables, singleton; Ruby v. --J/dobhs11T7y2rNN Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable David Masover: > class Line > attr_reader :a, :b > def slope > (a.x - b.x) / (a.y - b.y) > end > end > No one has to know that @slope no longer exists. > Granted, you might have some coders who deliberately break things by > talking to @slope directly, but if you've defined an accessor, they > have to be a masochist to want to do it that way. Similarly, because > it's just one command for you to define them, you really have no > excuse not to. Also, if they=E2=80=99re accessing @slope directly, they deserve punishment =E2=80=93 and I don=E2=80=99t mean =E2=80=98deserve=E2=80=99 solely in the = bad-for-them sense, but also in a good-for-them way: it means their code was tailored to work with version X of your code, and if it relied on such low-level internals, it=E2=80=99s actually beneficial for them to know outright that your intern= al representation changed (and they might want to examine all of the places in their code that depend on the internal state of your objects). =E2=80=94 Shot --=20 Clinical psychology seems designed for people too smart for religion but not smart enough for science. [Paul Lutus, Asperger=E2=80=99s by Proxy] --J/dobhs11T7y2rNN Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAksVZdkACgkQi/mCfdEo8Ura/QCgkS9Ow8Kqij5LB7KFolY+7BbD 0mEAnikgvWoTZemiKjeCCGF1+edSFfXq =a5Rg -----END PGP SIGNATURE----- --J/dobhs11T7y2rNN--