Trivial question about Some(data) naming convention

This seems like a pretty common situation:

switch user {
| Some(x) => Js.log(x)
| None => Js.log(None)
}

What is best practice for naming “x” inside Some?

Just shadow user?

switch user {
| Some(user) => Js.log(user)
| None => Js.log(None)
}

Modify user with something like “user_” (which I think I saw someplace, rust maybe?),

switch user {
| Some(user_) => Js.log(user_)
| None => Js.log(None)
}

Or just something simple like “u” if the scope is very small?

switch user {
| Some(u) => Js.log(u)
| None => Js.log(None)
}
1 Like

At Carla we use the convention to prefix optional variables with maybe. It improves the code readability as well as solves the problem with shadowing.

switch maybeUser {
| Some(user) => Js.log(user)
| None => Js.log(None)
}
7 Likes

Do you have anything like that for promises?

Yes, we append Promise to the variable name :relaxed:

1 Like