From: "Shot (Piotr Szotkowski)" Date: 2009-09-01T06:49:42+09:00 Subject: Private methods’ viability (was: What is the ruby conventions to name private method?) --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Ryan Davis: > 4) Don't have private methods if you don't need them. > 5) You don't need them. No, really. I=E2=80=99ll bite. Note: I consider myself a beginner Rubyist and I=E2=80= =99d love to hear your (and others=E2=80=99!) reasons for the above and/or against the b= elow. :) I use private methods when I factor them out of my public methods (once the public methods have decent spec coverage). This makes me think harder on the (hopefully =E2=80=93 minimal) public API of my objects and prevents me from calling such methods =E2=80=98in just that single place where it would be useful=E2=80=99; a method=E2=80=99s either useful to the = outside world (and should be promoted to public API with individual, descriptive spec coverage) or not, period. Using private methods helps me keep checks on this. I also use protected attr_readers so that my objects can tell whether they =3D=3D others of the same kind without exposing their instance variables to the outside world; an attr_reader on an Array/Hash/Set does not guarantee that the given Array/Hash/Set is not modifiable from the outside world=C2=B9, hence I=E2=80=99d rather not expose such instance = variables more than necessary. =C2=B9 It=E2=80=99s one of the few places where Ruby diverges from the prin= ciple of least surprise; I can see certain lovely symmetry and simplicity in attr_reader working the same for all variables, but I found the name a bit misleading when I started to learn Ruby =E2=80=93 my thoughts were th= at it should either not be called a reader or should return a dup of the variable in question=E2=80=A6 (I did get used to this since then, though, a= nd realised that other languages=E2=80=99 generic getters usually do the same.) =E2=80=94 Shot --=20 Born to be mild. [elpanda] --wRRV7LY7NUeQGEoC 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) iEYEARECAAYFAkqcRXAACgkQi/mCfdEo8UpIWwCeNYQ+NZNW895936Gbnwj3btMA ylYAnRbvAkMrzP0Ep6SW1y6kl07id7aV =0fIP -----END PGP SIGNATURE----- --wRRV7LY7NUeQGEoC--