

RegExpBuilder: because regular expressions suck - BobTurbo
https://github.com/thebinarysearchtree/RegExpBuilder

======
gregjor
[The response from BobTurbo that I replied to below disappeared while I was
writing this. In his comment he assumed that I must want every programming
language to use symbols instead of methods and functions.]

You can assume whatever you want but that won't make for a productive
conversation. I didn't say anything about "entire programming language
syntax," I was talking about regular expressions. In other contexts -- jQuery
is a good example -- techniques like yours actually help because they improve
over the alternative. In the case of regular expressions I'm not persuaded.
I'll give a few reasons.

1\. Hundreds of thousands of programmers have learned and used regexes since
the 1960s. regexes have been implemented in too many languages, libraries and
tools to count. That didn't happen because they "suck" but no one has been
smart enough to improve on them until now. That happened because they are an
efficient, succinct, well-understood and tested way to do the job.

2\. Programmers can find lots of good documentation on regexes, there are many
good tools for building and testing them, and they are built-in to the syntax
of quite a few languages (including Javascript and Perl). If I come across a
regex in code I'm working on I know where to go to figure it out and test it.
If I come across your code I will have to learn something new and wonder if it
does what I think it's doing.

3\. I can't copy/paste your code into a regex validator or tester. I can't use
the same regex in Javascript and PHP unless/until you have a PHP version (for
example).

4\. Regular expression syntax is part of the IEEE POSIX standard, although
there are quite a few variations and implementations.

5\. I'm much more likely to trust the correctness of regex libraries that have
been around and in use for 20 years or more than an add-on library I found on
github.

6\. To build a non-trivial regex with your library I still need a fairly good
understanding of the things that catch people up: backtracking, grouping,
subexpressions, etc. The same problem comes up with the various attempts to
simplify SQL or hide it behind an ORM -- by hiding complexity you add a layer
of difficulty to understanding and debugging that wouldn't be there if you
just mastered the hard sucky thing in the first place.

7\. Regexes are taught (or should be taught) to illustrate finite state
machines and regular grammars. Learning how regexes work is rewarding
independent of specific implementations in programming languages.

8\. As I already mentioned I am 99.999% more likely to come across a regular
expression in it's usual form (the one that sucks) than in the form you've
adopted. That may be in Java, Python, or Javascript code, a text editor, an
AWK script, or an Apache config file. I have no incentive for learning another
syntax for regular expressions since it is not going to replace the widely-
used syntax.

There's a little irony here: you must have learned regular expressions at a
fairly deep level to write your library, so you probably don't need it for
your own projects.

No personal offense intended. You post on Hacker News, people are going to add
their opinions. You can agree or not. Good luck with your library.

------
gregjor
Dismissing a mature and widely-used tool by saying "it sucks" doesn't inspire
me to read more, but I did. Personally I think it's easier to learn, read and
maintain /\$[0-9]+\\.[0-9][0-9]/ rather than a bunch of new
Dart/Javascript/Python/Java methods. It's certainly more efficient. But I've
been using regexes since before any of those languages were invented.

You're going to encounter regexes in other contexts -- text editors,
Unix/Linux utilities, databases, code you didn't write -- and if you can only
use them with training wheels you're stuck.

------
tudborg
It doesn't seem to simplify regex, just make it more verbose. That might be
fine, except the people who need to understand how to use it, must already
understand the concepts of regexes.

And if you can use this library without understanding regex, you might be
better of not using regex at all.

Regex looks complex at first glance, but with a good cheatsheet and tool you
should have no problem.

[http://gskinner.com/RegExr/](http://gskinner.com/RegExr/) is a great tool for
building and testing regexes.

