Earlier quoted context omitted.
Yea, anytime I use a regex that isn't immediately obvious I put it in a function called get_ . Unfortunately people that write overly complicated and error prone regexes usually don't choose to document them.
If a regex is going to be reusable, then yeah, I'd agree. But dumping single lines of code into their own functions just for readability isn't practical for real time systems. In those cases you really should be using comments as they get stripped out by the compiler.
My favorite regex of all time
101–110 of 117 posts
Re: My favorite regex of all time
#102Earlier quoted context omitted.
If a regex is going to be reusable, then yeah, I'd agree. But dumping single lines of code into their own functions just for readability isn't practical for real time systems. In those cases you really should be using comments as they get stripped out by the compiler.
Couldn't those functions just be inlined by the compiler if they're simple regex-wrappers anyway? I do agree that it might be overkill to move regexes to their own functions just for readability's sake but I don't buy the performance argument. Furthermore, regexes are most popular in scripting languages that no sane person would use for real time performance-critical systems anyway.
2. Web sites are a classic example of scripting languages being used for real time performance critical systems (though I'm not arguing that all web sites are real time).
Sometimes the ability to modify code easily is as important to the choice of languages as the raw execution speed of the compiled binaries.
Re: My favorite regex of all time
#103My favourite is this one: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html
Re: My favorite regex of all time
#104Re: My favorite regex of all time
#105Earlier quoted context omitted.
I'm not sure who the PHB is, but I'm certainly not impressed by anything cryptic in a codebase. Deliberately writing code that's hard to understand should be a firing offense.
PHB: Pointy Haired Boss
Re: My favorite regex of all time
#106Earlier quoted context omitted.
Search "[ -~]" (with or without quotes) to see how good Google's comment is.
The only ambiguous thing about this regex is knowing what's between space and tilde. Otherwise this is a pretty ordinary regex.
So I read the snippet, thought 'Yeah, a character class of space, -, ~' and fell on my face in the next couple of lines.
Yeah, I should've known better, I know how to read it. If .. I invest the time and don't glance over a construct and hope to just get it instantly.
I wouldn't want to see this in a code base without proper documentation (be it a comment, a function name or whatever. Something).
Re: My favorite regex of all time
#107Earlier quoted context omitted.
Yea, anytime I use a regex that isn't immediately obvious I put it in a function called get_ . Unfortunately people that write overly complicated and error prone regexes usually don't choose to document them.
If a regex is going to be reusable, then yeah, I'd agree. But dumping single lines of code into their own functions just for readability isn't practical for real time systems. In those cases you really should be using comments as they get stripped out by the compiler.
If you're using a regex, and certainly if you're using a language other than C, you probably have space for the function call overhead.
Re: My favorite regex of all time
#108Earlier quoted context omitted.
Couldn't those functions just be inlined by the compiler if they're simple regex-wrappers anyway? I do agree that it might be overkill to move regexes to their own functions just for readability's sake but I don't buy the performance argument. Furthermore, regexes are most popular in scripting languages that no sane person would use for real time performance-critical systems anyway.
1. Ahh right. I wasn't aware that happened. 2. Web sites are a classic example of scripting languages being used for real time performance critical systems (though I'm not arguing that all web sites are real time). Sometimes the ability to modify code easily is as important to the choice of languages as the raw execution speed of the compiled binaries.
Re: My favorite regex of all time
#109Earlier quoted context omitted.
Thank you for that. You have no idea how annoying it is to port perl scripts from ASCII to EBCDIC when they do that kind of thing.
It's not an ASCII v EBCDIC thing, its an ASCII vs Unicode thing.
Re: My favorite regex of all time
#110Earlier quoted context omitted.
> Who's filenames aren't unicode? Many filesystems don't support unicode or support only a subset of it: https://en.wikipedia.org/wiki/Filename#Comparison_of_filenam... > Also domains and URLs can be unicode too. Domains: it depends at which level you are dealing with them. See https://en.wikipedia.org/wiki/Internationalized_domain_name Internationalized domain names are stored in the Domain Name System as ASCII stri…
http://www.ebækur.is