Remix.run Logo
Joker_vD 8 days ago

> I didn’t recognize /o. It didn’t seem critically important to lookup yet.

> With nothing else to investigate, I finally looked up the docs for what the /o regex modifier does.

I'll probably never understand this mode of thinkning. But then again, Ruby programmers are, after all, people who chose to write Ruby.

> /o is referred to as “Interpolation mode”, which sounded pretty harmless.

Really? Those words sound quite alarming to me, due to personal reminiscences of eval.

Also, this whole "/o" feaure seems insane. If I have an interpolation in my regex, obviously I have to re-interpolate it every time a new value is submitted, or I'd hit this very bug. And if the value is expected to the same every time, then I can just compile it once and save the result myself, right? In which case, I probably could even do without interpolation in the first place.

gpvos 7 days ago | parent | next [-]

It's a feature dating from the 1990s, when Perl (and I guess Ruby?) didn't have a way for the user to store a compiled regex, and this was a useful shortcut for a very specific optimization, which Ruby documented badly. Perl (and I guess Ruby?) later evolved in a way that made /o unnecessary, but the (now mis)feature remained.

apgwoz 8 days ago | parent | prev [-]

“Compilation”, I think, is exactly right. This feature is less about interpolation than it is about compilation of a single regexp to be used many times. It’s just shrouded in confusing documentation that should say: “/o tells ruby to rewrite this code such that it refers to a new statically allocated regexp object.” And when you write it that way, you see how insane it is for a function call to be hoisted automatically like this, without an explicit, obvious, syntactic annotation.

gpvos 7 days ago | parent [-]

The implications of "statically allocated" are less clear than if you'd just write "compiled only once".