5 ms·
that code stinks on many levels. matching test in a string with a regex is so far away from being part of a good solution to this problem on any level imo... i
by jheriko 11y ago
that code stinks on many levels.
matching test in a string with a regex is so far away from being part of a good solution to this problem on any level imo... its a recipe for pain. i'm sorry anyone has to work in that codebase.
- eridius 11y agoYou're taking regex hate way too far. This is actually pretty much an ideal use-case for regular expressions. The correct regular expression looks like /\b[Tt]est/, which is trivial to write by anyone who has a passing familiarity by regex, easy to read, and will do exactly what it's trying to do.
- jheriko 11y agoits nothing to do with the regex. its the algorithm and its suitability 'any function containing test in its name' being a test is a stinky practice. using something well defined is what i would expect from any programmer at any level. this is what we call a 'hack'... and its a particularly revolting one.
- eridius 11y agoI'm going to go out on a wild limb here and guess that you have no clue whatsoever what a regex is, because your comment makes absolutely no sense. The original regex from the article is wildly broken, yes. But the trival regex /\b[Tt]est/ does not match "any function containing test in its name". And this regex is extremely well-defined. The fact that you can't understand it, and the fact that you are making no effort whatsoever to learn even the most basic stuff about regexes, does not make this a 'hack', it just makes you one.
- jheriko 11y agonope. use them every day, but not as a pro expert because its rarely necessary. i don't know what \b is off the top of my head but i'd guess at word boundary so its only checking for functions starting with test, which is equally bad... matching strings contents of function names is not a good way to work. using well defined constructs is. thank you for the hate though.