News for hackers. Stuff that matters.
Re:Rust is more than safety by Animats on Wednesday December 28, 2016 @02:21PM (#13272880)
A sales pitch asking others to help you with your sales pitch. That's a good marketing concept. It's similar to "ordinary people say why X is great" ads.

Beyond the safety issue, I'm still not clear on how to think about Rust. It's mostly an imperative language at the language level, but it has so much functional programming stuff in templates that it looks like a functional one. It's often hard to visualize what all that stuff is doing. Did that ".collect" generate a big intermediate array? How can you tell without looking at the generated code? What kind of development environment would help?

Rust uses closures very heavily for routine functions. That's a big change in thinking for C programmers.

The module system seems clunky. There are modules, and crates, and TOML files, and module statements, and required directory structure. Adding a module seems to require editing about three files. The management of imported names seems unnecessarily obtuse, too. Having both "extern" and "use" seems overkill. Most languages get by with a single "import" statement.

I see all this as an acceptable price to pay for safety, but it's rough on many programmers.

Re:Rust is more than safety by tatterdemalion on Wednesday December 28, 2016 @02:58PM (#13273162)
> The module system seems clunky. There are modules, and crates, and TOML files, and module statements, and required directory structure. Adding a module seems to require editing about three files. The management of imported names seems unnecessarily obtuse, too. Having both "extern" and "use" seems overkill. Most languages get by with a single "import" statement.

You have to edit two files - the new module and its parent. Crates are a separate concept from modules, and the toml file is only relevant for cargo. I do not find there are more concepts than in the module systems of other languages.

That said the Rust module system is empirically more challenging for new users than it ought to be and we'd like to improve it. "extern crate" declarations are actually unnecessary if you're using cargo and people have toyed with removing them.

Re:Rust is more than safety by ucarion on Wednesday December 28, 2016 @02:43PM (#13273066)
Though I knew how to use them, I didn't understand how Rust closures could work until I read these articles:

https://doc.rust-lang.org/book/closures.html

https://doc.rust-lang.org/book/trait-objects.html

Basically, a closure is just an anonymous trait, and traits are implemented with vtables. This reminds me of how you can think of Java's lambdas as anonymous classes (though they're not implemented that way).

Re:Rust is more than safety by tatterdemalion on Wednesday December 28, 2016 @02:53PM (#13273133)
Close. :-) Closures are anonymous types which implement one of the Fn traits (which are not anonymous). Traits are usually not implemented with vtables; they are usually monomorphized and statically dispatched (this includes most higher order functions). If you need dynamic dispatch, they can be cast into "trait objects" with vtables. This is a pretty big deal - static dispatch is why functionalish abstractions like map and filter can compile to a very tight loop.
Re:Rust is more than safety by ucarion on Wednesday December 28, 2016 @08:06PM (#13275007)
Ah, thanks for catching that subtle-but-important mistake. :)
Re:Rust is more than safety by Animats on Wednesday December 28, 2016 @03:54PM (#13273554)
And you wonder why C programmers have trouble with Rust.
Re:Rust is more than safety by akiselev on Wednesday December 28, 2016 @04:21PM (#13273769)
No one in their right mind is wondering that. Going from "go ahead, do whatever you want" memory management to Rust's ownerhsip system or object oriented programming to trait based programming isn't something anyone excepts to happen without some perseverance.
Re:Rust is more than safety by Animats on Wednesday December 28, 2016 @04:33PM (#13273864)
"Expects", I think.

Ask who really needs Rust. People who write code that has to work and causes real trouble when it doesn't. That includes embedded system programmers. They're typically into C and can use an oscilloscope. They seldom know C++ and have never heard of Haskell. But they can lay out a circuit board and get it to work.

Rust needs to be accessible to those people.

Re:Rust is more than safety by Manishearth on Wednesday December 28, 2016 @07:55PM (#13274958)
Almost none of the above is something you actually need to know when programming in Rust.

You just need to know how closures work at a high level, which is pretty straightforward. Rust closures are basically the same as C++ closures.

If you're really worried about the generated code generally iterator code with closures compiles down to the same thing as the imperative code. This isn't a hidden complexity unique to Rust; C code these days is pretty far removed from the generated asm too.

Re:Rust is more than safety by Veedrac on Thursday December 29, 2016 @04:26PM (#13280268)
I strongly disagree. Though it is possible to fudge through working Rust code without understanding the principles that govern Rust, which is probably more than you can say for C++, not understanding these things is going to make life a lot harder when you do run up against them.

An example: https://www.reddit.com/r/rust/comments/5iwyt9/how_to_accompl...

You might not need to know what "vtable" means, but the differences between, for example, `T: Fn()` and `T = Fn()` are pretty important.

Re:Rust is more than safety by kibwen on Wednesday December 28, 2016 @04:47PM (#13273969)
Rust's closure model is literally just C++'s with an extra dose of memory safety on top.
Re:Rust is more than safety by Manishearth on Wednesday December 28, 2016 @08:03PM (#13274994)
> It's mostly an imperative language at the language level, but it has so much functional programming stuff in templates that it looks like a functional one.

Not everything can be neatly boxed in "imperative" and "functional". It's a language without purity, but with many other concepts that make a functional style work very well with it. Swift is similar. IIRC so is Scala. Depending on your POV you may classify this as functional or not; folks ascribe different meaning to the terminology here.

> Did that ".collect" generate a big intermediate array? How can you tell without looking at the generated code?

I don't understand this logic at all. How is this different from any function call in C? You don't know what that function call does without looking at the code or documentation.

This is no different from asking whether operator<< on cout allocates.

> and TOML files

This is like make/cmake/ninja files for C. Those are worse, especially since each codebase does its own thing.

> required directory structure.

no. You can set it up how you like, there's a default directory structure that's easier to use. You can redirect modules to whatever path you want using `#[path]`

> Adding a module seems to require editing about three files.

Two files.

In C you have a header and c file anyway, so the totals match up.

I agree that the module system itself is a bit confusing -- we need to get better at teaching it, but you're being rather inaccurate here overall.

Re:Rust is more than safety by stirner on Wednesday December 28, 2016 @03:20PM (#13273290)
> There are modules, and crates, and TOML files, and module statements, and required directory structure.

I'm a fan of Rust but I also think Cargo seems pretty inelegant considering how carefully considered everything else in the language is. Maybe I'm just biased against Tom Preston-Werner.

Re:Rust is more than safety by steveklabnik on Wednesday December 28, 2016 @03:40PM (#13273425)
What would you have chosen instead? At the time, we weren't super big fans of TOML, but it was the least bad choice. It's grown on me.
Re:Rust is more than safety by stirner on Wednesday December 28, 2016 @05:17PM (#13274163)
I get what you mean by "least bad". I guess I'm wary of all configuration formats. Would plain old INI have been an option or is it too poorly specified?
Re:Rust is more than safety by steveklabnik on Wednesday December 28, 2016 @05:29PM (#13274238)
Too poorly specified, yeah :/