News for hackers. Stuff that matters.
Re:Why the developers who use Rust love it so much by nickm12 on Saturday June 06, 2020 @05:23AM (#23437831)
I love this quote from a friend of mine who was learning Rust:

"It's hard but I love it. Dealing with the compiler felt like being the novice in an old kung fu movie who spends day after day being tortured by his new master (rustc) for no apparent reason until one day it clicks and he realizes that he knows kung fu."

Re:Why the developers who use Rust love it so much by WJW on Saturday June 06, 2020 @06:24AM (#23438150)
Sounds a lot like programming in Haskell. Applying higher-order functions or condensing a parser into a oneliner just makes me feel smart in a way that generating a new Rails controller never does.

My personal theory is that a lot of Rust and Haskell (and many other "advanced" languages) usage is caused by people chasing that feeling. The publicly expounded benefits like memory and type safety are true, but the real reason is that people want to use the language for their own reasons and "I really like it" usually does not have enough weight in a business context.

Re:Why the developers who use Rust love it so much by gameswithgo on Saturday June 06, 2020 @07:27AM (#23438419)
Unlike Haskell, Rust offers a unique combination of safety and runtime performance, which does provide real business value in sone domains.
Re:Why the developers who use Rust love it so much by UK-Al05 on Saturday June 06, 2020 @07:39AM (#23438471)
Algebraic data types, monads, and things based around those have tons of business value for writing correct business logic for non-performance critical code. You get that in haskell.

Though admittedly you can get them other functional languages that are not quite as different. Like Ocaml.

Re:Why the developers who use Rust love it so much by jolux on Saturday June 06, 2020 @07:49AM (#23438515)
Monads are so cumbersome to implement and consume in OCaml that they are not very commonly used. Jane Street Core has monadic abstractions for things like async but it’s a pain without syntax extensions.
Re:Why the developers who use Rust love it so much by lpage on Saturday June 06, 2020 @09:50AM (#23439154)
That was true until 4.08. OCaml now supports monadic let bindings, and more generally, user defined let bindings [1].

You get the benefits of ppx_let (Jane Street) but in a more general and syntactically nicer form. I still wouldn’t call it as nice as do notation in Haskell but it makes monads highly usable in OCaml without the need for an external dependency.

[1]: https://github.com/ocaml/ocaml/pull/1947

Re:Why the developers who use Rust love it so much by jolux on Saturday June 06, 2020 @07:08PM (#23443150)
Wow, I completely missed this! Nice.
Re:Why the developers who use Rust love it so much by ghostwriter on Saturday June 06, 2020 @07:52AM (#23438524)
Rust's safety and runtime performance are not unique, and these properties can be improved further from the level of Rust. Have a look at ATS:

- http://www.ats-lang.org

- https://www.youtube.com/watch?v=zt0OQb1DBko

Re:Why the developers who use Rust love it so much by wuschel on Saturday June 06, 2020 @12:20PM (#23440235)
What kind of project would be a sweet spot to ATS? Would it be comparible with F* [1]?

I would love to understand the nature of the theoretical advantage ATS has here over Rust.

ATS seems to be very much a concept/language in R&D phase. Its ergononics are difficult ergonomics (have a look at the error messages), documentation and example projects sparse.

[1] https://fstar-lang.org/

Re:Why the developers who use Rust love it so much by ghostwriter on Saturday June 06, 2020 @06:55PM (#23443082)
> What kind of project would be a sweet spot to ATS?

I'd say a large mission-critical C codebase that decides to grow and expand a formally-verified kernel of its most important functionality - it can be a real-time sytem, an OS kernel, a HFT algorithm etc.

Nowadays people seem excited about gradual typing in widespread dynamic languages like JavaScript and Python, because it allows them to adopt the best parts of static typing without having to rewrite the entire codebases in new langauges. Now imagine that you can introduce gradual formal verification to your battle-tested C codebase, without a loss in performance[1] and without forcing you into a new tooling ecosystem (compiler, debugger, profiler etc). Actually, you don't need to imagine it, because that's what ATS is :)

> I would love to understand the nature of the theoretical advantage ATS has here over Rust.

I'd say it's a synergy of two key features, that produce miracles when put together - 1) direct and safe pointer arithmetics [2], which enables the same data structures and optimisation tricks available in C, yet in a verifiable environment, and 2) refinement types [3].

> Would it be comparible with F*

Unfortunately, I don't know much about F*, MS Research regularly releases a new PL prototype after the other and I lost my count on Koka[4].

> ATS seems to be very much a concept/language in R&D phase. Its ergononics are difficult ergonomics (have a look at the error messages), documentation and example projects sparse

All true, but nonetheless it's a solid implementation of the mentioned theoretical parts, and if one dares to get through the objective lack of docs and ambigouos compiler messages, they are rewarded with an impressively powerful production-ready system-level compiler, complimentary to their standard C ecosystem which has decades of accumulated wisdom. That's the level of code-reuse other ecosystems can only dream of.

[1] http://blog.vmchale.com/article/ats-performance

[2] http://blog.vmchale.com/article/ats-safe-pointers

[3] http://ats-lang.github.io/DOCUMENT/INT2PROGINATS/HTML/c2584....

[4] https://www.microsoft.com/en-us/research/project/koka/

Re:Why the developers who use Rust love it so much by sasaf5 on Saturday June 06, 2020 @10:42AM (#23439512)
As someone who needs parsers in a daily basis, I got hooked by your "oneliner parser". A search for parser generation in Haskell only gave me typical parser generators. Can you point some examples?
Re:Why the developers who use Rust love it so much by WJW on Saturday June 06, 2020 @11:40AM (#23439907)
What you'd want to google is "parser combinators" or "parsec tutorial" I think. The idea is that parsers are "just" functions and can therefore be combined with higher order functions in various ways to produce "bigger" parsers. For example, an element in the Redis replication stream can be either an Array, a BulkString, an Integer, an Error or a SimpleString and you can express that with the `choice` function:

  parseRedisValue = choice [ parseRedisArray, parseRedisBulkString, parseRedisInteger, parseRedisError, parseRedisSimpleString]
Each of the underlying parsers (ie `parseRedisArray` etc) are also built up out of smaller parsers, all the way down to parsers that just detect a single character. It seems like it should be slow, but in my experience the results have not diappointed yet. If you're interested, I wrote a longer example on my blog, at http://www.wjwh.eu/posts/2019-01-01-parsing-infinite-streams...
Re:Why the developers who use Rust love it so much by skohan on Saturday June 06, 2020 @06:06AM (#23438069)
Sometimes I wonder a key part of the appeal of Rust is that feeling of climbing the mountain. I've noticed that coming to a solution around the particular constraints of Rust can have a eureka feeling which is similar to how it felt applying a new concept successfully for the first time when I was first learning to program (e.g. recursion). I'm not always convinced the solution I come to is superior to what I would have done in a more traditional programming language, but it certainly feels rewarding to overcome challenge, and I would bet that's true of a lot of people, and that it's more motivating than the promise of performance and memory safety alone.
Re:Why the developers who use Rust love it so much by Dowwie on Saturday June 06, 2020 @09:11AM (#23438937)
I've experienced that climber's high several times while working out problems with Rust during my first two years working with the language. It's a rewarding feeling. I couldn't climb without the community, either. There's so much to learn, especially when one chooses to learn while doing, but it can be done with help. I am convinced that the solutions I come with are superior to those I would write with Python, but the first time solving them may involve a costly investment of time and effort.
Re:Why the developers who use Rust love it so much by fluffything on Saturday June 06, 2020 @06:23AM (#23438146)
I consider myself a quite expert C++ programmer, and when I program in C++, I do fight with the compiler, constantly.

For example: 2000 line template error, some overload cannot be picked deep in the template instantiation stack. Probably a bug with SFIANE, or template argument deduction, or ADL, or... the error message isn't helpful. The compiler tries hard to give me a "smaller" error message, by filtering out overloads that it thinks aren't relevant. One of those is the one that should get picked. Why isn't that happening? Let's figure it out. Let's start going through the template stack, trying to break the compiler in the right way to give you the right error message. Tricks like:

    template <typename T> struct NeverDefined;
    NeverDefined<U> {}; // errors spitting out U
    int******** k = t; // errors spitting out the type of t
etc. Its a constant fight.

That's the exact opposite of "fighting" rustc. Using rustc feels like pair programming with a god-like developer. They see your mistakes dozens of moves ahead. They give you a nice error message, 10 lines long, with a summary, and an annotated version of the relevant parts of your code, explaining how the different pieces fit together to cause a problem. If you are not sure you fully understood it, you can just ask rustc to explain the error a bit more, and it would give you a couple of "self-contained" examples that produce the same error, so that you can learn from those, and then go back to your big program and fix the issue. Its fighting in the same way that going through university and learning for exams is a "fight".

People who think they know better and there is nothing left to learn from them will see that as a real fight. They'll also see pair-programming as just another fight, a waste of time. Or even will start a fight when somebody elses review their PRs.

If you are that kind of person, then Rust probably isn't for you. You won't enjoy the compiler. You won't enjoy the language. The language is designed by listening to all opinions, listening to how many different people weight them, and then making an engineering decision. That's the complete opposite of "i'm always right, best products are designed by a single person".

Luckily for Rust, most programmers aren't like that. Github is proof that for many, programming is a social activity. Programming with rustc makes you feel less alone, you are always pair programming. Programming is not a fight with the compiler, but a back & forth interactive conversation, in which you together with the compiler are working together to write a bug free program.

When you collaborate in Rust projects with other people, the social experience is also improved. The discussions about dependencies are very "goal-oriented and high-level": is this a dependency that will make the product better? Things like "how do we integrate or maintain this dependency" aren't issues with cargo. You also never discuss about formatting, that's handled for you automatically. You also never discuss about undefined behavior, or what the C or C++ standard say, or whether dereferencing something is UB or not, or whether you need a check here or not. If it compilers, the compiler proves your program for you. A huge refactor in a lock-free multi-threaded program? If it compiles, it has no memory safety or data-races. You can focus on just discussing the underlying algorithms, the architecture, the things that are most relevant for humans.

Just look at github.com/rust-lang/rust itself. People have time to write issues, explaining in them how to fix them for beginners, offering to mentor beginners into fixing them. You can drop a Rust beginner into a compiler, and you just need to explain them the high-level description of the fix. The compiler makes sure that they make no errors, and they can explore that part of the compiler on their own, by just following the types.

Because Rust is not "just memory safety". Its also having very strongly typed and explicitly-typed APIs and function signatures, that automatically give you great docs, great error messages that tell you which types to use, which you can use to find which methods these types have, and just explore code.

And these are just a couple of things that make Rust better than everything else I've ever used.

Is it perfect? Of course not. I've been using Rust full-time 5 years. It has _a lot_ of issues that probably cannot be fixed due to backward compatibility. But these issues are smaller, and less annoying, than the issues that all other programming languages I've ever used have.

Will I use Rust forever? I really hope not. I really hope somebody manages to discover a language that's significantly better than Rust in every way.

But I doubt I'll see that in my lifetime. Given the amount of features in Rust pipeline(), and the amount of time the group of PL design PhDs are taking to get them just right, such a language would need to be a significant advantage over the state of the art.

() specialization, higher-kinded types, generic associated types, variadics, full operational-semantics specification, ... there are even RFCs for dependent-types. It wouldn't surprise me if programming in Rust in 10 years feels closer to programming in Idris2 than in "Rust 2018".

Re:Why the developers who use Rust love it so much by 9q9 on Saturday June 06, 2020 @08:49AM (#23438819)

   has _a lot_ of issues 
I value your perspective on programming languages. Would you mind sharing those issues? I am in a position where I can and do influence PL design.
Re:Why the developers who use Rust love it so much by fluffything on Sunday June 07, 2020 @07:24AM (#23446595)
There are way to many probably unfixable issues at this point, from the top of my head:

* Lack of proper Linear and !Movable types, and being in a spot where adding them to the language would be a backward incompatible change. This results in complex abstractions, like Pin.

* Fallible destructors without an easy way to return failure. In Rust, destructors (Drop::drop) can fail, but the only way for them to fail is to unwind the stack, which doesn't play very well with the rest of the Rust error handling story. C++ gets this a bit better with destructors being noexcept(true) by default, and providing tools to query whether that's the case.

* Inconsistent handling of Out-of-memory errors. Initially, Rust decided that OOM errors would be fatal, and settled on using unwinding for them. Then realized that some projects driving Rust design, like Servo, actually needed to handle them (e.g. imagine downloading and image that's too big to fit in memory bringing your webbrowser down..), so they patched being able to handle OOM on top, by adding methods to some of the collections, like `Vec::try_push`, `Vec::try_reserve`, etc. This essentially means that there are two methods to do any operations on collections, that it is pretty much impossible to make sure that code that must handle all OOM errors for correctness does so, and does not call an unwinding method by default, etc. Its also one of the reasons why colelcitons parametrized by allocators (Vec<T, A>) its taking so long.

* Lack of parametrized modules, probably a decision that's just too hard to fix at this point.

* Lots of lang items for singletons, like global allocator, panic runtime, etc.

* Unsafe keyword being too coarse grained. Unsafe functions implying unsafe function body block, unsafe keyword used to allow different types of contracts, from dereferencing a raw pointer, to calling a target-feature function, ...

* const and mut raw pointers: this distinction adds pretty much zero value, and complicates certain types of code quite a bit, for no reason.

* too monolithic standard library: libcore adds floats suport, which essentially requires you to implement floats for embedded targets, for which they might make absolutely no sense. No way to prevent programs there from using floats, etc. No way to only implement the different parts of the standard library that make sense for a platform, like threading, etc. but instead requiring targets to just mock the standard library with "unimplemented!()" hacks that error at run-time when you try to use certain APIs.

* PartialOrd, Ord, PartialEq, Eq, traits are not very mathematically sound. They attempt to achieve what C++ spaceship operator attempts, but fail quite hard. They assume that there is only one "ordering" that might make sense for a particular type, but that's usually not true. For example, floats have many orderings (the classic partial order, and IEEE total order, etc.).

* Operator overloading traits like Add or PartialOrd mix half-backed semantics with operator overloading. The standard library ends up, e.g., implementing addition for Strings, to mean concatenation. So essentially any program that constraints generics using the Add trait and requires, e.g., associativity for being free of logic errors kind of fails when passed strings (it will work, but produce garbage).

* Iterator::next returns &Target, which means that you cannot implement Target to return a "proxy" reference type.

* Many of the standard library algorithms, like "sort" and "unstable_sort" only work on slices, there is no way to use them on Lists or other collections, requiring everybody to re-implement them. C++ got this a bit better.

* BinaryHeap is only a min-heap, reusing it as a max-heap is quite weird. In general, these std::collection API mistakes are consequences of having bad fundamental traits (like PartialOrd and friends mentioned above), and a lack of more meaningful Operation traits.

* std-library is a mixed bag, with some things being quite good thought out (Result, Option, The smart pointer types, Cell types), and others being kind of an after-thought (operator overloading traits, collections). Method names are also often inconsistently named across the different parts of the library, does not feel very cohesive.

* C FFI feels like an afterthought. Some things got bolted afterwards like va_args, unions, packed, etc. Its pretty much not clear at this point how to use these correctly, or whether they can be used correctly at all in C FFI. libc is one of the most used Rust libraries, and its a huge mess of duck tape, ABI incompatible depending on where you run your binaries, which resultes in crashes that are hard to debug, etc. It basically assumes that all operating systems that Rust will ever support never will break their platform ABI. Which is an assumption that no widely-used OS satisfies. How to pass C callbacks that panic, etc. is also still super weird.

And probably many more that I can't remember right now. These are just a small fraction of the issues I've encountered and that I believe are not fixable in a backward compatible way. None of them is, in isolation, a big deal. Whether they lead to a death by 1000 paper cuts at some point or not, only time will tell. Rust also has maaany more issues, that are hopefully fixable.

Re:Why the developers who use Rust love it so much by llogiq on Monday June 15, 2020 @06:17PM (#23533730)
We should be able to write a MIR lint that gives us linear types wherever we want them. I hear they are most useful with unsafe code.
Re:Why the developers who use Rust love it so much by verdagon on Monday June 08, 2020 @02:53PM (#23459538)
Wow, thanks for this beautiful post! I'm coincidentally about to publish a language similar to Rust which addresses #2, and I'm now seeing perhaps I should improve a lot of these other things!

I've been looking for someone knowledgeable about Rust's benefits and drawbacks, to learn how the language compares and how to best explain it, would you be willing to chat?

(My email is my username @gmail.com, and I'm also on discord at Verdagon#9572)

Re:Why the developers who use Rust love it so much by 9q9 on Sunday June 07, 2020 @06:36PM (#23451606)
Thanks!

The C FFI worries me because if I choose Rust for our project I'll need to interface a huge number of C / C++ libraries with the Rust core. OTOH, Mozilla seems to be doing fine mixing Rust with C++.

Re:Why the developers who use Rust love it so much by fluffything on Monday June 08, 2020 @03:14AM (#23454312)
Its not that it doesn't work, but rather that it is not guaranteed to work, and the design is basically a pile of duck tape. For example, you can use Rust arrays in a C FFI declaration, but that won't do what you think it does:

    extern "C" { fn foo(x: [u8; 42]); }
does not declare the C function

    void foo(uint8_t x[42]);
Re:Why the developers who use Rust love it so much by pjmlp on Sunday June 07, 2020 @04:55PM (#23450719)
I believe it is only time until you start discussing standards with Rust.

If Rust wants to be taken seriously in many domains where C, C++, Ada and Java are used nowadays, it needs to eventually get a standard specification and multiple implementations.

Re:Why the developers who use Rust love it so much by bjarneh on Saturday June 06, 2020 @06:19AM (#23438125)
That's an excellent quote; and 100% true based on my experience. The only language that I've struggled even more with is Prolog.
Re:Why the developers who use Rust love it so much by dgzl on Saturday June 06, 2020 @05:49AM (#23437999)
Reminds me of learning Vim