Live data from Hacker News

Reflections on Rust, and the Sand Castle Metaphor

brandur.org

71–80 of 89 posts

Re: Reflections on Rust, and the Sand Castle Metaphor

#71
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.…

You need to type your Python code extremely fast to finish it 10 times faster than this Rust program: extern crate xpath_reader; extern crate regex; use std::io::prelude::*; use std::fs::File; use xpath_reader::Reader; use regex::Regex; fn main() { let mut contents = String::new(); File::open("test.xml").expect("Unable to open the file").read_to_string(&mut contents).expect("Unable to read the file"); //println!("Fil…

It was rather more complicated than that. I could go into details but that's not really the point.

It's not the typing that is slow - it's the constant "why can't I do it like this?" stackoverflow trips. For example - how do you open a file in read-write mode? Using File::open()? Nope!

Ok that one is just poor API design - most of the time was really in restructuring to make the borrow checker happy, and fiddling with adding and removing '&' and 'ref' to get the right types.

Re: Reflections on Rust, and the Sand Castle Metaphor

#72
post #38
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.…

If that was your first foray into Rust land, I hope you give it another shot. I definitly struggled with fitting into the Rust programming model at first, but a few adjustments to how I code have really helped me. Some particular points which helped me are: 1. It really helped me to stop trying to force my code to be as pretty as possible the first time around. 2. If you are getting errors about a lifetime not living…

Sadly this is my third or fourth Rust foray. Only one was really successful - writing a tool to basically do 'git describe' using libgit2. That was a decent experience. I also tried to write a wrapper around libsoundio - got quite far but eventually gave up because of limitations in the Rust lifetime system, and because of how hard it is to do callbacks.

Re: Reflections on Rust, and the Sand Castle Metaphor

#73
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.…

You need to type your Python code extremely fast to finish it 10 times faster than this Rust program: extern crate xpath_reader; extern crate regex; use std::io::prelude::*; use std::fs::File; use xpath_reader::Reader; use regex::Regex; fn main() { let mut contents = String::new(); File::open("test.xml").expect("Unable to open the file").read_to_string(&mut contents).expect("Unable to read the file"); //println!("Fil…

This is a really silly counterpoint. I am not even sure what point you are trying to make. How can pasting some program show how long it would take someone to reason out how to write it?

Re: Reflections on Rust, and the Sand Castle Metaphor

#74
post #65

Earlier quoted context omitted.

There are more languages on this world that compile to native code, besides C and C++. It not my fault not everyone bothers to learn them.

Yup, which you're happy to point out in every single thread about Rust. I can set my clock to a post from you about how another language did it first, it's about a useful as a comment saying "+1" these days. Why not celebrate that these concepts are making it into more and more languages? Languages that have rich, vibrant communities and ecosystems. Seems a lot more productive to me then yelling at the kids to get of…

Because many praise Rust as being the language that did those features first, as if they were re-writing history.

Those misconceptions eventually become urban myths and lead to situations like many young devs nowadays thinking that C was the very first systems language, while we old timers know for fact we had plenty of other choices.

Rust is a great language, just lets not pretend it is the first in many of its safety or portability features.

Re: Reflections on Rust, and the Sand Castle Metaphor

#75
post #35
post #18

Earlier quoted context omitted.

Why is that the comparison point though? How long would it have taken in, say, OCaml or Haskell, which would have given similar correctness guarantees to Rust?

Neither OCaml[1] nor Haskell[2] has performance competitive with Rust. It’s impressive how many high-level functional features Rust was able to include, but it’s ultimately a systems language—and it’s unique precisely because it’s a fast systems language that can give the sorts of high-level guarantees usually reserved for GC languages. [1] http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan... [2] https://b…

If I have a budget of 300ms and 100MB, am able to deliver it within 150ms and 30MB, why should I spend more money to make it lets say 50ms and 10MB?

Re: Reflections on Rust, and the Sand Castle Metaphor

#76
post #75
post #35

Earlier quoted context omitted.

Neither OCaml[1] nor Haskell[2] has performance competitive with Rust. It’s impressive how many high-level functional features Rust was able to include, but it’s ultimately a systems language—and it’s unique precisely because it’s a fast systems language that can give the sorts of high-level guarantees usually reserved for GC languages. [1] http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan... [2] https://b…

If I have a budget of 300ms and 100MB, am able to deliver it within 150ms and 30MB, why should I spend more money to make it lets say 50ms and 10MB?

There are many reasons why you might use a systems programming language [1].

> System programming requires a great degree of hardware awareness. Its goal is to achieve efficient use of available resources, either because the software itself is performance critical (AAA video games) or because even small efficiency improvements directly transform into significant monetary savings for the service provider (cloud based word processors).

[1] https://en.m.wikipedia.org/wiki/System_programming

Re: Reflections on Rust, and the Sand Castle Metaphor

#77
post #55
post #53

Earlier quoted context omitted.

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.

Every time you say this, someone rebuts you, or asks you to explain, but you seem to completely ignore any feedback. Could you be more specific?

Rust has nowhere near the incidental complexity of C++: there's so many features/syntaxes in C++ that have surprising interactions. For various reasons (such as not aiming for direct C compatibility), Rust has been able to avoid those for the most part.

Even just initialization syntax in C++ is complicated. For instance, what does this print?

  #include 
  #include 
  #include 
    
  class Foo {
  public:
    Foo(int a) {
      std::cout  int_paren_0(0);
    std::vector int_brace_0{0};
    std::vector int_paren_2(2);
    std::vector int_brace_2{2};

    std::cout  string_paren_0(0);
    std::vector string_brace_0{0};
    std::vector string_paren_2(2);
    std::vector string_brace_2{2};

    std::cout 
Trick question! It segfaults, because string_brace_0 (and only that one, not even string_brace_2) is trying to be a vector of size 1 with an element constructed using the std::string(const char *) constructor (i.e. the 0 literal is becoming a null pointer to pass to that constructor), and this calls strlen on a null pointer. If the string_brace_0 stuff is removed, it prints

  Foo 0
  Foo 0
  int_paren_0 0
  int_brace_0 1
  int_paren_2 2
  int_brace_2 1
  string_paren_0 0
  string_paren_2 2
  string_brace_2 2
  
That is, constructing Foo is the same with () or {}, constructing vector with () is different to {} (the latter uses the explicit initializer_list constructor), and constructing a vector with () is different to {} sometimes, and the same other times!

Unfortunately, random interactions like this aren't an isolated occurrence in C++ (especially due to C compatibility stuff, but it can't be avoided even using only "modern C++" constructs, as above): I suspect if you name any feature of Rust, someone will be able to demonstrate that the equivalent part of C++ is significantly more complicated to use[1]. That is, C++ is probably more complex than Rust on a per-feature level, not just some nebulous whole-language complexity.

[1]: The borrow checker is possibly the only thing that this doesn't work for, but I think there's a fair argument that it is actually simpler in Rust: a C++ programmer ends up having to do something similar, in their head, with no computer assistance.

Re: Reflections on Rust, and the Sand Castle Metaphor

#78
post #32

Earlier quoted context omitted.

Rust doesn't have the Billion Dollar Mistake, as far as I can tell. That alone makes it safer than Java.

Eiffel was one of the first languages to fix it.

... While your history comments can be interesting, not every comment about a feature of Rust needs a "rebuttal" about how it wasn't the first language with that feature. Especially not a comment that wasn't even mildly suggesting that Rust was the first language to not have null pointers/references!

The comparison here was to "easier statically typed languages" (likely with an implicit "that one is likely to consider for a project these days"), with Go and Java explicitly raised for comparison. It's perfectly reasonable to respond to that with "There's no null", without explicitly acknowledging that there's also other languages (even ones before Rust) that don't have null.

Re: Reflections on Rust, and the Sand Castle Metaphor

#79
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.

What Rust gives you over Java is determinism. Having a GC doesn't preclude you from leaking resources(file handles, textures, etc) and you're at the mercy of whenever the finalizer decides to run once the GC has determined it's time to free an object. Usually this manifests as your Java application humming along until you hit some GC threshold cliff and then perf/memory plummets. I also can't enforce ownership in Jav…

Some languages have deterministic, in-thread GC.

Re: Reflections on Rust, and the Sand Castle Metaphor

#80
post #78
post #32

Earlier quoted context omitted.

Eiffel was one of the first languages to fix it.

... While your history comments can be interesting, not every comment about a feature of Rust needs a "rebuttal" about how it wasn't the first language with that feature. Especially not a comment that wasn't even mildly suggesting that Rust was the first language to not have null pointers/references! The comparison here was to "easier statically typed languages" (likely with an implicit "that one is likely to conside…

> not every comment about a feature of Rust needs a "rebuttal" about how it wasn't the first language with that feature.

People keep repeating that the popular language/framework/library of the year has $feature without acknowledging that it's not a new idea. This creates hype.

Post reply on HN