Live data from Hacker News

How I fixed a bug in Atom

davidvgalbraith.com

161–170 of 189 posts

Re: How I fixed a bug in Atom

#161
post #149

Earlier quoted context omitted.

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. - Jamie Zawinski

Just so you know, jwz is not the original source of this quote, it's much older: http://regex.info/blog/2006-09-15/247

Your reference link literally says that Jamie Zawinski is the originator of the quote.

Re: How I fixed a bug in Atom

#162

Isn't arbitrarily-long nesting or matching any sort of palindrome, where you count up and down, the classic case of something you should never do with a regex, because they're finite automata? People don't build parsers because of masochism, but because regular expressions are provably insufficient to capture things like nesting. You need to go at least one level up on the Chomsky hierarchy[1] to pushdown automata fo…

I guess NFA is the classic regex, but most implementations are vastly more powerful through the introduction of backtracking and back references.

In any case, a regex is hilariously unsuitable for the purpose here. It's obtuse, it has terrible corner case performance (as noticed here), it probably took vastly longer to write than a simple loop and apparently it isn't even correct.

Re: How I fixed a bug in Atom

#163
post #98

Earlier quoted context omitted.

I don't always want to spend insane amounts of time writing full AST parsers. Sometimes it is a lot easier to write a simple, hacky, throwaway regex. It's a bit much to claim that backtracking regular expressions, a very useful tool sometimes, should never ever be used and everybody should waste loads of time writing careful code even in situations where it isn't required. The problem is not the tool. The problem is…

"I don't always want to spend insane amounts of time writing full AST parsers." This is an effect of the language, not the problem space. Backtracking REs make it very easy to write bad code, and then most languages make writing the parsing code hard. If you're in a language that makes parsing code easier, like Haskell, then the tradeoff isn't anywhere near so bad. I don't mention Haskell just because it's the trendy…

Interesting. Can you point to a piece of Haskell code that does some parsing of roughly the same level of complexity of that in the OP, so that we can compare how long it takes to write such a parser compared to a regex?

Re: How I fixed a bug in Atom

#165
post #149

Earlier quoted context omitted.

Just so you know, jwz is not the original source of this quote, it's much older: http://regex.info/blog/2006-09-15/247

Your reference link literally says that Jamie Zawinski is the originator of the quote.

You must not have finished reading. He originated the version that says "regular expressions", but not the "two problems" part or the sentiment about textmatching:

>As cute as the “now you have two problems” quote is, it seems that Jamie wasn't the first to come up with the idea. The same quote (but with AWK rather than regular expressions as the punch line) shows up in the sig of John Myers post from 1988, where he credits a “D. Tilbrook” for it:

“Whenever faced with a problem, some people say `Lets use AWK.' Now, they have two problems.” -- D. Tilbrook

Re: How I fixed a bug in Atom

#166

Earlier quoted context omitted.

Actually, this is false. A lot of regex implementations use a backtracking approach in all cases, causing pathological behavior even on regexes which match a regular language (and so should never take any significant amount of time to process). See https://swtch.com/~rsc/regexp/regexp1.html , which gives a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (see the backtracking?…

> (see the backtracking? me neither) If I understand the article correctly, the Perl regex evaluator, if given a string consisting of only the minimum required number of 'a's, first matches them to the optional 'a's, and then has to backtrack to match the required 'a's.

I misspoke a little. The point is that that expression doesn't use backreferences, and therefore doesn't need to use backtracking at all. The fact that it does use backtracking anyway is the focus of the complaint.

Re: How I fixed a bug in Atom

#168

Earlier quoted context omitted.

Your reference link literally says that Jamie Zawinski is the originator of the quote.

You must not have finished reading. He originated the version that says "regular expressions", but not the "two problems" part or the sentiment about textmatching: >As cute as the “now you have two problems” quote is, it seems that Jamie wasn't the first to come up with the idea. The same quote (but with AWK rather than regular expressions as the punch line) shows up in the sig of John Myers post from 1988, where he…

But, to be fair, that's not the same quote. jwz was paraphrasing Tilbrook on awk, but the new utterance about regular expressions was his own.

Re: How I fixed a bug in Atom

#169
post #110

In general, when you are working on a problem and you think "let me use a regex for that" and then you come up with ^\s*[^\s()}]+(? [^()]*\((?:\g |[^()]*)\)[^()]*)*[^()]*\)[,]?$ to solve your problem, then you have IMHO come across a problem which you should not be solving using regular expressions. Case in point is counting and balancing parentheses which is very easily done using a single loop over the string in qu…

The worst part is that as soon as he mentioned regular expressions I knew exactly what the problem was. Regexes are powerful and useful but also dangerous. People who don't thoroughly understand them and try to get fancy often run into problems like this. In general you shouldn't be using them to parse a computer language anyway, it is something you should be using a tokenizer/parser for.

If something can be done with regex, someone will do it with regex, and it will end up in a big project.

That’s why I weeped when support for named groups and backmatching was added.

Re: How I fixed a bug in Atom

#170
post #75

Earlier quoted context omitted.

Actually, this is false. A lot of regex implementations use a backtracking approach in all cases, causing pathological behavior even on regexes which match a regular language (and so should never take any significant amount of time to process). See https://swtch.com/~rsc/regexp/regexp1.html , which gives a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (see the backtracking?…

You are right. The support of fancy features like backtracking should not cause any degradation of performance for simple regular expressions. You are not obliged to use them, but they should not hurt you when you do not use them. I am surprised this issue is not fixed in perl.

EDIT: Actually, nevermind. Does not matter in the grand scheme of things.
Post reply on HN