3 ms·
I think people dislike [Regex] for the some of the same reasons The Principle or Least Power makes sense. If you can do the same manipulation in three ones of
by hinkley 9y ago
I think people dislike [Regex] for the some of the same reasons The Principle or Least Power makes sense.
If you can do the same manipulation in three ones of code it’s more likely to be correct and stay correct. And when you look at it again in six months you won’t have to stare at it. All those little time sucks add up as the code grows.
Edit: autocorrect got me twice.
- ogdoad 9y agoActually thrice: lines -> ones.
- GordonS 9y agoI'd say (as I often do), 'it depends'. Firsly, for relatively simple regex expressions, any competent developer should be able to grok them very quickly - at least as quick as the equivelant C#/Java/whatever code. Secondly, it may be that regex is the most performant solution, and sometimes that matters quite a bit. Honestly, I just don't get why some people are intimidated by regex.
- laumars 9y agoRegex is seldom the most performant code. I mean the engine themselves are fantastic pieces of engineering but in tight loops I've found I can get - sometimes significant - performance improvements by replacing regex matches or substitutions with purpose written string manipulation. Obviously the results depend massively on several big variables: 1/ the regex engine 2/ host language 3/ problem you're trying to solve But I've found generally I was better off not using regex for performance critical code. HOWEVER (!!!) where regex consistently wins is development time. Not just writing the code, but testing (it's trivially easy to test regex) and updating the pattern matching (Vs updating the equipment character matching in an imperative language). Yeah regex can get ugly quickly, but then so can any language if misused.