--bg08WKrSYDhXBjb5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Mar 18, 2011 at 05:15:08PM +0900, Ryan Davis wrote:
>=20
> There is nothing "kind of ugly" about it and it doesn't "work fine".
> The regexps are _very_ ugly and as you can see below, they're ugly
> enough that it is hard to see that they're wrong and fit to match a lot
> more than they should. I edit one step at a time and describe each step
> above the method.

I find your attitude distasteful.  Have you tried being a pleasant human
being and found it not to your liking, or have you simply never tried it?

=2E . . and you did not actually show that they match more than they
should.

[snip]

>=20
> # remove stupid formatting and align - flog: 35.1

"Stupid formating" is "limit column width", which is helpful in a number
of environments in which the code needs to be read and/or edited,
including email.


>=20
> # remove unnecessary to_s.downcase.match - flog: 9.7

Actually, the to_s.downcase was moved elsewhere in the code anyway
shortly after I sent this email.  In fact, I thought it had been changed
*before* I pasted into the email, but apparently I did that in the wrong
order.  The to_s is *not* unnecessary, though, considering certain
non-string values are possible in the method argument (something I did
not explain in the previous email, but that I figured anyone with half a
brain might figure out from the presence of the to_s message).  The
downcase is more explicit and noticeable than the regex "i" at the tail
end of an ugly regex.  In Ruby code, I prefer .match over =3D~, because I
prefer to write Perl only when writing Perl, and not when writing Ruby.


>=20
> # remove unnecessary regexp [c][a][s][e][s] - flog: 9.7

Yeah, I don't know what I was thinking with the brackets.  I had a brain
fart.  Thanks for pointing out that boneheaded maneuver on my part.

Strangely, two people who can write Perl in their sleep and are more
intimately familiar with regex syntax than with their wives also looked
at this code and completely failed to notice the unnecessary brackets.  I
don't know how that happened.


>=20
> # switch to case - flog: 9.6

*Now* the .match method becomes unnecessary.  Good call, going with the
case statement.


>=20
> # now that it is a lot less complex, you can see a lot more clearly
> # that the regexps involved match a lot more than intended. eg: stgth
> # either, you need s(?:t(?:r(?:e(?:n(?:g(?:t(?:h)?)?)?)?)?)?)? (ugh)
> # or you need an entirely different approach: - flog: 13.6
> def expand_attribute_arg6 attr
>   {
>     "strength"     =3D> 1,
>     "dexterity"    =3D> 1,
>     "constitution" =3D> 2,
>     "intelligence" =3D> 1,
>     "wisdom"       =3D> 1,
>     "charisma"     =3D> 2,
>   }.each do |str, len|
>     return str.capitalize if attr.size >=3D len and str.index(attr.downca=
se) =3D=3D 0
>   end
> end
>=20
> # or:
>=20
> require "abbrev"
>=20
> attribs =3D %w(strength dexterity constitution intelligence wisdom charis=
ma)
> ATTRIBS =3D Abbrev::abbrev attribs
>=20
> # use abbrev - flog: 2.6
> def expand_attribute_arg7 attr
>   ATTRIBS[attr.downcase]
> end

Thanks for that.  The first, especially, is the kind of solution I
wanted.

>=20
> P.S. _NEVER_ exit from a library method. Raise and exit above.
> Rescuable, testable, maintainable.

P.S. Never be an asshole.  It tends to make people ungrateful even when
you've helped them.  Your opening made you come off like a jackass with
an urge to belittle people, who offers helpful coding advice only as an
unintended side-effect of serving that urge.

--=20
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

--bg08WKrSYDhXBjb5
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAk2DGRsACgkQ9mn/Pj01uKWrLgCgrcoan//jH13B4tE7XWBuJnIk
y+8AoLIxAH1lhFyVFFL396ZHmJ34UzBK
=j/DR
-----END PGP SIGNATURE-----

--bg08WKrSYDhXBjb5--

On Fri, Mar 18, 2011 at 05:15:08PM +0900, Ryan Davis wrote:
>=20
> There is nothing "kind of ugly" about it and it doesn't "work fine".
> The regexps are _very_ ugly and as you can see below, they're ugly
> enough that it is hard to see that they're wrong and fit to match a lot
> more than they should. I edit one step at a time and describe each step
> above the method.

I find your attitude distasteful.  Have you tried being a pleasant human
being and found it not to your liking, or have you simply never tried it?

=2E . . and you did not actually show that they match more than they
should.

[snip]

>=20
> # remove stupid formatting and align - flog: 35.1

"Stupid formating" is "limit column width", which is helpful in a number
of environments in which the code needs to be read and/or edited,
including email.


>=20
> # remove unnecessary to_s.downcase.match - flog: 9.7

Actually, the to_s.downcase was moved elsewhere in the code anyway
shortly after I sent this email.  In fact, I thought it had been changed
*before* I pasted into the email, but apparently I did that in the wrong
order.  The to_s is *not* unnecessary, though, considering certain
non-string values are possible in the method argument (something I did
not explain in the previous email, but that I figured anyone with half a
brain might figure out from the presence of the to_s message).  The
downcase is more explicit and noticeable than the regex "i" at the tail
end of an ugly regex.  In Ruby code, I prefer .match over =3D~, because I
prefer to write Perl only when writing Perl, and not when writing Ruby.


>=20
> # remove unnecessary regexp [c][a][s][e][s] - flog: 9.7

Yeah, I don't know what I was thinking with the brackets.  I had a brain
fart.  Thanks for pointing out that boneheaded maneuver on my part.

Strangely, two people who can write Perl in their sleep and are more
intimately familiar with regex syntax than with their wives also looked
at this code and completely failed to notice the unnecessary brackets.  I
don't know how that happened.


>=20
> # switch to case - flog: 9.6

*Now* the .match method becomes unnecessary.  Good call, going with the
case statement.


>=20
> # now that it is a lot less complex, you can see a lot more clearly
> # that the regexps involved match a lot more than intended. eg: stgth
> # either, you need s(?:t(?:r(?:e(?:n(?:g(?:t(?:h)?)?)?)?)?)?)? (ugh)
> # or you need an entirely different approach: - flog: 13.6
> def expand_attribute_arg6 attr
>   {
>     "strength"     =3D> 1,
>     "dexterity"    =3D> 1,
>     "constitution" =3D> 2,
>     "intelligence" =3D> 1,
>     "wisdom"       =3D> 1,
>     "charisma"     =3D> 2,
>   }.each do |str, len|
>     return str.capitalize if attr.size >=3D len and str.index(attr.downca=
se) =3D=3D 0
>   end
> end
>=20
> # or:
>=20
> require "abbrev"
>=20
> attribs =3D %w(strength dexterity constitution intelligence wisdom charis=
ma)
> ATTRIBS =3D Abbrev::abbrev attribs
>=20
> # use abbrev - flog: 2.6
> def expand_attribute_arg7 attr
>   ATTRIBS[attr.downcase]
> end

Thanks for that.  The first, especially, is the kind of solution I
wanted.

>=20
> P.S. _NEVER_ exit from a library method. Raise and exit above.
> Rescuable, testable, maintainable.

P.S. Never be an asshole.  It tends to make people ungrateful even when
you've helped them.  Your opening made you come off like a jackass with
an urge to belittle people, who offers helpful coding advice only as an
unintended side-effect of serving that urge.

--=20
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAk2DGRsACgkQ9mn/Pj01uKWrLgCgrcoan//jH13B4tE7XWBuJnIk
y+8AoLIxAH1lhFyVFFL396ZHmJ34UzBK
=j/DR
-----END PGP SIGNATURE-----