From: Jeff Wood Date: 2005-12-15T13:20:44+09:00 Subject: Re: regular expressions question --------------010903040806040504060700 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit James Edward Gray II wrote: > On Dec 14, 2005, at 6:16 PM, Jeff Wood wrote: > >> You should be able to tell who this message is meant for: > > > Yes, I recognize that you are probably speaking at least in part to > me, since I did that in this very thread. You can call me by name if > you like. I'm a big boy and I can take it. ;) > >> PLEASE stop sending out code that uses any of the perl ${x} >> variables ... > > > Hang on there Mr. Code Police. Let's not lay down the law down too > heavily before we get into this... > >> They are ugly and have no place in Ruby ... they are only provided to >> make the transition of Perl people easier ... > > > I seriously doubt those variables were invented in Perl. They are a > common feature to many Regular Expression implementation and I'm not > sure they are even that ugly. $1 holds what was grabbed by the first > set of parenthesis. Fairly logical. > >> Please teach people to use MatchData objects ... > > > I also showed a MatchData example. > > I've used them a time or two, but honestly, they just don't feel > right to me. I've stopped using the default variable, I'm using a > two-space tab, etc. I'm Ruby assimilated, but I just like the Regexp- > linked variables. > > I see a lot of code running the Ruby Quiz and I feel quite confident > saying that the Regexp variables are far more common than MatchData. > I don't think that says anything bad about the latter, but it does > tell me that you are in the minority. ;) > > We won't yell at you for using MatchData, if you'll provide the same > consideration... > > James Edward Gray II > > > Quite simply, Ruby is *supposed* to be about consistency ... Having the "everything is an object, principal of least surprise" mantra, then using these which act like a global ( $ ) but aren't actually ( local scope ) is just vile. That's why I have a problem with them. If the community uses them, well, that's their option, I'm just one that's all for consistency, always, as much as possible... It tends to make things more generic and able to handle change better. I can't speak as to whether Perl was the first language to do the ${x} variables ... but, it ( so far of the languages I've learned ) uses it heavily, and it contributes to all of the punctuation soup that we all left Perl to get away from... ( again I'm speaking generally, but I could also again be wrong ... that's one of the uglies I left because of ). ... Not trying to be language police, I just really love the MatchData, and find it MUCH easier to deal with. Then you can keep your datasets from multiple matches around ... to me it *is* easier to read ... instead of ... $1 ... where'd that come from ... I didn't assign a glob... oh that's right ... Anyways, I'm sorry to have causes this thread to go on this long ... I just really thought more of the people on the list would step up and say, yeah, those are some very ugly warts and we don't use them ... but apparently, I was wrong. I'll shut up now. j. --------------010903040806040504060700--