The "loop" keyword doesn't carry its weight


You could hope the compiler understands what you mean by while true etc., or you can just say what you mean with loop.


I wouldn’t normally reply, but since Leonardo’s been chastised on my behalf, I feel the need to make sure we’re absolutely clear about this. Hopefully, this is the last reply on this topic; the last thing I want to do is drag this out any further, but see again the stated motivation.

“You’re a cool boy” didn’t make any sense literally or colloquially, and I didn’t expect Leonardo to be trying to attack me, so I assumed it was a slightly clumsy or regional turn of phrase and just ignored it. There’s enough offense in the world as it is, you shouldn’t be getting offended on behalf of other people. If someone says something that offends or upsets me, it’s my prerogative to bring that up, no one else’s.

I mean, if he’d replied to that hideous and obviously impractical macro with “Go boil your head”, despite being something you could interpret as a command to greviously injure myself, I’d have gotten a chuckle out of it and assumed he was being facetious. If anything, I’d be more upset that he hadn’t taken the opportunity to tell me to throw some vegetables in with my head when I boiled it to at least make a semi-decent “pork” broth.

One thing that does offend me is people being offended on my behalf. That assumes you know me on a deep and personal level, down to my visceral, emotional reaction to anything I might encounter. To so casually claim such intimate knowledge of me feels like a serious violation of my personal space. It’d be like coming up to me on the street, never having met me, sitting down, throwing your arm around me and talking like we’re old pals. If you’d have been standing next to me and said that, I’d probably have given you the swear-laden chewing-out of your life. But you’re not, and I can take the time to do what I feel is the correct thing: understand it was said out of concern (inappropriate and misplaced though it may be in this case), and just ignore it.

… until a moderator posts a message and I feel compelled to defend Leonardo just in case it wasn’t clear that I wasn’t offended in any way by what he said.

Ok, we all good? Good.

I’ve kind of gone from thinking this to liking having an explicit construct. The former is good as an additional bit of checking the compiler can do, but having an explicit form that’s absolutely unambiguous makes the code a little easier to understand.

I used so much implicit junk when I was writing D, but as your codebase gets more and more complex, it gets progressively harder to actually understand what the code is doing. You start to hate yourself for being lazy all those years ago when you write all this stuff.

I mean, it doesn’t really apply in this case (while true is pretty easy to recognise), but I’m saying that I prefer loop as an overall approach to the design of the language.

Sure, we end up with an extra keyword and construct, but it’s one of the simplest possible constructs, so it’s not a huge imposition on my mental processing.


Just because something is directed at you doesn’t mean it can’t offend or bother anyone else. The particulars of this situation aside, consider an example in which two people have a relationship in which they are comfortable exchanging words that other people consider very abusive. Even though neither target of the language is offended or hurt, that could still create an unwelcoming environment for others. I don’t think @birkenfeld was claiming to speak for you.

On the subject of this thread, my own opinion that I would rather see while removed from the language than loop. loop is the purest representation of the construct, whereas while is nothing but sugar for a case that is not actually that common, at least in the code that I write. Still, I think they both carry their weight.


This is the part I don’t quite understand. What makes you think Rust is “bare-bones”? As core language features for a low-level language go, Rust seems pretty rich.

The “cool boy” comment is so innocuous, though, especially coming from someone for whom English is not a first language, that taking offense to it seems like an attack. On the other hand…

Absolutely. This is something that seems worthwhile to discourage within the community, regardless of the whom such comments are directed at.


Compared to C89 Rust is a rich language, but compared to the languages I’ve used, D, Ada and C++, Rust feels rather bare-bones to me.

And from what I’ve read in the last period before the V.1.0, Rust was stripped from everything that wasn’t essential (and this was a good thing! Here I am not criticizing!). I have read even about a desire to remove the immutability…

I can write a rather long list of features present in those three languages that are missing in Rust. Most of those things are not necessary, but I miss few of those features (and I am not alone: some of them are being asked in RFCs). Rust even lacks a do-while, see the macro above that adds a boolean.


I realize that the “bare-bones” feeling is subjective, but are there specific features you feel are lacking beyond do-while? You mention a “rather long list,” so maybe just give us your top three or so?


Yes, but they are few (probably three or four), and none of them is major, I think. And it’s better to discuss each of them in separated threads, when I’ll be more expert about Rust. If I suggest medium-sized enhancements now, I risk saying some silly things, because I have only few months of Rust coding experience.

You mention a “rather long list,” so maybe just give us your top three or so?

That “long list” refers the features of D/C++/Ada/etc that aren’t in Rust. But this is a mostly useless list to write down, because the point of a good language design is not to collect as many features as possible :slight_smile:


I can’t disagree with you there! More features almost always seems to mean more footguns.


IMHO the loop argument has one very important purpose - providing a looping construct whose type is !.


As do most people here – remember, Rust isn’t that old, 1.0 dates from May 2015, and most of us jumped in at that version. So don’t be afraid to look stupid. We’re all still learning Rust as we go – and yes, that happens to include the core developers.


Rust has a notion of “constant” expressions in places like the right hand side of a const item. There should be a type-theoretically sound way to equate while <const boolean value evaluating to true> { ... } to loop { }


That sounds like an awfully roundabout way to write the easiest possible loop.


Yes, if we are going to simplicity, we should remove while, as it is redundant

while <cond> { <body> }
// is equivalent to 
loop {
    if !<cond> { break; }


We’re going for usefulness, usability, etc.


loop is the only looping construct that can not be expressed by any of the others, and at the same time loop, if and match are sufficient for all the others. We could remove for, while and while let to clean up the language.


While we’re at it, nobody needs if either: match on a bool. Clearly the only constructs we should have the language are those needed for Turing-completeness, not those that people find useful to express clear code.


Apologies for the exaggerations. Removing while and while let is an exaggeration, but I admit it’s the kind of minimalism that I find thrilling. In reality I quite like the convenience of while let, for example. I don’t find it troubling that we have a simpler base loop in the language (loop) from which all other loops can be derived, rather the opposite.


Isn’t that part of Rust’s philosophy?