Kinsua
November 6, 2024, 10:27pm
1
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
mayel
November 6, 2024, 10:36pm
2
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 = C omparing A S ingle E xpression
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
budgie
November 7, 2024, 1:13am
4
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.