7 ms·
> Regex is fine Hrm, I don't think regex is fine. It's well established yes. It's dense, concise and minimalist, yes. It is somewhat powerful, yes But ther
by ur-whale 4y ago
> Regex is fine
Hrm, I don't think regex is fine.
It's well established yes.
It's dense, concise and minimalist, yes.
It is somewhat powerful, yes
But there's a lot of places where it comes short:
1. Very steep learning curve for beginners, especially if they have to read a regex they didn't write themselves
2. Write-only language, just like APL: dense and concise, but a giant PITA to read once you've walked away from a complex regex for a couple of days.
3. Not standardized (sed regex vs. sed extended regex vs. perl regex vs. vim regex vs. bash regex vs. globbing vs. whatever else, it's never the same, what a giant effing PITA)
4. No proper integrated debugger (there might be some 3rd party out there, but it's never around when you need it, as in: integrated in whichever environment you are currently doing regexes in). When your large and complex regex fails good effing luck trying to figure you why, short of breaking it down in tiny pieces and debugging each in turn recursively. You don't even have access to a bloody printf.
5. Boolean trees of regexes (match blah OR blech AND NOT blargh, where blah, blech and blargh are themselves boolean trees of regexes) are a giant PITA to express within the language.
6. Overlap and confusion between capture '()' and factoring out an expression to plug into a dyadic OR.
7. No way to factor out common and/or repeating parts, like you would in a normal programming language.
So any attempt at improving this mess is welcome in my book.
- bmn__ 4y ago> So any attempt at improving this mess is welcome in my book. Already done, I think. :) 2. Not a big problem if the responsible programmer employs named captures and named subpatterns, and switches on extended mode and makes use of whitespace and comments. Like with any other programming environments, it's a matter of wanting to write readable code, and perhaps enforcing this through technical and social means. 3. I observe that Perl-style regex have become the de facto standard, in the sense that numerous programming languages in common use have adopted it, and preceding styles are marginalised to the point that any discussion about regex that does not mention the style makes the assumption of Perl-style. The next points are actually implementation dependent. It is not fair to condemn regex as a whole just because some implementations fall short. 4. Perl has good debugging tools for regex. 5. This is easy to express in Perl. 6. Non-capturing grouping exists. 7. Named subpatterns exist, interpolation of variables containing regex values exists.
- oblio 4y agoPerl is a dying language. Your 4-5 "solutions" are non-solutions in practice for 99% of software developers out there. And regexps are by default written in the concise form. It's the standard problem of "opt-in" vs "opt-out". Opt-in, as a rule of thumb, has low adoption rates, for various reasons (maybe 20% if you get lucky). Opt-out is the inverse, it has adoption rates of 90%+, except for total, universally known disasters. Tools which are unsafe by default are bad. Yes, the craftsmen are bad, but the way we improve is by also improving our tools. It doesn't matter how much pointing at the idiots we do, practical regexps have been around since ~1975, that's almost 50 years. In industrial use they haven't gotten safer. That's bad.