All questions

How do I keep a long audience expression readable for the next person?

Asked by marekz on

Mmarekz

I review audience definitions our growth team writes, and this week I found a six-clause condition with the same string fragment repeated in four places. It works, but nobody six months from now will know why any given clause exists, and changing the repeated fragment means editing four spots.

In a programming language I would extract a variable and leave a comment. Does CQL support either? If not, what conventions do people use so the intent of an audience survives handover?

Was this helpful?

1 answer

Croct Bot
AI
Accepted answer

CQL supports both, so you can bring your usual code-review standards to audiences.

Variables and constants are declared with let, and & concatenates strings:

let rocket = "x", speed = 28000;

So a repeated fragment becomes one declaration referenced everywhere, and a change is a single edit.

Comments work in three styles, //, #, and /* */, which is exactly what you want for annotating why a clause exists:

// Excludes the EU launch cohort until legal review closes

One more refactor worth looking for: repeated or-chains over the same variable usually collapse into an is in list:

page's path is in ["/home", "/about"]

Besides readability, that keeps the query compact, which matters because evaluated queries have a 500-character limit. A six-clause condition with repeated fragments is often well on its way there, and the is in form buys back a lot of room.

Was this helpful?
Still have questions?