3 ms·
But regular expressions are not neat tricks, they're basic features of Perl, and are immediately understandable once you've learned about them.
by jpd 18y ago
But regular expressions are not neat tricks, they're basic features of Perl, and are immediately understandable once you've learned about them.
- dood 18y agoAre you suggesting that a cryptic regex is as easy to read as [:] or [::-1]? If you know python, that syntax is clear at a glance, dense regular expressions are not comparable. Basic language features don't need comments, difficult to read lines do.
- thwarted 18y agoAnd that depends on if regular expressions are a basic language feature. The proper way to "explain" or "comment" a complex regular expression is not to include a single line comment near it, but to use the /x modifier that allows you to "extend your pattern’s legibility by permitting whitespace and comments". That is, of course, assuming you're using a language where regular expressions are first class types and has syntax to support regular expressions as literals (if you have to include your regular expression in a quoted string, your language doesn't), and uses PCRE.
- kaens 18y agoExactly - 90% of the regular expressions you (or at least I) use in Perl are going to be fairly simple. They'll look like cryptic nonsense to someone who is not familiar with regexes, but be immediately obvious to someone who uses them often, and obvious with 40 seconds of looking at documentation to someone who is just familiar with them. Regexes shouldn't, IMO, be removed or avoided in Perl - they're a crucial part of the language, and one of the reasons Perl is so good for what it's good for. Same goes for slices in python. Just like how if you're using Perl, you need to become familiar with regular expressions, if you're using python, you need to become familiar with slicing, because it's a crucial part of the language, and you'll probably be writing a lot of "un-pythonic" code in python without them, as well as being utterly unable to read someones code who is familiar with them. As far as palish's point about explicit and implicit listb = lista[:] is explicit, once you're familiar with the basic features of python, assuming you consider slicing a "basic feature" - I certainly do.