Suggestilon Removing loop and while : replace with for

  • Are « loop » and « while » keywords really necessary ?

  • Golang uses three forms of « for » to achieve the same result.

Removing unnecessary keywords increases reliability.

A few points:

  • This forum is dedicated to helping people use today's Rust. Suggestions for changing the language should be directed to the internals forum.
  • For better or worse, this is unlikely to change. The language maintainers take backwards compatibility very seriously. Removing syntax that is so commonly used would break essentially all Rust code that currently exists.
5 Likes

You could also replace the fn keyword with for. The for keyword is currently never used in that position, so this introduces no additional ambiguity, and removing unnecessary keywords apparently increases reliability!

8 Likes

Still, « for » could be used in all cases while maintaining « loop » and « while » for compatibility.

Deprecating while in favor of a word that reads less naturally in that position, while still keeping while as a keyword seems like a really really poor tradeoff.

2 Likes

Rust is Rust.

We all have our little preferences for this and that syntax. It's a trivial matter that causes no harm whilst making things familiar to others coming from C or whereve. Hardly worth thinking about.

But whilst we are at it. Why does Rust use fn rather than function? That would make Javascripters more comfortable.

Or conversely, if terseness was the goal, why does Rust not use lo, wh, fo, ma, re instead of loop, while, for, match, return? And others. For consistencies sake, and think of all that redundant typing.

:slight_smile:

Well, return once used to be ret. I think, the policy was a maximum keyword length of 4 or 5 or something along the lines.

1 Like

I think the question has merit. Unfortunately, Rust is past this phase - for the core language - where everything is up for grabs and can change. Things like that won't change now (Rust before 2015 was exciting!) We have experimental features where the design is still changing, and that's the place to question if things are really necessary, now, before they are incorporated in stable Rust.

6 Likes

Even in the nascent stages of language development it's a hairy issue, because even if a proposal like this were excepted, it would just result in a steam of people asking for while and for, and their questions will also have merit. Just because people have a genuine interest in stepping up to serve in the grand game of Syntax Pong doesn't mean it's a game worth playing...

// ...
where
    for<'f> F: For(&'f str)

Ah yes, my favorite: alphabet soup. :slight_smile:

2 Likes

It's a matter of opinion, and different priorities:

  • Rust decided that for ;; loop form is error-prone, and should be discouraged. So it has robust range-only for, and kept while as a separate form for other kinds of loops.

  • Rust was designed to be familiar to C programmers. C has for, while, and while(1) as an idiom, so Rust's syntax is a refinement of C's syntax.

IMHO Go's multiple variants of for make the code less readable, because you have to scan the expression looking for ; to understand what it actually does. In Rust the first word immediately tells you which form of loop it is. Multiple syntaxes of for make it less certain which syntax was intentional, and which could have been a mistake. Is for x < y actually supposed to be that, or is it a mistake and it's missing ; x++?

7 Likes

"Necessary" is not a useful bar in a programming language. if isn't "necessary" either -- you could always just use match ... { false => ..., true => ... } instead. But I don't think you'd find much support for removing if.

(And taken as far as possible, all you really need is ι.)

Citation needed. One can easily look at static in C++ for an example where using the same keyword for multiple things makes things more confusing to a human than having multiple keywords would be.

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.