Re: function to match parenthesis '(' and ')'

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Ludovic SOEUR" <Ludovic_SOEUR@xxxxxxxxxxx> wrote in message
news:%23Kq5w2J2FHA.3560@xxxxxxxxxxxxxxxxxxxxxxx
>I did not think that my post would start a debate. So as it has started, I
> have to reply.

Well, you can't expect a nice troll like me not to participate in one. =)
While I'm a joker and probably will drive you nuts below and in future
posts;
I do think you have created a nice debate and have some serious points.

> I put this sample to prove that it's possible with regex and I would like
> to
> do a time comparison too. I still stay on my point of view when I say I
> prefer RegEx version if you do not need to do this check 100 000 times.

What works and what we find desirable are seldom the same.
We all know you CAN do it, but do we really WANT it. What do we find USEFUL?

> First of all, I would like to answer to Michael's reply. No, I'm not evil
> enough to write such a RegEx. I used the Regex from the Ryan Byington's
> one
> http://blogs.msdn.com/bclteam/archive/2005/03/15/396452.aspx
> that is very well explained. The only improvment was to remove all 'names'
> and to capture ONLY valid strings (the ones Steve is looking for). I
> ALWAYS
> explain my regular expressions and this one is a very usefull one that is
> known by most of who works with regex.

And I was being funny/ironic.
If you do code such a complex regexp, I would expect a full description of
what it does.
The thing is that the commentary would probably take up a lot of space and
be forced to use complex language.

I would bet that for the comment to be useful; it would take up more space
than if you coded it 'by hand' as in the example in the previous post.
Hence, not only do you got a cryptic regexp, you also have a cryptic comment
that actually is poetry, for what code could better describe, taking up same
amount of .cs-space.

> Maintenance for this case is useless. It's like providing a function for
> the
> System namespace. You dont have to do maintenance for "substring" method
> of
> string class. When a regular expression is known to be correct and used by
> many developpers, you don't have to change anything. Only put a link to
> the
> original explanation and add comment in your code if you want to be more
> precise. On the other hand, Marcus code must be commented, and i would
> say,
> more than the regex one...it should be surprising for most people who are
> not used to balancing in regex.

Amagad. I don't know where to begin...

First things first:
This is a typical case for maintanance. Wanna bet that the OP (his/hers
customer really) comes back and says: - I need to to skip '(' and ')' that
are inside strings a la " and also support braces and curly braces.

Code tend to change...

Secondly:
This is also a typical example for when "developers" don't care for
"maintainers".
As an architect and technical project manager, a part of my job is to
'approve code'.
Often I read 'smart code' like in your example and simply won't accept it.
Too complex.

While being a joking lurking troll, with some (dubious) knowledge, in this
newsgroup; I can be a pretty serious dude at work. When I review code, there
is just one criteria: - Is this maintainable? If so, quality and
performance; are aspects I'd consider. But the first question takes care of
several sub-questions. Is it understandable? Is it readable? Does it need
commenting? Is it fault tolerant? Are all bounds, constraints and exits
handled? Is that visible? Do I like what I read?

Your regexp would never make it to the test-server if I eyeballed it. =)

> Second, to answer to Jon, it took me 2 minutes to understand the original
> regex from Ryan Byington. Firstly because it's well commented and also
> because I am used to writting balanced regex.

<-snip->
Well, YOU are perhaps. The poor dude or gal that needs to modify your
regexp, 3 years after you wrote, it might not be as clever as you.... Or
even find your code as 'fun' as you thought it was when you wrote it. I've
seen it before and I'll probably see it again in the future: People with a
lot of free brainpower doing smart stuff to please themselves and not the
project, system and customer they work for.

Are you even sure that regexp will be still in use for the next 3 years? 5?
10? 20?
I'm not so sure. But what I do know is that keywords like while, for, if,
else and switch are here to stay.
I also believe that humans can and like to follow a sequence, and dislikes
trying to figure out how someone elses regexp works. Call me silly...

> I totally disagree when you say that regular expression is not the job for
> this work. With one line that you do not mind if it's understable, you can
> do everything you need with parenthesis balancing. It's the right tool if
> you not need to do a loop over thousands of checks, you don't have to
> write
> your own classes or method, everything is already done. It's like using a
> dll, libray, in four words, reusing what was done.

I totally agree that this is a wonderful example of when not to use regexp.

Just to prove my point:
I for sure didn't even try to understand your regexp. Too complex...
Why don't you write a GOOD comment to your regexp and we'll see if thh rest
of us can understand that.

I dare you.. =)

> Ludovic SOEUR.

High Regards
- Michael S


.



Relevant Pages

  • Re: Identifier like "_", "$", etc.
    ... Do not expect that to be a reliable source of ... function should be "Do not use with RegExp ... What if regex ends up as an argument of your function and that function invokes `call` on it after testing it with `typeof`? ...
    (comp.lang.javascript)
  • Re: Can Access use Fuzzy Logic - RegEx
    ... And OLE makes it easy to use VBScript's RegEx ... I, for one, have never found RegExp to be easy to understand at all. ... while VBA string handling functions are native to Access (and thus, ... expect it to be less efficient than the native VBA string handling ...
    (comp.databases.ms-access)
  • Re: [FYI] MSXML HTTP translates response status code 204 to 1223
    ... Don't you think regex is really a wrong tool for the job in this case? ... Modifying the property requires much less effort than modifying the method. ... the RegExp provides the user which much an ... Efficiency difference most definitely doesn't matter. ...
    (comp.lang.javascript)
  • Re: Change a single character in a string
    ... I already gave this regex in another branch of this tread: ... There is an overhead to the construction of a RegExp and to the ... but after that the replacement will be quick. ... 8-character strings; for a 2-character string, ...
    (comp.lang.javascript)
  • RE: [PHP] Validating Email Conditional
    ... know what they are doing and did the regex right... ... Subject: Validating Email Conditional ... accommodating some of the formats you provided. ... get rid of the regexp completely. ...
    (php.general)