Remove the then keyword in the compiler?

I saw the then keyword when I am reading the latest changes in the crystal-book.

is anyone still use it? AFAIK, it only used when use with case.

p! case 200
when 100 then "hello"
when 200 then "world"
end

But even the output of p! in above remove the then keyword.

case 200
when 100
  "hello"
when 200
  "world"
end # => "world"

So, why we still keep that?

3 Likes

I use it all the time for short lines, yeah.

Yea I don’t think it’s something we’d want to remove. Like what would the benefit be?

This is mostly because the output is a stringified version of the Case macro which has normalizations and such applied to it. I.e. then is just syntatic sugar to allow one-line case when statements that is transformed by the compiler to what you see as the result of p!.

2 Likes

I prefer to use THEN all the time as it makes code much more elegant and readable.
In Ruby you can omit THEN in IF blocks, but I always used it as it improves the readability.
I miss this in Crystal.
For me reading code in Ruby or Crystal is as if I am reading an English poem.
So all shortcuts are crippling that sense of that poem.

3 Likes