From: ara.t.howard@... Date: 2007-02-08T08:15:28+09:00 Subject: Re: Patterns of semantic contradictions? On Thu, 8 Feb 2007, Robert Dober wrote: > Hi list > > I just could not resist to post a stupid remark - which was taken very > gracefully ty ;) - to a thread where somebody corrected his typo with the > well known sub idiom, only that he did something like > > "abcdefghijklmnop".gsub(/a/,"A") > > I am kind of troubled with this, of course this is equivalent to using #sub, > and the question that arose in my head is the following. > Is this a pattern to avoid? Can there be good reasons to do this and > furthermore and most importantly are there some publications about > "Antipatterns" like that. Maybe on much grater scale than my fun example. > > Well it is time to explain why it is an Antipattern to me, maybe you do not > agree at all. > > being a code reviewer and seeing 5 lines later > "abcda".gsub(/a/,"A") > I will be troubled, or should I not? Is it sound to assume that the coder > knows what she is doing? hmmm. hard to say without context, but i generally squirm at any regex that has neither anchors nor uses the positive, rather than negative - eg i prefer pathname =~ %r| IMG [^/]+ \.jpg $ |iox to pathname =~ %r/ IMG.*jpg /iox because it's can't sweep down path separators. interesing thread... -a -- we can deny everything, except that we have the possibility of being better. simply reflect on that. - the dalai lama