February 8th, 2013, 08:28 PM
Gotta see today's XKCD
February 9th, 2013, 05:18 AM
Think i have seen the similar "joke" in someone signature.
What is it that makes regular expression so bad? performance?
February 11th, 2013, 08:07 AM
You have indeed. Axweildr has had a related quote in his sig for years.
Originally Posted by MrFujin
February 11th, 2013, 12:31 PM
I figured the comic was a play on that too.
Originally Posted by ishnid
February 11th, 2013, 01:18 PM
Want to comment at my question too?
February 11th, 2013, 02:36 PM
That can be answered with another quote.
More seriously, people learn this cool new thing called "regular expressions" and try to come up with situations where they can use it. Even if it's just to show off. Even if regular string parsing or DOM traversal or something else more appropriate (and correct) exists. And half the time these people have a decent, not complete, understanding: no sense of optimizations, don't understand how greedy quantifiers work with the engine, think that an expression they have which works on their sample input will necessarily work for every other input (valid or otherwise)...
February 11th, 2013, 05:09 PM
Ok, that makes sense and clarified that it is more about be able to "use the correct tool to the correct job" instead of the tool itself.
Would say I have great use of regex in notepad++, but must probably also admit that half of the reason is in the "fun" to find out if it can be done this way.
I'm usually using regex to wrap same text or similar that have to applied around several lines of text.
February 11th, 2013, 05:43 PM
I totally agree with this, and probably most people discovering the power of regexes tend at one point or another to try to overuse them, or abuse them, or use them where there are much better tools, but once you really understand them (including issues of greediness, eagerness, etc.), and also know other tools available in the language or environment you are using, regex are a tremendous tool at your disposal when they are available. They should not be used for things for which they are not fit (they are not a good substitute for a real parser, for example, and should generally not be used for parsing XML or HTML files, for example), but they are immensely useful for doing the things for which they are fit.
Originally Posted by requinix
And performance is certainly not a good reason not to use them, unless you really have a performance issue (and provided you are using regexes in a good way). I am working almost daily with huge files (10 or 15 gigabytes, sometimes even 10 to 20 times larger) and am happily using Perl regexes on them, when they are fit to the purpose. A very very poorly designed regex can take billions of years to match (or not match) just a single line of input (well, actually, I guess you really have to do it on purpose to reach such a bad result, but the point is that it is possible), but a good regex can also analyze hundreds of million lines in a few minutes.
In brief, regexes are an excellent tool for some purposes, and may be a disaster for others.
An additional point about performance. If you are working on relatively small data input (in my perspective, 100 megabytes is often small), ask yourself the question whether it is worth spending hours of valuable developer's time for winning a few seconds of processing time. Usually not (but, in rare cases, yes). So, if regexes enable you to write the really useful part of a program in 3 lines of codes, rather than 300 lines (meaning development times 10 or 100 times shorter), it is quite likely to be the right way to go unless you really have difficult processing time constraints.