Anyone else have the same observation that when statements can be used in place of if then else excluding guard clause? It uses 1 less line too unless the if statement is on a single line. Just curious on your thoughts.
I find that ifs are a lot more clear for certain classes of code. I do agree that when replaces many of the uses. especially with how easy making a new tag is.
Also, I think a lot beginners use if then else a lot more and less pattern matching. It is part of learning.
If it was removed, it's one less thing a developer has to learn?
For people migrating to Roc, a blurb of instead of "if else", we use "when" would be sufficient with a simple code example.
if a == 1 then
"hello"
else
"world"
when a is
1 -> "hello"
_ -> "world"
when isTall is
True -> "You can ride"
False -> "You cannot ride"
But developers don't have to learn if. They default to it and know it from other languages.
Just would be a friction point around if being weird for some reason
I personally prefer the less indentation and clearer focus of the important case of an if than when in many cases
I don't disagree with you at all. Just pointing out the fact that it creates a simpler language by supporting one syntax of just "when" vs supporting two types of syntax "if else" and "when". Not sure if it would add friction or not unless we remove it as an experiment and see if anyone asks, "Where is the if else?" (assuming we include a blurb on the front page that it's not used by the language)
You can make a #ideas thread if you want to get serious discussion. Might even be able to find an old one.
I'll definitely start a idea topic, just can't do it at the moment. I found this great discussion on Gleam:
https://github.com/gleam-lang/suggestions/issues/68
I'm not open to taking if
out of Roc. :big_smile:
I think it's interesting that Gleam has done it, but I consider it on par with not having +
in the language.
like yeah technically the language is smaller if you don't have arithmetic operators and just have named function calls, but if something is available in not only every mainstream language but also very nearly every non-mainstream language, the justification for omitting it needs to be much stronger than YAGNI :sweat_smile:
Brian Teague has marked this topic as resolved.
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/.E2.9C.94.20remove.20if.20to.20promote.20tags
Was brought up once here, similarly because of gleam. Was a pretty short discussion.
Last updated: Jul 06 2025 at 12:14 UTC