3 ms·
Re "compatibility", I was thinking more about the language's library ecosystem, that could benefit from a single official regex implementation that can be relie
by benniw 12y ago
Re "compatibility", I was thinking more about the language's library ecosystem, that could benefit from a single official regex implementation that can be relied upon and can be assumed to be known by programmers (when designing library APIs, for instance).
But I actually forgot to mention the biggest benefit of having dedicated regex literals (rather than just passing them as strings to some constructor at run-time):
They will be treated as part of the language, and can be parsed and compiled together with the rest of the code (a.k.a. at compile-time).
Which means:
1) Better performance
2) Syntax errors in regexes are compile-time errors, which is a huge help in keeping bugs out
3) Editors will show you syntax highlighting inside of regexes
It's hard to overstate the benefit of those three consequences; Once you've worked with a language that supports such compile-time regex literals (e.g. Perl) you don't want to go back to using regexes in a language that treats them as strings (e.g. Python).
Regexes are code, and defining code in strings to be eval'ed at run-time is just plain wrong.