Stream: beginners

Topic: ✔ Remove If Then Else?


view this post on Zulip Brian Teague (Feb 15 2025 at 19:11):

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.

view this post on Zulip Brendan Hansknecht (Feb 15 2025 at 21:20):

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.

view this post on Zulip Brendan Hansknecht (Feb 15 2025 at 21:21):

Also, I think a lot beginners use if then else a lot more and less pattern matching. It is part of learning.

view this post on Zulip Brian Teague (Feb 15 2025 at 21:26):

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"

view this post on Zulip Brendan Hansknecht (Feb 15 2025 at 21:27):

But developers don't have to learn if. They default to it and know it from other languages.

view this post on Zulip Brendan Hansknecht (Feb 15 2025 at 21:28):

Just would be a friction point around if being weird for some reason

view this post on Zulip Brendan Hansknecht (Feb 15 2025 at 21:28):

I personally prefer the less indentation and clearer focus of the important case of an if than when in many cases

view this post on Zulip Brian Teague (Feb 15 2025 at 21:30):

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)

view this post on Zulip Brendan Hansknecht (Feb 15 2025 at 21:31):

You can make a #ideas thread if you want to get serious discussion. Might even be able to find an old one.

view this post on Zulip Brian Teague (Feb 15 2025 at 21:37):

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

view this post on Zulip Richard Feldman (Feb 15 2025 at 21:39):

I'm not open to taking if out of Roc. :big_smile:

view this post on Zulip Richard Feldman (Feb 15 2025 at 21:44):

I think it's interesting that Gleam has done it, but I consider it on par with not having + in the language.

view this post on Zulip Richard Feldman (Feb 15 2025 at 21:47):

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:

view this post on Zulip Notification Bot (Feb 16 2025 at 02:32):

Brian Teague has marked this topic as resolved.

view this post on Zulip Norbert Hajagos (Feb 16 2025 at 07:35):

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