Live data from Hacker News

Some notes on Rust

lambda-the-ultimate.org

51–60 of 113 posts

Re: Some notes on Rust

#51
post #47

Earlier quoted context omitted.

Steve, what's the reason that Rust doesn't have HKTs (higher-kinded types). Is there a technical barrier, e.g. to do with life-time inference, or is it a philosophical choice not to have them?

It's one of our most requested features (and would be really good for collections) but it should be backwards compatible and therefore was postponed until after 1.0. Nobody has put in the work to actually make a formal RFC yet either, which is required.

Is anybody actively working on this? I suspect that doing this well is non-trivial. Neither Tofte/Talpin nor Cyclone, both of which heavily inspired Rust's lifetimes, have HKTs as far as I'm aware.

Re: Some notes on Rust

#52
post #30

Earlier quoted context omitted.

> What? C++11/14 solves these issues. You're right that C++ provides a solution to the first two, but C++ locking via std::mutex isn't done in the same way as Rust: in Rust the mutex owns the data and prevents you from getting access to it unless you lock. std::mutex, however, is a separate value from the data it protects and it's up to you to coordinate access to that data. I would also argue that Rust is a better s…

My simplification of matters is that while C++ can now do everything right, it still easily lets you do everything wrong. Rust compels correctness, so for any project where you can't trust your coworkers aptitude towards correctness (and that is to say you even trust your own) Rust is an insane productivity booster. We could have avoided millions of hours of work and thousands of zero day and system destroying bugs i…

> so for any project where you can't trust your coworkers aptitude towards correctness

So, for any non-trivial project. People will make mistakes, no matter how skilled or experienced they are. Catching these mistakes at compile-time can be a huge gain for security and stability.

Though it remains to be seen is what kind of maintenance/development burden these constraints introduce over the longer term lifecycle of a software project.

Re: Some notes on Rust

#53

Earlier quoted context omitted.

So I should use `return` except when I shouldn't? This is the cognitive overhead problem I'm talking about. The original context of my concern is the instance where the match statement makes up the last statement in the function (frequently the only statement in the function's immediate scope). Since the individual cases are not terminating the function early, to get a value out of a match statement you simply leave…

> So I should use `return` except when I shouldn't? This is the cognitive overhead problem I'm talking about. No. Use `return` only when you must . If you want an early return in a function, then you need to use `return`. If you don't need an early return, then don't use `return` at all. I can't remember if this was ever a cognitive load for me personally. I don't think it was.

> I can't remember if this was ever a cognitive load for me personally. I don't think it was.

Well, to be fair, it sounds like you're used to semicolons having special meaning (aside from separating expressions) from a previous language.

> As for `;`, it's just like Standard ML. `;` is for sequencing expressions. I love it.

It's worth remembering that most users of C, C++, Ruby, Java, Python, or whathaveyou are not used to the semicolon having special meaning. Since Rust appears to be primarily aimed at replacing C++, this is going to be a significant change which will likely trip people up for awhile.

Re: Some notes on Rust

#54

Earlier quoted context omitted.

It's one of our most requested features (and would be really good for collections) but it should be backwards compatible and therefore was postponed until after 1.0. Nobody has put in the work to actually make a formal RFC yet either, which is required.

Is anybody actively working on this? I suspect that doing this well is non-trivial. Neither Tofte/Talpin nor Cyclone, both of which heavily inspired Rust's lifetimes, have HKTs as far as I'm aware.

Everything is focused on shipping a good 1.0, so no.

Re: Some notes on Rust

#55
post #50
post #37

Earlier quoted context omitted.

How many Fortune 500 do you see writing those?

Microsoft, Apple, IBM, Amazon?

How many C++ developers can apply to work on those world wide?

The point isn't what companies are using C++11 or C++14, rather what companies for the common C++ developer on the street.

Sometimes HN seems to think SV is the only place where programmers live.

Re: Some notes on Rust

#56

> In particular, allocating a new object and returning a reference to it it from a function is common in C++ but difficult in Rust, because the function doing the allocation doesn't know the expected lifetime of what it returns. I'd like to see a code snippet explaining this problem.

I think he may not understand that Rust has move semantics by default, and so returning a Box just transfers ownership of that object.

Re: Some notes on Rust

#57
post #19

Earlier quoted context omitted.

> I like C++, but I don't see the opportunity where to use C++14 outside hobby projects. Sure, but I’ve encountered some notable exceptions: LLVM projects (C++11), Playstation 4 games (C++11/14), QT5 (C++11) projects, et al.

None of those are the typical corporation code that most of us are exposed to.

Google is on C++11, or was when I left in 2014. They may be on C++14 now.

Re: Some notes on Rust

#58
Wow. I wrote that article on LtU last night, after going over there to see what the language theorists were saying about Rust. (And after, for the third time in three weeks, having my Rust code fail to compile because the Rust crowd changed the language again, after the "alpha release" and its claims of stability: http://blog.rust-lang.org/2014/12/12/1.0-Timeline.html) I wasn't expecting it to be picked up on Hacker News.

Rust is going to be very important. The ownership system is a major step forward in language design. It's a huge improvement over C/C++.

It's not easier to write than C++. Rust may feel clunky for people coming from Javascript, Python, Ruby, and PHP. Having to think about lifetime issues for mere strings is a new cognitive load. The big win with Rust is that most of the errors are caught at compile time. This is Rust's big advantage, but alien to scripting programmers. The Rust compiler report errors in three phases. First you get all the syntax errors, and until the syntax is perfect, that's all you get. Then you get all the type errors, and until the type issues are perfect, that's all you get. Then you get the ownership errors. Ownership is a global analysis; ownership problems involve at least two points in the program. The compiler produces good, but very wordy error messages. (Hint to Rust developers: put in a line length limit and word wrap for long compile time error messages.) If your ownership design is faulty, the result is likely to be "fighting with the borrow checker", because the problem isn't local, and just fixing the compiler-reported error will make the problem pop up elsewhere. The cleverness of the ownership system is impressive, but some programmers are going to feel like they're being hammered by it. Successful C++ programmers won't have a major problem with this. It may be tough on the Javascript crowd.

Rust requires some advance planning, which may be incompatible with "agile" development. It's also difficult to port code from other languages to Rust without rethinking the ownership and bounds logic. There is a port of Doom to Rust. It has a lot of unsafe code, because Doom's internal memory structures are not directly compatible with Rust's. Such problems will recur as big packages with delicate internals are ported over to Rust.

This is partly a documentation problem. The current tutorial (http://doc.rust-lang.org/book/hello-cargo.html) is relentlessly upbeat and glosses over too many of the hard problems. Once some third-party books have been written, that situation should improve.

Re: Some notes on Rust

#59
post #42

Earlier quoted context omitted.

Fair points Rust’s synchronization primitives are immature — they’ve been rewritten once or twice in the past year or so — but cool from a usability perspective. edit: oh, hello pcwalton. I suspect you knew this already. :P

[Citation needed]

?

Re: Some notes on Rust

#60
post #7

Earlier quoted context omitted.

> References and lifetimes allow you to safely return pointers to stack allocated objects. This is explicitly called out as non-idiomatic behavior in the documentation, however. The preferred action is to allocate on the caller's heap and pass a mutable reference down to the callee. In fact, in general it's recommended not to use Box, because it complicates human reasoning about the code. And while it gets around a l…

> In fact, in general it's recommended not to use Box, because it complicates human reasoning about the code. Really? I've always understood it was because when possible that decision should be left to the caller and boxing by default just made the interface less flexible/convenient for callers. How does Box complicate reasoning about the code?

To me, because Boxed objects are a weird combination of a pointer and a stack value. Boxed values have a lifespan all their own, and you need to understand the details of a box's scope to understand how they will behave, and when they will be deallocated.
Post reply on HN