Mnemonics to differentiate "cond" and "case"

Maybe this is something intuitive for a native English speaker, but I am not one and I have a hard time remembering when to use which.

Both start with c and both are 4 letters long, so that doesn’t help.

Do you have some mnemonic tools to remember and differentiate between them?

1 Like

Good idea, I didn’t have any, but here’s some possibilities (found with the help of claude.ai):

  • “caSe” where S could stand for “Same” value - because case always examines the same value against several patterns.
  • Think of “conD” where D stands for “Different” statements - because cond checks different, unrelated conditions.

Or:

  • CASE = Comparing A Single Expression
  • COND = “Compare ONWARD” (as in, keep going until you find a match)
7 Likes

I like your second options.

Cond is short for condition / conditional. So you’re going “which condition is true?”

With case you’re pattern matching, so the question is closer to “in case I have this, do that”

3 Likes

imo, like the keyword unless, just forget that it exists. Unless you have an exact need for an if else if, find a way to rewrite cond using case or with.