# Deleted

**URL:** <https://forum.crystal-lang.org/t/deleted/5958>\
**Category:** Crystal Contrib\
**Created:** [August 27, 2023, 4:10am UTC](https://forum.crystal-lang.org/t/deleted/5958 "2023-08-27T04:10:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![solvecodes](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/solvecodes/32/2141_2.png) [@solvecodes](https://forum.crystal-lang.org/u/solvecodes)\
**Post date:** [August 27, 2023, 4:10am UTC](https://forum.crystal-lang.org/t/deleted/5958/1 "2023-08-27T04:10:19Z")

</div>

this post was deleted

---

<div class="post-metadata">

**Author:** ![MistressRemilia](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/mistressremilia/32/2585_2.png) [@MistressRemilia](https://forum.crystal-lang.org/u/MistressRemilia)\
**Post date:** [August 27, 2023, 11:11am UTC](https://forum.crystal-lang.org/t/deleted/5958/2 "2023-08-27T11:11:45Z")

</div>

Hashes can still be created like this using `of`:

```crystal
foo = {} of String => Int32
foo["neat"] = 42

```

And `then` is still used with `case` statements when you just have a single line after the `when`/`in`.

```crystal
case someVar
when 9 then doSomething
when 13 then doSomethingElse
else puts "Not 9 or 13"
end

case someEnum
in .foo? then puts "Foo!"
in .bar? then puts "Bar!"
end

case other
when 69
  puts "Not a single line on the same line after the 'when'"
  puts "So no 'then'"
end

```

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [August 27, 2023, 1:10pm UTC](https://forum.crystal-lang.org/t/deleted/5958/3 "2023-08-27T13:10:34Z")

</div>

No they definitely aren’t deprecated. What gave you that idea?

---

<div class="post-metadata">

**Author:** ![Devonte](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/devonte/32/1927_2.png) [@Devonte](https://forum.crystal-lang.org/u/Devonte)\
**Post date:** [August 27, 2023, 11:19pm UTC](https://forum.crystal-lang.org/t/deleted/5958/4 "2023-08-27T23:19:16Z")

</div>

I find it interesting that `then` is only ever used in `case` and `select` statements, it would be nice if we replaced the current ternary operator with `if..then..else`, and it would make more sense since we can already use `if` statements as expressions.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [August 28, 2023, 11:50am UTC](https://forum.crystal-lang.org/t/deleted/5958/5 "2023-08-28T11:50:58Z")

</div>

`if a then b else c` would be quite confusing as ternary expression compared to a regular conditional expression `if a; b else c end` considering the final `end` keyword. And it’s not even shorter, so really there’s no point in that. Just use the regular `if`.

---

<div class="post-metadata">

**Author:** ![Devonte](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/devonte/32/1927_2.png) [@Devonte](https://forum.crystal-lang.org/u/Devonte)\
**Post date:** [August 28, 2023, 1:50pm UTC](https://forum.crystal-lang.org/t/deleted/5958/6 "2023-08-28T13:50:18Z")

</div>

I don’t see how it would be confusing, I often have trouble reading code like this: `foo = bar? ? baz : qux` which would be much more readable as `foo = if bar? then baz else qux`. Using a regular `if` statement forces extra whitespace by the formatter even when trying to use the semicolon form:

```crystal
foo = if bar?
        baz
      else
        qux
      end

```

Also, you could make the same argument about inline\[1\] `rescue` expressions which (as far as I’m aware) aren’t even documented properly. Why not just use `begin..rescue..end`?

* * *

1. I’m not actually sure what this form of `rescue` syntax is called, but it is “inline” with the current expression so that made sense to me.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [August 28, 2023, 2:04pm UTC](https://forum.crystal-lang.org/t/deleted/5958/7 "2023-08-28T14:04:36Z")

</div>

`foo = bar? && baz || qux` would also do the trick :S

EDIT: Kinda meant this as a joke, but if you find this syntax better than `bar? ? baz : qux` then 👍.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [August 28, 2023, 9:32pm UTC](https://forum.crystal-lang.org/t/deleted/5958/8 "2023-08-28T21:32:49Z")

</div>

Sure, `then` could be allowed as separator between condition and then branch.

But if you think about the general case, I think it is often a good solution to split this into multiple lines.  
In your example you’re using very short identifiers. In most real use cases, they are likely much longer. Maybe calls with a receiver and arguments. At that point the additional overhead of writing out the keywords will make a poor fit for an inline expression. The ternary operator is concise, which makes it more useful. You don’t have to use it, of course. But I think the best alternative is most commonly a multi-line expression, rather than an inline condition with keywords.

---

<div class="post-metadata">

**Author:** ![gs412](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/gs412/32/2144_2.png) [@gs412](https://forum.crystal-lang.org/u/gs412)\
**Post date:** [September 7, 2023, 3:31pm UTC](https://forum.crystal-lang.org/t/deleted/5958/9 "2023-09-07T15:31:37Z")

</div>

In the absence of ‘then,’ if statements lack a sense of ceremony, and it is hoped that ‘then’ remains an optional element

Ritual is more important than simplicity

Why did I choose Ruby over Python? It’s because Python, in its pursuit of simplicity, omitted ‘end,’ and it lost the ceremonial aspect of programming.

---

<div class="post-metadata">

**Author:** ![Xen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/xen/32/2288_2.png) [@Xen](https://forum.crystal-lang.org/u/Xen)\
**Post date:** [September 7, 2023, 7:09pm UTC](https://forum.crystal-lang.org/t/deleted/5958/10 "2023-09-07T19:09:54Z")

</div>

> [@gs412](#):
>
> ceremonial aspect of programming

OK, haven’t heard that one before. I gather that you don’t use and editor that automatically adds an `end` when typing `do`?

---

<div class="post-metadata">

**Author:** ![gs412](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/gs412/32/2144_2.png) [@gs412](https://forum.crystal-lang.org/u/gs412)\
**Post date:** [September 9, 2023, 1:47pm UTC](https://forum.crystal-lang.org/t/deleted/5958/11 "2023-09-09T13:47:55Z")

</div>

@Xen  
The sense of ceremony is not only in writing, but also in reading

---

<div class="post-metadata">

**Author:** ![j.m](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@j.m](https://forum.crystal-lang.org/u/j.m)\
**Post date:** [September 10, 2023, 1:21am UTC](https://forum.crystal-lang.org/t/deleted/5958/12 "2023-09-10T01:21:47Z")

</div>

If the conditional part spans multiple lines, I think it would be easier to read if there was `then`. Without  
`then`, the conditional part may be enclosed in parentheses.

Someone who think `then` is redundant/unnecessary would also think that `elsif` is unnecessary because

> if condition1  
> block1  
> elsif condition2  
> block2  
> else  
> block3  
> end

could be replaced with

> if condition1 {  
> block1  
> } condition2 {  
> block2  
> } else {  
> block3  
> }

I think this type of simplification leads to lisp-like syntax. I believe that `then` and `elsif` is necessary for readability. (Because of the same reason, I believe that `for i in a do block end` is necessary.)

---

<div class="post-metadata">

**Author:** ![Xen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/xen/32/2288_2.png) [@Xen](https://forum.crystal-lang.org/u/Xen)\
**Post date:** [September 10, 2023, 5:56pm UTC](https://forum.crystal-lang.org/t/deleted/5958/13 "2023-09-10T17:56:34Z")

</div>

> [@gs412](#):
>
> The sense of ceremony is not only in writing, but also in reading

Oh, indeed… Python kinda feels like it’s constantly stopping mid-sentence, doesn’t it?

But `then` feels archaic to me. I wouldn’t say “if they have eggs, then buy 2”, but rather “if they have eggs, buy 2”. In a one line context, using a semicolon works for me. And I think I’d rather write `when 7; puts "seven"` than `when 7 then puts "seven"`.

But isn’t it a bit inconsistent that `if a; b else c end` doesn’t require a semicolon before `else`? And, well, technically `end` too?

I practice, I use the ternary operator in one-line conditions, or the `if`/`unless` suffixes.

---

<div class="post-metadata">

**Author:** ![Devonte](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/devonte/32/1927_2.png) [@Devonte](https://forum.crystal-lang.org/u/Devonte)\
**Post date:** [September 10, 2023, 7:07pm UTC](https://forum.crystal-lang.org/t/deleted/5958/14 "2023-09-10T19:07:38Z")

</div>

> [@Xen](#):
>
> But `then` feels archaic to me. I wouldn’t say “if they have eggs, then buy 2”, but rather “if they have eggs, buy 2”. In a one line context, using a semicolon works for me. And I think I’d rather write `when 7; puts "seven"` than `when 7 then puts "seven"`.

I think it depends on background/context. In the UK you would use `if ... then` in a formal context and omit it in informal contexts (which would be the equivalent of `if ...;`).

It’s also worth pointing out that `if a then b else c` is not the same thing as `if a; b else c end` so this wouldn’t be the removal of the latter syntax because they are two separate expressions. `case` statements similarly support this: you don’t have to use `when a then b`, you can also do `when a; b` or the more popular newline format.

---

<div class="post-metadata">

**Author:** ![MistressRemilia](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/mistressremilia/32/2585_2.png) [@MistressRemilia](https://forum.crystal-lang.org/u/MistressRemilia)\
**Post date:** [September 10, 2023, 8:56pm UTC](https://forum.crystal-lang.org/t/deleted/5958/15 "2023-09-10T20:56:27Z")

</div>

`if...then` feels like Pascal to me, a bit too verbose with extra unneeded keywords, and also complete with the possibility of a dangling else because you forgot a `begin` and `end`.

```plaintext
if var1 <> var2 then begin
  func1
  func2
end else if var1 = 69 then
  func3SingeLineOnlySoNoBegin
else
  func4AlsoSingleLineOnly;
// No end needed because it's a single line

```

For a single line, either a ternary operator with some parenthesis for visual separation, or a suffixed `if`/`unless` looks perfectly readable to me.

---

<div class="post-metadata">

**Author:** ![Devonte](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/devonte/32/1927_2.png) [@Devonte](https://forum.crystal-lang.org/u/Devonte)\
**Post date:** [September 10, 2023, 9:22pm UTC](https://forum.crystal-lang.org/t/deleted/5958/16 "2023-09-10T21:22:43Z")

</div>

To reiterate what I said earlier:

> [@Devonte](#):
>
> It’s also worth pointing out that `if a then b else c` is not the same thing as `if a; b else c end` so this wouldn’t be the removal of the latter syntax because they are two separate expressions.

so your code example would be equivalent of this in Crystal:

```crystal
var1 == var2 ? begin
  func1
  func2
end : var1 == 69 ? func3SingleLineOnlySoNoBegin : func4AlsoSingleLineOnly

```

You wouldn’t write code like this in Crystal, you would use an if statement. They cover different use-cases, and for a language that is meant to be read like English, I think it makes more sense to have `if..then..else` which has better visual representation compared to [my initial example](https://forum.crystal-lang.org/t/are-then-and-of-deprecated-in-crystal/5958/6).

---

<div class="post-metadata">

**Author:** ![j.m](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@j.m](https://forum.crystal-lang.org/u/j.m)\
**Post date:** [September 10, 2023, 11:08pm UTC](https://forum.crystal-lang.org/t/deleted/5958/17 "2023-09-10T23:08:12Z")

</div>

It is acceptable for me `if condition then block1 else block2 end` is replaced with `if condition do block1 else block2 end`. We could include the syntax without adding the keyword `then`…

(DELETE: I did not read the beginning of this thread carefully.)

(DELETE: This paragraph was a bit of a detour, so I’ll write it again.)

Although `if condition; block1 else block2 end` is acceptable in Crystal/Ruby/Einglish, I feel something beautiful/comfortable/consistent in the expression `if condition then/do block1 else block2 end`. I never use the ternary operator because it is not Crystal/Ruby-like.

---

<div class="post-metadata">

**Author:** ![jzakiya](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jzakiya/32/278_2.png) [@jzakiya](https://forum.crystal-lang.org/u/jzakiya)\
**Post date:** [September 11, 2023, 4:31pm UTC](https://forum.crystal-lang.org/t/deleted/5958/18 "2023-09-11T16:31:32Z")

</div>

This seems similar to this previous discussion

> [@Is it possible to remove unless keyword?](https://forum.crystal-lang.org/t/is-it-possible-to-remove-unless-keyword/2656):
>
> As all know, Crystal brought many concepts from Ruby. Why remove all alias methods, but keep unless left? No language use unless, like JAVA, Go, PHP, C++, Python. All of them use if !.

except in the opposite direction (the inclusion of keywords vs their removal).

I think anyone coming to any language (human or software) has to be willing to learn it to become convsersant in it to other people using it. There are many ways to express ideas in a language. Some give you more options than others to say essentially the same thing. Sometimes this is good, but it may be abused when clarity isn’t the real goal.

**“There is no greater impediment to the advancement of knowledge than the ambiguity of words.”** - Thomas Reid

Here I feel, as someone who came from Ruby, the syntax feels familiar and consistent with past experience. What I had to learn unique to Crystal was mostly based on idioms necessary to program in a compiled language paradigm. But that wasn’t a big deal because I knew a little C, C++, etc, so these concepts weren’t new to learn.

Here the developers of Crystal made certain decisions, based on their preferences, which you wish to extend to meet your preferences. I guess the things they have to determine are 1) does it make the language easier to write, 2) does it make it easier to read, 3) does it make it perform better.

I don’t see this proposal affecting 3).

So it seems it’s just a matter of satisfying 1) and 2) to them.

I don’t think the devs are going to (need to) go through the effort to change the language to accommodate these changes, with the finite amount of time, energy, and resources needed to do other things.

Sometimes you just have to say to yourself, is the language useful (and nice to use) the way it is, warts and all, or do I wait for it to meet my concept of perfection (or even just much better) until I use it?

I would just say, don’t let perfection be an opponent of utility.

---

<div class="post-metadata">

**Author:** ![Xen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/xen/32/2288_2.png) [@Xen](https://forum.crystal-lang.org/u/Xen)\
**Post date:** [September 11, 2023, 8:26pm UTC](https://forum.crystal-lang.org/t/deleted/5958/19 "2023-09-11T20:26:45Z")

</div>

> [@jzakiya](#):
>
> This seems similar to this previous discussion

`unless` has a special place in my heart. It’s superfluous, longer than `if !` and even `if not`, but it comes with the message “I’m going to spend a few extra keystrokes _just_ to make this ever minutely easier to read for you”. Which is a lovely sentiment in a sea of languages that insists that there should only be one form of conditional.

I kinda dig @Devonte’s argument, `if a then b else c` does look nice, but I’m also very wary about adding new syntax, as it _is_ changing the language.

---

<div class="post-metadata">

**Author:** ![j.m](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@j.m](https://forum.crystal-lang.org/u/j.m)\
**Post date:** [September 11, 2023, 10:04pm UTC](https://forum.crystal-lang.org/t/deleted/5958/20 "2023-09-11T22:04:43Z")

</div>

(My previous post was a bit of a detour, so I am writing it again.)

I think that ease of writing and reading depends on a person and a situation. The language could be flexible to satisfy many users and situations.

We can have the flexibility by using a powerful macro as introduced in lisp. Users can define a new syntax by themselves to satisfy their request. However, the powerful macro might be dangerous because it diverges the language.

Because `then/do` has already been a keyword, I think that the addition of optional `if then/do` syntax does not get in the way of others.

Personally (I mean that it is unnecessary for the developers to accept my opinion), I expect Crystal/Ruby to be also a pseudo code language. To be a pseudo code language, algorithms should be written formally, where verbosity is preferred over brevity. Of course, lisp is an alternative (opposite side) pseudo code language. I respect both languages.
