4 ms·
These sorts of screeds against regexes always strike me as very strange: regexes can be written in the terse, difficult to read manner that the author demonstra
by nimih 4y ago
These sorts of screeds against regexes always strike me as very strange: regexes can be written in the terse, difficult to read manner that the author demonstrates, but they can also be written with inlined comments, named capture groups, and plenty of whitespace, so that they're actually readable by normal humans. The former is useful for when you are sitting at a terminal and need to sift through gigabytes of log files in an ad-hoc manner while debugging an issue, the latter when you want to commit something to a codebase. Confusing these two use-cases, and then writing a few hundred words of inflammatory flamebait about it, seems unfair to what are otherwise an extremely powerful and versatile tool on the one hand, and a relatively unobjectionable[1] way to write software on the other.
[1] I think that sticking even moderately complicated regexes in a modern codebase is probably not a great plan most of the time (lots of modern languages have easier-to-use options for accomplishing complex parsing tasks!), but given that regex libraries typically ship as part of the standard library and are extraordinarily well documented as a language, they're not a bad tool to reach for in a lot of cases.
- gonzo41 4y agoAnd usually where you have a complex regex, you can extract it into a stateless util method and then unit test the hell out of it. Which is pretty useful to aid in understanding.
- rmason 4y agoI've always struggled writing regexes. It's somehow counter intuitive for me. Luckily I have friends who just adore writing them and will help me when I get stuck. Thought I had a killer idea of creating a regex generator using AI. Well someone beat me to it. https://www.autoregex.xyz/ https://www.autoregex.xyz/ I have also heard of another one as well. I suspect it will be quite a popular project for awhile. I wouldn't care if I never had to write another regex again.