Live data from Hacker News

Reflections on Rust, and the Sand Castle Metaphor

brandur.org

51–60 of 89 posts

Re: Reflections on Rust, and the Sand Castle Metaphor

#51
It's not the borrow checker that the author considers a problem. It's move semantics and futures. The borrow checker was a huge breakthrough in language design. Some of the other new stuff is marginal. Trying to hammer Rust into a functional language via the template system was probably a mistake. Too many "see what cool things I can write in one line" features.

I was a big fan of Rust at first, but I bailed out a while back.

Re: Reflections on Rust, and the Sand Castle Metaphor

#52
post #34
post #20

I have a hard time believing that Rust's guarantees make it safer than easier statically typed languages like Java or Go. Rust is hard because it is solving a different problem, memory management without a garbage collector, not because it has the strongest correctness guarantees.

Rust doesn't have iterator invalidation issues or "ConcurrentAccessException" which are very nice for writing highly concurrent code at large scales. Throw in niceties like no null, result types for better error typing, and a culture of correctness and you've got a really nice language for writing correct software. Go and Java are certainly good at writing correct software too, especially compared to python or javasc…

Agree and Rust's biggest benefit to me over most other languages, is being able to give ownership of a mutable structure away, and knowing at compile stage that every part of the program but the receiver loses access to make further modifications to that data. Then the receiver doesn't have to make a defensive copy (which is easy to forget and often hurts performance), or deal with immutable structures where they aren't performant or natural. I'm hoping some easier languages can add this ability - I think Swift might be planning to do some form of this IIRC, hoping to see some other languages follow.

Re: Reflections on Rust, and the Sand Castle Metaphor

#53
post #51

It's not the borrow checker that the author considers a problem. It's move semantics and futures. The borrow checker was a huge breakthrough in language design. Some of the other new stuff is marginal. Trying to hammer Rust into a functional language via the template system was probably a mistake. Too many "see what cool things I can write in one line" features. I was a big fan of Rust at first, but I bailed out a wh…

From the article

> This is especially true when it comes to the more complicated ones like moves and futures, but also true for simpler ones like borrows. What I didn’t know when I wrote about it in frustration a month ago is that it doesn’t take a little longer longer to be effective in Rust compared to other languages, it takes 10 to 20 times longer.

I think futures might be exacerbating the authors problems. There was a recent post [0] that does a good job explaining why futures are so hard and how the in-progress async/await features fix it.

[0] https://aturon.github.io/2018/04/24/async-borrowing/

Re: Reflections on Rust, and the Sand Castle Metaphor

#54
post #17

This is not at all specific to rust: OP is just grateful for the compiler to find lots of problems one would have to write tests for in dynamic languages.

I think that assessment is more black and white than the situation. There are gradations to how much the compiler and static analysis help you. Coming from C++, I've been blown away by how much confidence Rust gives me in my code.

The borrow checker is the primary reason I feel this way. A smaller aspect is how easy it is to write white box unit tests. I can have an equivalent of a C++ static function in Rust and run unit tests on it. For C++, I'd either have to hack up the source files for when building my unit tests or make turn the function from static to being exposed in a header so my tests can access it.

Re: Reflections on Rust, and the Sand Castle Metaphor

#55
post #53
post #51

It's not the borrow checker that the author considers a problem. It's move semantics and futures. The borrow checker was a huge breakthrough in language design. Some of the other new stuff is marginal. Trying to hammer Rust into a functional language via the template system was probably a mistake. Too many "see what cool things I can write in one line" features. I was a big fan of Rust at first, but I bailed out a wh…

From the article > This is especially true when it comes to the more complicated ones like moves and futures, but also true for simpler ones like borrows. What I didn’t know when I wrote about it in frustration a month ago is that it doesn’t take a little longer longer to be effective in Rust compared to other languages, it takes 10 to 20 times longer. I think futures might be exacerbating the authors problems. There…

Too many articles about Rust talk about why the current language sucks, but some feature in progress will fix it.

Rust started out with roughly the complexity level of C++, and it's become more complex from there.

Re: Reflections on Rust, and the Sand Castle Metaphor

#56
post #5

I do think the difficulty of Rust is brushed aside by its proponents. This week I wrote a little script to read an XML file, get a path from it, read a file at that location, do some regexes on it, and then update the XML and write it back to disk. I'd estimate it took me about 10 times longer to implement in Rust than Python. And I don't exactly know Python well - it wasn't just extra time Googling how to do things.…

> A lot of it is just how restrictive the borrow checker is. Often you have to structure your code in a really weird way to satisfy it.

I've rarely found this the case for me but I came from C++ and am generally used to thinking in terms of lifetimes. Could you elaborate on how you ran into problems with borrows messing up code structure?

> Dealing with strings is another pain point. I get why there is `&str` and `String`. But that doesn't explain why I can't add two `String`s together using +.

I feel like the Rust stdlib takes after C++ in making costs obvious to people and not providing shortcuts for slow operations, causing the ergonomics to scale with performance.

Something that some of us in the CLI-WG have been talking about is creating a library that interops with the standard library but instead focuses on python-like semantics at the cost of performance. This will be a big benefit for "quick scripts" and people learning the language while allowing people to still fall back to high performance idioms as determined by a profiler.

Unfortunately, this is a little lower on our priority list for now.

Re: Reflections on Rust, and the Sand Castle Metaphor

#57
post #45

Earlier quoted context omitted.

Because Rust is a systems language?

What does that cash out as that the programmer cares about though? A task like "read an XML file, get a path from it, read a file at that location, do some regexes on it, and then update the XML and write it back to disk" doesn't need any special systems-ness (and maybe Rust is only a suitable choice for problems where you need that systems-ness, but people seem to be writing a lot of ordinary code in it and advertis…

Because C/C++ are systems languages. You can use a hammer for whatever you like, that doesn't make it the right tool for the job. If you want ease of implementation then I'd reckon you don't need Rust. Rust is for correctness and speed. This is why the comparison was made in the first place.

To address the heart of what you're getting at: I don't buy the fact that it took "10x" longer to read an XML file. I'll give you some amount of "longer" just by virtue of Rust's general strictness and lengthy semantics (like any systems language), but you can't just squash together your unfamiliarity with the language or its libraries and use that to determine the base line difficulty of implementation. To highlight this, consider a seasoned C# developer trying to read an XML file in python for the first time. It would probably take them "10x" longer in python too, and it won't be because the languages have different purposes/audiences or the languages' rules and conventions.

Re: Reflections on Rust, and the Sand Castle Metaphor

#58
post #44
post #6

This is indeed very light in content. Also, while Rust fixes a whole set of problems, it doesn't mean that Rust fixes all possible problems. It is relatively easy to create a situation where you overflow your program. See here: https://github.com/rust-lang/rust/issues/50049 Googling around, there are many situations where bad code can lead to an overflow and your code breaking.

This is the equivelent of `~Foo() { Foo f; }` isn't it?

Yeah, not sure I understand the criticism here. This program also has a bug.

  fn main() {
      let a = 3;
      assert(a == 2, "a should definitely be 2");
  }
Rust doesn't mean no bugs ever, and it doesn't mean no crashes. It protects you from a very specific class of severe bugs, and it has a pretty good set of built-in primitives to help you write bug-free code in the other classes. No more, no less.

Re: Reflections on Rust, and the Sand Castle Metaphor

#59
post #20

I have a hard time believing that Rust's guarantees make it safer than easier statically typed languages like Java or Go. Rust is hard because it is solving a different problem, memory management without a garbage collector, not because it has the strongest correctness guarantees.

My experience would disagree with this. Features like enums, traits and newtypes make it easy to encode a lot more of your programs invariants statically, and in ways which naturally fit the problem domain (as opposed to Java where I often feel like I'm trying to squash my structure into a class hierachy which it doesn't really fit).

In addition the explicit error handling (together with enum error types) allow the compiler to check that you have handled every error case.

Rust has enabled me to write programs that just don't contain bugs (after an initial testing period). This is certainly acheivable with other languages, but it involves a lot of discipline, writing tests, etc. Rust makes it easy.

Re: Reflections on Rust, and the Sand Castle Metaphor

#60
post #31
post #4

Very much matches my experience with the last ~2.5 years of Rust. One of the really eye-opening ones for me was building a UI library on win32 and watching it just work on Linux, OSX, Android and WASM(with some Canvas work). Obviously each platform took some work to build out their respective rendering primitives but the core engine(including embedding Lua via gcc crate) just worked. As someone who's done x-platform…

I had the same experience with any programing language with a rich set of libraries since the 16 bit days.

Oh come now, anyone who's worked with C or C++ knows there's a million pitfalls in porting code across platforms.

Heck, C doesn't even guarantee that a byte is exactly 8 bits.

The point I was making is that I was able to do this without a single ifdef/platform specific code without even planning for it(since it was the first time I'd cross-compiled for more than one other platform). While that's common in the VM language space seeing that in a compiled language was refreshing.

Post reply on HN