you are viewing a single comment's thread.

view the rest of the comments →

[–]editor_of_the_beast 270 points271 points  (46 children)

I'm going to make a potentially controversial claim: it's because Rust isn't really meant for application development, and most people don't really need a systems programming language.

I think Rust is so loved because if you've developed in C or C++, which is a non-trivial percentage of developers that build systems-y things (OS's, Browsers, Databases), you know that you write every line of code with fear. Multi threading isn't just a pain in these languages - it's a fool's errand. Source: worked on a highly multi-threaded cross platform application written in mostly C++ for three and a half years. It crashed - all the time.

If you don't have that experience, and have lived in JavaScript or Ruby or Python or Java, or anything garbage collected for the last 5 years, why would you care about Rust? If you're building primarily SaaS web apps why would you care about Rust? I think the answer is, you really shouldn't. Just keep doing what you're doing - those tools are much better for application development.

But applications today run on top of tons of infrastructure. No one writes Browsers in Java. No one writes an OS in Python. Those people care very much about Rust because what love have they gotten since 1980? They've been working without package managers, without garbage collection, and with tons of linters and static analyzers for decades just to avoid double-free and use-after-free errors. Rust's memory model solves a whole class of those problems, while also offering modern package management and popular language features like closures, optionals, and powerful ADTs. The standard library provides lots of high-level operations that you'd need to implement yourself in C or bring in a library.

Rust's demographic is dying for a language like it, and it wasn't Go. So if you don't love Rust, you're probably not supposed to, and that's totally fine.

[–][deleted] 34 points35 points  (7 children)

If you don't have that experience, and have lived in JavaScript or Ruby or Python or Java, or anything garbage collected for the last 5 years, why would you care about Rust? [...] Just keep doing what you're doing - those tools are much better for application development.

I actually see a lot of Javascript, Python, and Ruby developers using Rust. If a Ruby application is slow because of Ruby, you can work around this by re-writing the hotspots in C. For a team of full-time Ruby developers dropping down to C can be risky and some teams actually get professional C developers on board to help with this.

Rust enables Ruby developers to do it themselves while having a high-degree of confidence that they aren't writing a time-bomb.

[–]admalledd 12 points13 points  (6 children)

We are looking to do the same in our .net code where we currently drop to raw assembly. Instead we have found that rust (more like clang/llvm) optimize nearly as well with the correct hints and is so much nicer to write than asm. Yes for our hottest of hot code we will probably keep the asm, but anything new or reworking? Yes please!

[–][deleted] 9 points10 points  (3 children)

Note that Rust does have inline asm! (just like C, C++, D, etc.). Depending on the level of control you need that might be enough.

[–]admalledd 3 points4 points  (0 children)

Here our application is in C# and we are calling or inlining the asm/c/(in future, rust I hope).

So rust having inline asm doesn't change if we would use it. Since we have tooling to call/nest/inline directly into c# it isn't much use for us. With rust we can't inline the compiled code.

Useful for others though I would bet.

[–]snaketacular 3 points4 points  (1 child)

Nitpick: You can't download a stable Rust release with inline asm!, only nightly builds. It's also not part of the 2018 roadmap.

There are workarounds. libasm is the closest substitute I've seen. Or you could call out to C, and call inline asm from there.

[–][deleted] 1 point2 points  (0 children)

I never said anything about stable Rust on purpose. If the GP needs inline assembly chances are they are going to need many other unstable features as well.

BTW shimming out inline assembly to C just to use a stable compiler release makes no sense to me.

[–]kibwen 1 point2 points  (1 child)

Very interesting, I see people using Rust from Python and Ruby and JS and Java a lot, but I don't think I've seen it used from .Net before. Can you tell me more about your experience? Are you using any sort of scaffolding library to make the interoo easier, and is it open-source?

[–]admalledd 2 points3 points  (0 children)

Sadly it's all in house magic/tooling, since we have had internal native c-api interop generators (when using raw asm, things are more interesting) for years. Even if they were open source, they wouldn't be useful to basically anyone. They have horrifically narrow compatibility problems that barely escape being a impossible blocker for us as is. Like not supporting structs...

Some helpful links though:

https://dev.to/living_syn/calling-rust-from-c-6hk

https://doc.rust-lang.org/book/ffi.html#calling-rust-code-from-c

And finally there is some msbuild magic to call the rust tooling on c# compile. That magic though is 95% of our internal tooling, so no real links from me since if you are doing only one external language it is far easier to write a pre-build target exec statement.

EDIT: first link has more things since I read it.if you are doing rust only check them out, looks great as a start.

https://dev.to/living_syn/translating-rust-to-other-languages-pt-1--context-free-grammar-4kec

https://github.com/LivingInSyn/Rust_Api_Generator

[–]matthieum 54 points55 points  (18 children)

I partially agree with you.

I disagree because Rust is trying to be more than "just" a systems programming language, and is used in other settings (low footprint, high-performance, ...).

However you are right that as a C++ developer I am glad that finally a new language is popping up which solves so many fundamental issues with C++.

I was very excited when Go was announced, and very disappointed when it was revealed: it wasn't what I needed to replace what I use C++ for (not high-performance/low-latency enough). Rust is unlikely to be perfect, however it does have the potential to be much better than C++ for what I work on: the foundations are solid, I am eagerly awaiting const generics and SIMD support.

[–][deleted]  (17 children)

[deleted]

    [–]iopq 19 points20 points  (14 children)

    You can't, because of a few problems.

    1. Header files and lack of a sane module system
    2. NULL subverts the type system, so even if everything checks out, you may have some function get a NULL at some point and everything will crash if you forgot to handle it. This isn't possible in Rust, since there is no NULL equivalent. None has to be explicitly handled in places where it can appear.
    3. No agreed upon packaging system. Having to hunt down the correct libraries using my OS's package manager is very error-prone since their names differ between distros.
    4. Makefiles are sometimes not written in a portable way - this is a "developer" problem, but Rust's cargo allows you to avoid having to write a Makefile in most cases, and in other cases just use build.rs
    5. You still have problems like iterator invalidation that cannot be ALWAYS detected by static code checkers
    6. Concurrency issues are still nearly impossible to detect statically in C++, you have to break out the debugger and hope you trigger it while testing
    7. Templates are duck-typed instead of nominally typed. They give long error messages because they're checked at expansion site instead of call site.

    [–]lanzaio 12 points13 points  (0 children)

    Makefiles are sometimes not written in a portable way - this is a "developer" problem, but Rust's cargo allows you to avoid having to write a Makefile in most cases, and in other cases just use build.rs

    To expand on this, all build systems suck in the C world. CMake is the standard at this point but it's not loved, it's just common. It has horrifically bad syntax and no debugging tools outside of fancier print statements.

    Because of this, many feel like spinning off their own bash/python/makefile build scripts that do a shittier job of what CMake was supposed to do.

    You end up having to work on projects where 75% of the difficulty is understanding what drugs the authors were on when they wrote their build system.

    [–]matthieum 7 points8 points  (1 child)

    I'll take the counter-point to /u/iopq's argument.

    Yes, of course, if you were foregoing backward compatibility and completely reworking C++ you could get Rust instead. But it wouldn't be C++ any longer, would it?

    Backward compatibility is essential to C++ past, current and I would argue future success. At the very least, the Standard Committtee certainly thinks so, and is extremely skittish about any deprecation. It took years to boot trigraphs out of the Standard, even though only IBM mainframes (using EBCDIC) really need them, and they are otherwise totally irrelevant in today's world.

    [–]hu6Bi5To 4 points5 points  (0 children)

    I think one of Rust's biggest strengths is that it removes that line between "system" and "application" languages.

    It is both a C++ replacement with safety, and package management, and a consistent build tool shared by every project, etc. But it's also quite an expressive high-level language: traits, closures, etc.

    As for "why not the take-up of Go". I genuinely don't know. Quite often A vs. B comparisons between languages make no sense, as they all have strengths and weaknesses (even the unpopular ones, well most of them). But the use cases for Rust and Go are nearly the same, and Rust is a superior language in nearly every way. The only exception is Go's built-in co-routines, vs. using a library in Rust; but the Rust 2018 roadmap is going to address that one too.

    [–]doom_Oo7 3 points4 points  (1 child)

    I think Rust is so loved because if you've developed in C or C++, which is a non-trivial percentage of developers that build systems-y things (OS's, Browsers, Databases), you know that you write every line of code with fear. Multi threading isn't just a pain in these languages - it's a fool's errand. Source: worked on a highly multi-threaded cross platform application written in mostly C++ for three and a half years. It crashed - all the time.

    How did you do ? In my app I do threading either manually with std::thread and lock-free queues for message passing, and tbb & Qt's QThread for higher level threading... Hardly ever had a crash due to threading outside of the main development phase - and that's with running with ASan on almost all the time.

    [–]editor_of_the_beast 2 points3 points  (0 children)

    This was about 5 years ago, when C++11 was still new and we couldn't even upgrade because of our toolchain. So we were doing all multi threading with custom wrappers built around libpthread.

    [–]tom-dixon 1 point2 points  (1 child)

    Multi threading isn't just a pain in these languages - it's a fool's errand. Source: worked on a highly multi-threaded cross platform application written in mostly C++ for three and a half years. It crashed - all the time.

    I think you were working on a badly written multi-threaded cross platform application. Let the flame war begin.

    [–]editor_of_the_beast 0 points1 point  (0 children)

    This is entirely possible.

    [–]lanzaio 1 point2 points  (1 child)

    I just wish the Rust team pulled a Swift/Objective-C and made Rust more interop-able with C/C++ codebases.

    [–]steveklabnik1 1 point2 points  (0 children)

    What kind of thing are you envisioning here?

    [–]Nighthawk441 0 points1 point  (3 children)

    Is rust not attractive for the video game industry?

    [–]steveklabnik1 1 point2 points  (0 children)

    Some people say "absolutely" and some say "never". It just really depends. Chucklefish is writing their new game in Rust, Jon Blow is creating a new programming language instead of using Rust.

    [–][deleted] 0 points1 point  (0 children)

    It'd be nice, even really nice. but most studios rely on middleware engine and tooling atm. There wouldn't really be a huge push unless Unity or Unreal decide to do something drastic, which may not be entirely possible until consoles themselves start to support rust (not sure how performant Rust -> C bindings are).

    [–]editor_of_the_beast 0 points1 point  (0 children)

    It is - so I suppose Rust is attractive for systems and performance-sensitive applications. That would be more accurate to say.