Synopsis: Jaywalking

Let's see how using a comma-separated list causes an antipattern.

Let’s imagine that you are developing a feature in a bug-tracking application to designate a user as the primary contact for a product. You originally allow only one user to be the contact for each product. Unsurprisingly, however, you are soon requested to support assigning multiple users as contacts for a given product.

At the time, it seems simple enough to change the database to store a list of user account identifiers separated by commas in place of the single identifier that you used before.

Soon, your boss approaches you with a problem: “The engineering department has been adding associate staff to their projects. They tell me they can add five people only. If they try to add more, they get an error. What’s going on?” You nod and say, “Yeah, you can only list so many people on a project,” as though this is completely ordinary.

However, sensing that your boss needs a more precise explanation, you quickly add “Well, five to ten—maybe a few more. It depends on how old each person’s account is.” But your boss begins to raise their eyebrows now and you realize that you can’t simply toss the matter aside, so you continue, “I store the account IDs for a project in a comma-separated list. But the list of IDs has to fit in a string with a maximum length. If the account IDs are short, I can fit more into the list. So, people who created the earlier accounts have an ID of 99 or less, and those are shorter than later IDs, which go past 99.” Your boss frowns. You have a feeling you’re going to be staying late.

Programmers commonly use comma-separated lists to avoid creating an intersection table for a many-to-many relationship. This antipattern is often named Jaywalking, the name given to the act of avoiding an intersection.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy