Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Code Smell 41 — Regular Expression Abusers

Maximiliano Contieri
Dev Genius
Published in
2 min readDec 3, 2020

Photo by John Jennings on Unsplash

Problems

  • Readability
  • Maintainability
  • Testability
  • Intention Revealing

Solutions

  1. Use regular expression just for string validation.
  2. If you need to manipulate objects, don’t make them strings.

Sample Code

Wrong

Right

Detection

Regular expressions are a valid tool. There’s not much automated way of checking for possible abusers. A whitelist might be of help.

Tags

  • Primitive Obsession
  • Abusers

Conclusion

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.

Relations

More info

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Maximiliano Contieri

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com

No responses yet

Write a response