Live data from Hacker News

Rewrite Everything in Rust

robert.ocallahan.org

191–200 of 242 posts

Re: Rewrite Everything in Rust

#191
post #190
post #122

Rust is nice. But the article miss one important point. Modern software engineering is a collaborative effort (well, it has always been, afaik). I write code for others to understand. I find Rust code significantly hard to read (I am saying this as an experienced C/C++ programmer and as an intermediate haskeller). Yes, one can write write-only code in any language. I think it is extremely important to write code that…

Another gripe I have is that the Rust Book examples are all targeted at non-system programmers. It would have been nice if certain programs written in K&R book or from one of those books from the Bell Labs Unix folks (like "The practice of programming" or "software tools") is written in Rust as a demonstration.

You should be much happier with the second edition of the book.

(One of the reasons it's this way is largely historic: so much was changing in the lead-up to 1.0 that I couldn't add many examples, as things kept changing out from under me.)

Re: Rewrite Everything in Rust

#192
post #185

Earlier quoted context omitted.

Note that while many OOP patterns are hard to express in Rust, there are equivalent patterns that handle the use cases. To give some context on those blog posts; they exist to figure out how to add single inheritance to Rust. One of the strongest arguments for single inheritance in Rust is "Servo and similar things need it to model the DOM". I.e; the strongest argument out there is that modelling cross-language thing…

> while many OOP patterns are hard to express in Rust, there are equivalent patterns that handle the use cases. May be there are, but they far from trivial, and with the current level of documentation they are in the realm of some obscure hacks rather than straightforward part of the language. Which is a disadvantage. May be when The Book will cover OOP topics in depth and explain such patterns, or there will be some…

> current level of documentation they are in the realm of some obscure hacks

I don't think so. Rust encourages a certain style of designing code, using enums and traits. Almost all the time this suffices.

My comment was at the macro level; I'm not saying that an OOP pattern will have an equivalent in Rust, I'm saying that if you look at the larger use case you can design your code in idiomatic Rust to avoid it.

Re: Rewrite Everything in Rust

#193
post #189

Earlier quoted context omitted.

We have and will add language features; though we haven't added any HUGE things in a while. You are right that RFCs contain language changes. A lot of them are small. Some of them are big, and there's certainly more big ones on the horizon.

May I ask what those big ones are? How is it going to affect/improve the life of a systems programmer?

The most recent one off the top of my head is the ? syntax RFC, which should reduce the amount of error-handling boilerplate.

The big ones though are:

* Specialization. This will allow you to write ultra-performent generic code by special-casing when you have the knowledge. It also will be a building block for the next few features.

* The bag of features colloquially known as "inheritance", though that's not really a good name.

* Non-lexical borrowing, and various other borrowck usability improvements.

* Abstract return types, which will allow for you to remove some allocation and make certain type signatures much better.

* Incremental compilation.

Those are the ones on the short list. There are others too, like higher kinded types.

Re: Rewrite Everything in Rust

#194

Earlier quoted context omitted.

Which is "for widespread libraries, the choices are basically C, C++, and now (hopefully) rust .": as in C++ you can use high-level constructs internally without relying on an extensive runtime, and expose and easy-to-FFI C interface. Rust still has insufficiencies though, the inability to customise the (library's) allocator is one I think.

You can use a custom allocator on nightly.

Does the custom allocator support allow for runtime customisation e.g. the library user calling it to set allocator functions then starting to use it? And I expect the custom allocator is global?

Re: Rewrite Everything in Rust

#195
post #185

Earlier quoted context omitted.

Note that while many OOP patterns are hard to express in Rust, there are equivalent patterns that handle the use cases. To give some context on those blog posts; they exist to figure out how to add single inheritance to Rust. One of the strongest arguments for single inheritance in Rust is "Servo and similar things need it to model the DOM". I.e; the strongest argument out there is that modelling cross-language thing…

> while many OOP patterns are hard to express in Rust, there are equivalent patterns that handle the use cases. May be there are, but they far from trivial, and with the current level of documentation they are in the realm of some obscure hacks rather than straightforward part of the language. Which is a disadvantage. May be when The Book will cover OOP topics in depth and explain such patterns, or there will be some…

The book will never cover OOP directly, or at least, the book will always attempt to show Rust as Rust itself, not as in comparison to other languages. "OOP Patterns in Rust" is a very different book.

That said, the second draft of the book is placing a lot more emphasis on understanding how to write Rustic abstractions.

Re: Rewrite Everything in Rust

#196
post #185

Earlier quoted context omitted.

> while many OOP patterns are hard to express in Rust, there are equivalent patterns that handle the use cases. May be there are, but they far from trivial, and with the current level of documentation they are in the realm of some obscure hacks rather than straightforward part of the language. Which is a disadvantage. May be when The Book will cover OOP topics in depth and explain such patterns, or there will be some…

> current level of documentation they are in the realm of some obscure hacks I don't think so. Rust encourages a certain style of designing code, using enums and traits. Almost all the time this suffices. My comment was at the macro level; I'm not saying that an OOP pattern will have an equivalent in Rust, I'm saying that if you look at the larger use case you can design your code in idiomatic Rust to avoid it.

> I'm saying that if you look at the larger use case you can design your code in idiomatic Rust to avoid it.

As I said, may be you can, but it's far from trivial and unless you know how to do it already, coming up with such approaches isn't something that one who just learns the language would be focusing on. You yourself said above, that it's hard. And unlike languages like C++ where OOP approaches are very well documented, Rust documentation lacks such kind of information at present.

Re: Rewrite Everything in Rust

#197
post #185

Earlier quoted context omitted.

> while many OOP patterns are hard to express in Rust, there are equivalent patterns that handle the use cases. May be there are, but they far from trivial, and with the current level of documentation they are in the realm of some obscure hacks rather than straightforward part of the language. Which is a disadvantage. May be when The Book will cover OOP topics in depth and explain such patterns, or there will be some…

The book will never cover OOP directly, or at least, the book will always attempt to show Rust as Rust itself, not as in comparison to other languages. "OOP Patterns in Rust" is a very different book. That said, the second draft of the book is placing a lot more emphasis on understanding how to write Rustic abstractions.

> "OOP Patterns in Rust" is a very different book.

Then may be there should be one like that :) May be it's just my personal impression, but I feel that such kind of documentation now is lacking.

OOP in Rust shouldn't necessarily focus on comparison with other languages (though explaining key differences would be very helpful). But it at least should explain common use cases that OOP expects the language to cover and approaches that Rust proposes for them.

Something like this would very useful in The Book (or some other book): https://lwn.net/Articles/548560/

Re: Rewrite Everything in Rust

#198

Earlier quoted context omitted.

You can use a custom allocator on nightly.

Does the custom allocator support allow for runtime customisation e.g. the library user calling it to set allocator functions then starting to use it? And I expect the custom allocator is global?

Currently, it replaces the global allocator. Using multiple allocators is an interface that's still being actively worked on, it's in the RFC stage, so no code has landed yet.

Re: Rewrite Everything in Rust

#199

Earlier quoted context omitted.

You can use a custom allocator on nightly.

Does the custom allocator support allow for runtime customisation e.g. the library user calling it to set allocator functions then starting to use it? And I expect the custom allocator is global?

It's a build option, and yes, it's global, but of course you can build an allocator that respects some global parameters.

Re: Rewrite Everything in Rust

#200
post #197

Earlier quoted context omitted.

The book will never cover OOP directly, or at least, the book will always attempt to show Rust as Rust itself, not as in comparison to other languages. "OOP Patterns in Rust" is a very different book. That said, the second draft of the book is placing a lot more emphasis on understanding how to write Rustic abstractions.

> "OOP Patterns in Rust" is a very different book. Then may be there should be one like that :) May be it's just my personal impression, but I feel that such kind of documentation now is lacking. OOP in Rust shouldn't necessarily focus on comparison with other languages (though explaining key differences would be very helpful). But it at least should explain common use cases that OOP expects the language to cover and…

Yeah, I think it would be a good book to have. It's just not one that I'm going to write. Hopefully someone else does!
Post reply on HN