3 ms·
This is a footgun. A language should strive not to add footguns. Every footgun you provide, somebody is going to blow their foot off with it, so that's a high p
by tialaramex 1y ago
This is a footgun. A language should strive not to add footguns. Every footgun you provide, somebody is going to blow their foot off with it, so that's a high price. If your language is popular it might be a lot of somebodies.
The opposite behaviour (we have a constant regular expression, we re-use it often but the tooling doesn't realise and so it's created each time we mention it) is not a footgun, it results in poor performance, and so you might want (especially in some managed languages) to just magically optimise this case, but if not you won't cause mysterious bugs. An expert, asked "Why is this slow?" can just fix it - you have to supply basic tools for that, but this flag is not a sensible tool.
- elif 1y agoIs it really though? There are tons of characters you can add to a regex that have difficult if not impossible to mentally comprehend impacts on the potential matches. That's why you need 100 test cases for every 10 characters you write in a regex. Regex itself could all be a footgun by this standard. No one in the history of no one has ever thought "why dont I just add a random character to my regex I don't need or understand" that's just boogie man level irrational fear if you think this has any bearing on the ease of use of ruby.
- pitched 1y agoRuby is a well-sharpened knife. Not everyone should be given a sharp knife though, especially children. And not all jobs need a sharp knife, like buttering toast. So I think it’s good for dull knives to exist as part of your tool belt. If we can only choose one language though, I’d rather it be a nimble, sharp one.
- stouset 1y agoRegexes are not fundamentally hard. People make regexes hard by trying to parse things by sight rather than finding a spec. If you have a spec, and it can be parsed by a regular expression, they are pretty damn rote to implement. If you aren’t working from a specified input grammar, the task is going to be borderline impossible no matter the tool and you’re going to have a bad time. If you aren’t working with a regular grammar, this is the wrong tool for the job and again you’re going to have a bad time. A hint; if you find yourself using `.`, you are probably shooting yourself in the foot.
- alexpotato 1y agoAbout 10 years ago I had to write a script to reconcile trade entries from various brokers back into our central system. You are 100% correct on the "100 to 10" ratio on test cases. PLUS, the ways in which broker files can break due to: - random carriage returns - different date formats - time zones - etc etc and regexes become both great and terrifying at the same time. One pattern I did find useful: regex + if/then e.g. if (regex is true) then if (regex2 is true) then
- emmelaich 1y agoSometimes you want to blow your foot off.
- roughly 1y agoOne of my favorites was Python’s datetime.time() object evaluating to True for every value except exact midnight, which is the sort of thing that makes fine sense when you think about the underlying implementation but is absolutely going to take a toe off of someone. My favorite part about that one was it got to go through the full feature deprecation cycle before removal because several people argued in the bug thread about it that they were relying on that behavior in their systems.
- gpvos 1y agoIn the 1990s, with the processing power of the time, /o was a reasonable compromise. The language later evolved to do the smart thing you describe, but you can't just remove features. A warning would be in order though.