3 ms·
The hate is when they are used for code where a parser would be better. (e.g. parse an e-mail address). I don't think anybody has an issue with regex search i
by aidenn0 11y ago
The hate is when they are used for code where a parser would be better. (e.g. parse an e-mail address).
I don't think anybody has an issue with regex search in an editor, but we are more talking about regex as a core language feature.
Even in an IDE there are times that regex is the wrong solution. e.g. regex based refactoring can introduce bugs in most languages where a parser based refactoring wouldn't.
- moron4hire 11y agoSounds like throwing the baby out with the bathwater.
- aidenn0 11y agoCan you please let me know what the "baby" is in this case? Nobody is seriously against regexes for all cases (all developer editors have a regex search, for example). However, they aren't even always the clearest way to parse regular languages (depending on the language, automata can be more clear than regexes or vice versa). Perl regexes can parse many context free languages, but again it's not always the clearest way to represent it. Despite the original quote, I use awk as a standard part of my toolbox. I'm not going to write a web-browser in it though. Nearly every time someone says "now you have 2 problems" or "considered harmful" it's a reaction to overuse or misuse, not a literal call to abandon it altogether.
- moron4hire 11y ago> not a literal call to abandon it altogether. No, that's literally every case I've seen for the use of the "now you have two problems" phrase. It's like someone has a bot on the lookout, alerting them to mentions of regexp so they can run in and say "now you have two problems!" I think it's another symptom of the common trend of modern programmers not wanting to do any programming anymore. Breath mention that you might want to implement your own text editor control because you haven't been able to find one that suits your needs and immediately get jumped no with "don't reinvent the wheel!" Spend a small amount of your spare time toying around with toy programming languages and it's, "you have too much time on your hands!"--as if being massively overworked on business interests is some kind of virtue. Make a puzzle game without using Unity or some other overblown framework on your small project and it's "you're nuts!" No, literally, I got called insane once for not using Angular on my personal website that mostly just amounts to a list of links to my social media profiles.
- Retra 11y agoI think it's a far more offensive grievance to write something like an e-mail address spec that isn't able to be parsed by regular expressions. A problem that I'm sure is compounded by some people's lack of experience using them.
- kbenson 11y agoA regex is really just a highly compact and powerful parser domain specific language and engine. People often don't understand the DSL adequately and it's use can become problematic, but properly applied it can dramatically ease certain tasks. That said, all you really need to know is that it boils down to the exact same underlying issues that cause people to like/dislike any language over another. It's exposure and preference. People prefer verbosity/conciseness/terseness, structure/versatility, speed/ease of coding, and the things other than what they prefer are obviously wrong.
- lisivka 11y agoGrammars are invented in Perl6 just for that. Perl5 has module[0] for that implemented using recursive regex's. Example of LaTeX parser: use Regexp::Grammars; $parser = qr{ <File> <rule: File> <[Element]>* <rule: Element> <Command> | <Literal> <rule: Command> \\ <Literal> <Options>? <Args>? <rule: Options> \[ <[Option]>+ % (,) \] <rule: Args> \{ <[Element]>* \} <rule: Option> [^][\$&%#_{}~^\s,]+ <rule: Literal> [^][\$&%#_{}~^\s]+ }xms [0] http://search.cpan.org/~dconway/Regexp-Grammars-1.041/lib/Regexp/Grammars.pm http://search.cpan.org/~dconway/Regexp-Grammars-1.041/lib/Re...