Code Smell 41 — Regular Expression Abusers
RegEx are a wonderful tool, we should to use them carefully and not to look smart.
- Intention Revealing
- Use regular expression just for string validation.
- If you need to manipulate objects, don’t make them strings.
Regular expressions are a valid tool. There’s not much automated way of checking for possible abusers. A whitelist might be of help.
- Primitive Obsession
Regular expressions are a great tool for string validation. We must use them in a declarative way and just for strings.
Names are very important to understand pattern meanings.
If we need to manipulate objects or hierarchies, we should do it in an object way.
Unless we have a conclusive benchmark of impressive performance improvement.
Code Smell 06 — Too Clever Programmer
Code difficult to read. Tricky with names without semantic. Sometimes using language’s accidental complexity.
Code Smell 20 — Premature Optimization
Planning ahead of time needs a crystal ball no developer has.
A Perl program is correct if it gets the job done before your boss fires you.
This article is part of the CodeSmell Series.