Patterns of semantic contradictions?

Hi list

I just could not resist to post a stupid remark - which was taken very
gracefully ty :wink: - 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?

Long live extreme programming :wink:

Cheers
Robert

On Thu, 8 Feb 2007, Robert D. wrote:

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

On 2/8/07, [email protected] [email protected] wrote:

On Thu, 8 Feb 2007, Robert D. wrote:

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

that is very good advice in practice and it is also an excellent example
for
my dilemma.
Redundancy (just imagine for the sake of argument that your regexp is
redundant in the space of strings it is applied to, which normally it is
not
of course) is a very good thing sometimes.
Your regexp tells the reader that you definitely do not want to match
“IMGS001/draft.jp” which might be pretty good for readability and
extensability, even if there are no such strings.

“a”.gsub(/a/,“A”) might have the same autocommenting effect in some
contexts, but it might be confusing too, I guess the team needs to talk
about this kind of ambiguity (think larger scale than the fun example
please).

What I was (or rather develop to be) up to is if there is a
categorization
of such things (on much a larger scale, sry if I repeat myself).
When we implement patterns, sometimes we refactor. When we do this do we
not
in some way look for Antipatterns to transform them into Patterns?

I would love to know more about that approach if it exists which I do
not
really doubt, gotta ask Google too :wink:

to

pathname =~ %r/ IMG.*jpg /iox

because it’s can’t sweep down path separators.

interesing thread…

thx :slight_smile:

-a


we can deny everything, except that we have the possibility of being
better.
simply reflect on that.

  • the dalai lama

Cheers
Robert

Robert D. wrote:

“abcdefghijklmnop”.gsub(/a/,“A”)

gsub seems out of place here; it feels like using a flat-headed
screwdriver to turn a star-headed screw. Instead, I would use tr:

“abcdefghijklmnop”.tr ‘a’, ‘A’

“abcda”.gsub(/a/,“A”)

Same here.