Live data from Hacker News

John Carmack: writing Rust code feels wholesome

twitter.com

51–60 of 85 posts

Re: John Carmack: writing Rust code feels wholesome

#51
post #47

Earlier quoted context omitted.

>the borrowing/ownership semantics of rust (at the time I looked at it) felt needlessly over complicated. Taking a wild guess here, but it sounds like you maybe referring to issues addressed by Non-Lexical Lifetimes (NLL)? Reference: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.... NLL are a part of Rust 2018 Edition. Three complementary books are the best resources: - The Official book: https://doc.ru…

NLL only modes aren't available on stable Rust atm. What edition 2018 has right now is migrate mode NLL. In order to fully enjoy NLL, you'll have to use Rust nightly and do #![feature(nll)] or -Z borrowck=mir -Z two-phase-borrows , both flags being independent of the edition you're using. Edit: removed outdated behaviour of migration mode.

This is incorrect. NLL is on for Rust 2018 code.

The transition mode is for Rust 2015 code.

Re: John Carmack: writing Rust code feels wholesome

#52
post #34

Earlier quoted context omitted.

C++ is actually doing very well, and the community is very well aware that C++ tooling sucks. It's just not an easy problem to solve because it has such a huge amount of existing code and projects.

Absolutely! I think the important question is, what will happen first: (a) C++ gets better tooling around build systems and package management; or (b) Rust libraries are written for all of the things that we care about? Certainly in the HN bubble it feels like (b).

It's not just package management. C++ is hugely overcomplicated with features. Understanding C++ is a life project. And the language is unsafe-by-default so you will spend time tracking down segfaults or other UB stuff. Rust allows me to focus on the problem domain, less on the language.

Re: John Carmack: writing Rust code feels wholesome

#53

I looked seriously at rust about 2 years ago. I seem to have tried the language at the wrong time .. they were transitioning between versions and this made learning it hard. I grew up with C so am very comfy with pointers. Even reference counting feels natural to me. That said, the borrowing/ownership semantics of rust (at the time I looked at it) felt needlessly over complicated. Has this got better? Is there a K&R…

Rust's ownership/borrowing model is very close to the (often implicit) model of proper pointer handling in a large C codebase. One medium-sized codebase I've worked with tried to be very disciplined about const pointers as a means of passing shared reference vs. ownership, with a style guide about when to use const that strongly preferred const wherever possible. I tried translating the style guide to Rust and found that's it's basically automatic once you add Rust's reference model.

Of course the big distinction is that Rust mandates it. There's lots of C code out there that happens to work fine with shared data structures that never collide in practice (or at least never collide under non-hostile input...) - see for instance every standard libc API that returns a pointer to a static buffer. Our codebase merely had a style guide, and lots of older code was less disciplined. Rust forces you to care up front about everything.

Re: John Carmack: writing Rust code feels wholesome

#54
post #47

Earlier quoted context omitted.

NLL only modes aren't available on stable Rust atm. What edition 2018 has right now is migrate mode NLL. In order to fully enjoy NLL, you'll have to use Rust nightly and do #![feature(nll)] or -Z borrowck=mir -Z two-phase-borrows , both flags being independent of the edition you're using. Edit: removed outdated behaviour of migration mode.

This is incorrect. NLL is on for Rust 2018 code. The transition mode is for Rust 2015 code.

Please see the code: https://github.com/rust-lang/rust/blob/68650cacf23c60ee2f346...

In edition 2018, migration mode is turned on.

I learned myself about this today btw, after I saw this PR: https://github.com/rust-lang/rust/pull/58342

I think I was mistaken about one point though which is that migration mode is erroring if one of the two errors. IIRC migration mode was introduced that way but it seems to have been changed to be a bit more tolerant than AST borrowck.

Anyways, more NLL fun is to come, and it's to come to both editions.

Re: John Carmack: writing Rust code feels wholesome

#55
post #47

Earlier quoted context omitted.

NLL only modes aren't available on stable Rust atm. What edition 2018 has right now is migrate mode NLL. In order to fully enjoy NLL, you'll have to use Rust nightly and do #![feature(nll)] or -Z borrowck=mir -Z two-phase-borrows , both flags being independent of the edition you're using. Edit: removed outdated behaviour of migration mode.

> What edition 2018 has right now is migrate mode NLL which emits an error if either NLL borrowck or AST borrowck think there is an issue with your code. If that were true, then this example would fail to compile, since it fails with the old AST borrowck: https://play.rust-lang.org/?version=stable&mode=debug&editio... See: https://rust-lang-nursery.github.io/edition-guide/rust-2018/...

Oh right, seems it got a bit more tolerant. The mode's still called migration mode though, full NLL is to be unleashed later on: https://github.com/rust-lang/rust/issues/57895

Re: John Carmack: writing Rust code feels wholesome

#57
post #40

I looked seriously at rust about 2 years ago. I seem to have tried the language at the wrong time .. they were transitioning between versions and this made learning it hard. I grew up with C so am very comfy with pointers. Even reference counting feels natural to me. That said, the borrowing/ownership semantics of rust (at the time I looked at it) felt needlessly over complicated. Has this got better? Is there a K&R…

I've been programming in C and C++ since sometime around 1992 (and Pascal before that). For the last 3 years, I've been writing Rust professionally. Here's my Rust advice for C and C++ programmers: - Rust is a higher-level language than C. A C/C++ programmer could think of Rust as "C++ without most of the footguns and magic." - Certain types of C/C++ code will translate very easily to Rust. For example, if your code…

I'll probably hold off on learning Rust deeply until they have async/await as keywords. Most of the programming I do involves async, and I currently do my day programming in Dart, which is an absolute joy to do async programming in. They had Future-based APIs from day one, so the whole ecosystem was built around futures starting out. They've had async/await as keywords for over 5 years now. It's so ergonomic it's painful to go back.

Re: John Carmack: writing Rust code feels wholesome

#59
post #40

Earlier quoted context omitted.

I've been programming in C and C++ since sometime around 1992 (and Pascal before that). For the last 3 years, I've been writing Rust professionally. Here's my Rust advice for C and C++ programmers: - Rust is a higher-level language than C. A C/C++ programmer could think of Rust as "C++ without most of the footguns and magic." - Certain types of C/C++ code will translate very easily to Rust. For example, if your code…

What are you building with Rust if you don’t mind sharing? I’m curious to know what sorts of companies are using it out there in production.

Here are the major categories of stuff we've built in Rust at work:

1. Lots of little CLI tools, statically linked using https://github.com/emk/rust-musl-builder. These are fast, portable, easy to share, and easy to add to Docker containers. For a fun open source example, see https://github.com/faradayio/geochunk, which groups US zip codes into evenly-sized chunks.

2. Code where we need to handle all the corner cases very carefully. Rust's enum and match are wonderful for this. An older open source example would be https://github.com/faradayio/cage, which performed all sorts of fiddly transformations on docker-compose.yml files. (I need to massively overhaul this to work with https://kustomize.io/ someday.)

3. Code which moves around large amounts of data, and maybe processes some of it. This might involve REST APIs, AMQP queues, cloud buckets or databases. Sometimes we wind up writing a little extra glue code, but we're pretty happy overall.

This morning, I'm working on an unreleased open source command-line tool that moves large database tables between different local and cloud databases. This actually uses async Rust (specifically https://tokio.rs/blog/2018-08-async-await/), which is definitely bleeding edge. But this particular code benefits enormously from Tokio, so we're taking the plunge.

Overall, our Rust code is fast and reliable. I enjoy working on it, and my boss likes the fact that our Rust code tends to be very solid.

Re: John Carmack: writing Rust code feels wholesome

#60
post #40

Earlier quoted context omitted.

I've been programming in C and C++ since sometime around 1992 (and Pascal before that). For the last 3 years, I've been writing Rust professionally. Here's my Rust advice for C and C++ programmers: - Rust is a higher-level language than C. A C/C++ programmer could think of Rust as "C++ without most of the footguns and magic." - Certain types of C/C++ code will translate very easily to Rust. For example, if your code…

What are you building with Rust if you don’t mind sharing? I’m curious to know what sorts of companies are using it out there in production.

[deleted]
Post reply on HN