3 ms·
To your last point about regexes: I think the general idea is to discourage their use, at least as a default. It is so easy to use them in Perl that they are us
by thirsteh 13y ago
To your last point about regexes: I think the general idea is to discourage their use, at least as a default. It is so easy to use them in Perl that they are used way too much, e.g. when you could do a regular (and faster) string search.
- DougWebb 13y agoThat's a lousy reason to not include them. Cars are used to much and people really should walk and bike and take the bus more, but we're not about to make cars more difficult to use because of that. Perl's embedding of regexes into the language syntax is a fantastic feature, as is the way captured groups can be assigned to a list. No other language comes close to making regexes usable. Javascript, which at least has a literal syntax for regex, is still awkward. And the other language I use the most, C#, has such a bad interface for getting captures that I get it wrong and have to look up the documentation EVERY SINGLE TIME I USE IT. I would compare regex as an add-on library in most languages to be as awkward as OOP as an add-on to Perl 5 was. At least Perl has corrected that; besides Javascript, have any other languages taken steps to make regexes easier to use?
- pyre 13y ago> At least Perl has corrected that Perl hasn't really corrected that. Moose is an external library (with downsides, such as load-time last I checked). When it becomes part of the core Perl language, I'll consider Perl to have corrected it.
- Renaud 13y agoBut isn't that a crime of premature optimisation? Perl's integration of Regex makes them easy to use and they fit naturally in the language, a lot more than in most implementations. Being able to use Regex easily is a plus in my book. Yes they are lower than some dedicated string search or some state machine ad-hoc implementation, but you can document Regexes and they pack a lot of punch. If a Regex is causing a concern in term of performance, then it may be time to review that code and optimise it, otherwise why even bother? When people talk about Regex being bad and they say you can often use string manipulation instead they only talk about the most trivial uses of Regex. As soon as you go beyond that, using a Regex is almost always going to be cleaner than spewing lines of codes and building state machines to achieve the same functionality.
- maxerickson 13y agoIt's more a matter of different design taste than it is an optimization. (I don't think it is controversial that Python has a relatively simple language definition/grammar/etc; regex as language syntax would expand all of that quite a bit)
- pyre 13y agoIIRC, they were not included because Guido's opinion is that Regex should be a library, not a core feature of a language.