3 ms·
It's kind of a cool feature. I like it.
by phoronixrly 1y ago
It's kind of a cool feature. I like it.
- thayne 1y agoIs it? I can't think of a non-contrived case where this would actually be useful. And in any case where it would be useful, it seems like a better way to optimize would just be to refactor the regex out into a constant.
- kayodelycaon 1y agoActually, I have a way this would work well. If you’re interpolating a value that comes from configuration and wouldn’t change. Example: /admin@#{Rails.config.x.domain}/io But you’re right that a constant would be a lot more clear. “o” is a footgun.
- naniwaduni 1y agoThe context is that this is a feature cribbed straight from perl, where where it's passed down from perl 4/pre-5.6, where compiled regexen weren't first-class values. Pretty much every use of it this century is a mistake.
- baobun 1y agoAn HTTP application server matching routes based on runtime configiuration (domains and whatnot) is not really that niche or contrived? Loads of other situations where input not changing during the thread/process lifecycle is part of a set of hot regexes large enough that explicitly compiling each is not a great experience. I, for one, appreciate /o.