News for hackers. Stuff that matters.
Re:How to speed up the Rust compiler in 2018 by MikkoFinell on Monday April 30, 2018 @05:28AM (#16957072)
Why is Rust so popular on HN? Honest question.
Re:How to speed up the Rust compiler in 2018 by noelwelsh on Monday April 30, 2018 @05:35AM (#16957106)
Because it's interesting.

It is interesting because it advances the state of the art: it makes safe "systems programming" possible, which no production ready language previously provided.

It is interesting because it is accessible to many of the people who frequent HN. It's community is similar enough to the community of HN readers that many HN readers can use Rust and not feel out of place. The concepts it introduces are not such a departure from the concepts familiar to many programmers that a huge amount of learning is required. (Compare to, say, more research oriented languages like Idris).

Re:How to speed up the Rust compiler in 2018 by pdpi on Monday April 30, 2018 @06:04AM (#16957245)
> The concepts it introduces are not such a departure from the concepts familiar to many programmers that a huge amount of learning is required.

More specifically, I would say that it lands in the Goldilocks range: It's not so alien as to make it inaccessible, while being alien enough that you'll learn something from it.

Re:How to speed up the Rust compiler in 2018 by dozzie on Monday April 30, 2018 @06:16AM (#16957298)
> it makes safe "systems programming" possible, which no production ready language previously provided.

I think you have just made Ada and several other languages disappear from the history.

Re:How to speed up the Rust compiler in 2018 by noelwelsh on Monday April 30, 2018 @06:29AM (#16957354)
Yeah, "production ready" was the wrong phrase. It's more a combination of availability of language compiler, tooling, training, and interest from developers.

If you start a new project using Rust there is a reasonable chance you'll be able to find libraries for common tasks and developers willing to work on it. You can make a case for it and not lose your job. With Ada, outside of a few niches that isn't going to be the case IMO.

It's been a long time since I looked at Ada, but I believe it's memory mgmt is more inline with modern C++ than Rust. So perhaps it's not truly comparable.

Re:How to speed up the Rust compiler in 2018 by kibwen on Monday April 30, 2018 @09:36AM (#16958452)
The thing that Ada and its peers lack that Rust has already tackled is finding a strong foothold in OSS. Doubtless there are more lines of Ada than Rust in the wild, but in 30 years of use the only OSS Ada project I can name is GNAT itself, whereas anyone using e.g. Firefox or VSCode is using Rust despite it being ten times younger. Given that most new developers these days seem to learn to program via OSS, and given that HN is largely OSS-focused, it's no surprise that Rust gets mentioned more.
Re:How to speed up the Rust compiler in 2018 by dozzie on Monday April 30, 2018 @12:25PM (#16959927)
> The thing that Ada and its peers lack that Rust has already tackled is finding a strong foothold in OSS.

Which is irrelevant to the claim that no previous language provided safe environment for systems programming.

Re:How to speed up the Rust compiler in 2018 by swsieber on Monday April 30, 2018 @12:50PM (#16960163)
You're missing the qualifier of "production ready". While I'd argue that Ada was indeed "production ready" language wise, I'd say that it's not with respect to libraries, of which, OSS contributes a whole bunch.

For some people, a good library selection is essential to being "production ready".

Re:How to speed up the Rust compiler in 2018 by dozzie on Monday April 30, 2018 @03:55PM (#16961700)
We must think about quite different things behind "systems programming" if you need libraries for it. For me system implements and provides interface, not uses it. Like in operating system.

And then, Ada had a selection of libraries for a long time. You just conveniently forget about the paid ones, so you can call Ada "not production ready".

Re:How to speed up the Rust compiler in 2018 by swsieber on Tuesday May 01, 2018 @01:13PM (#16969004)
I wouldn't even say conveniently forgot, I'd say it didn't even cross my mind. It is perhaps also representative of why people don't consider Ada when picking out a language.

That said, I agree that it'd be moving the goal posts to omit paid libraries.

--

I do think we have slightly different ideas of "Systems Programming", or at least what production ready means for that type of language. I think it boils down to the fact that people do a lot more in "Systems Programming" languages than just OS or implementing and providing interfaces. Specifically, people do it for performance and control, which I don't necessarily excludes the use of libraries.

I think the contention here is that people are thinking of production ready for these types of languages in terms of general use, not just the niche you describe. In retrospect, I do think it was a poor way to word it.

I guess I'd probably amend the original comment to say something like "Rust is the first production ready systems programming language that can comfortably (after a learning curve) be used at higher levels".

Re:How to speed up the Rust compiler in 2018 by kibwen on Monday April 30, 2018 @07:27PM (#16963412)
Sure, but that's irrelevant to my comment, which is answering the original question "Why is Rust so popular on HN?" in the specific context of Ada.
Re:How to speed up the Rust compiler in 2018 by dozzie on Tuesday May 01, 2018 @12:06PM (#16968290)
It's not irrelevant. Ada provided safe, production ready language for systems programming long before Rust, so this part of explaination is simply false.
Re:How to speed up the Rust compiler in 2018 by wtetzner on Tuesday May 01, 2018 @03:33PM (#16970616)
I wouldn't say it's simply false, just that it requires a bit more explanation. Ada is a safe systems language, but is more restricted in what can safely be expressed.
Re:How to speed up the Rust compiler in 2018 by pjmlp on Monday April 30, 2018 @11:13AM (#16959236)
While you are right, it would also be good to learn the history of computing in a proper way, instead of re-writing it based on urban myths and perceptions.
Re:How to speed up the Rust compiler in 2018 by monocasa on Monday April 30, 2018 @11:54AM (#16959639)
Ada doesn't have the same memory management safety without a garbage collector that Rust does.
Re:How to speed up the Rust compiler in 2018 by Raphael_Amiard on Tuesday May 01, 2018 @08:35AM (#16966473)
Ada has memory management safety, even though it is not the same paradigm as Rust. Affine typed pointers might be a tad more powerful than Ada's scoped pointers and limited types, but they're still not powerful enough to express everything useful - cyclic structures in general are a very big hole in Rust's type system in that regard.

And then in both language, you can use unsafe when you need more power. So Rust might (and I say might, because I have no clear proof of that yet) be a tad more powerful in the safe subset, but it's not in a different class.

Re:How to speed up the Rust compiler in 2018 by dozzie on Monday April 30, 2018 @12:24PM (#16959905)
Indeed Ada has different memory management model, though equally safe.
Re:How to speed up the Rust compiler in 2018 by monocasa on Monday April 30, 2018 @12:41PM (#16960089)
I've coded in Ada. Storage pools are not as safe as Rust's affine type system. For one it's a lot easier to leak memory with Ada, since they're mainly built off of reference counting.
Re:How to speed up the Rust compiler in 2018 by moosingin3space on Monday April 30, 2018 @03:57PM (#16961708)
Pedantic: memory leaks are memory-safe, despite generally being undesirable.
Re:How to speed up the Rust compiler in 2018 by monocasa on Monday April 30, 2018 @05:15PM (#16962429)
You're totally right, but yeah, I tend to roll it in to the same category since I consider the denial of service associated with memory leaks to be as bad as stricter memory unsafety. (And to be very pedantic I said 'memory management safety', not just 'memory safety').
Re:How to speed up the Rust compiler in 2018 by pcwalton on Monday April 30, 2018 @05:23PM (#16962512)
Ada uses a garbage collector for the free store (or just uses unsafe code if it's disabled). Ada's memory management model is not really different from any other typical language.
Re:How to speed up the Rust compiler in 2018 by dozzie on Tuesday May 01, 2018 @06:19AM (#16965809)
This is the first time I've ever heard of Ada being garbage collected. Neither ARM, Barnes' nor Ben-Ari's books, nor GNAT manual say that there is supposed to be a garbage collector (quite the contrary, the books say that GC is allowed, but usually not present).

Where did you get your information from?

Re:How to speed up the Rust compiler in 2018 by exDM69 on Monday April 30, 2018 @06:02AM (#16957231)
It's the first "new" language in a long time that is viable for embedded/bare metal/kernel space, high performance and real time applications.

The memory safety concepts are novel and unique to Rust but enough has been talked about them already.

Additionally, it brings a lot of features from "advanced" programming languages (ML, Haskell) to a more mainstream language. Sum types, pattern matching, powerful macros. None of these are new or unique, but are executed particularly well in Rust.

In addition to the new features and concepts, the Rust compiler and ecosystem are well engineered and have a good amount of support.

It's the first "new" programming language in a decades worth getting excited about. Ok, maybe I was a bit excited about Julia too, but their execution is not as great as Rust's (and they have made some questionable design decisions).

Re:How to speed up the Rust compiler in 2018 by sevensor on Monday April 30, 2018 @10:24AM (#16958757)
There's also the community. I've never seen another language community built with so much deliberate effort, rather than just accreting around a project. And for a language like Rust, I think this is necessary -- with so many unfamiliar concepts and new ways to fail, it would have been very hard to get any traction without a strong community push.
Re:How to speed up the Rust compiler in 2018 by ThenAsNow on Monday April 30, 2018 @02:05PM (#16960823)
> Ok, maybe I was a bit excited about Julia too, but their execution is not as great as Rust's (and they have made some questionable design decisions).

Could you expound on this? The code I currently write and expect to write in the near-to-mid-term is numerical for engineering purposes. I have the luxury of being able to write greenfield projects, at least for now. My experience with OCaml has inculcated a deep appreciation for powerful type systems and functional styles, so Python, despite its awesome ecosystem, is not particularly of interest. Julia appears to be the natural choice in this space for new development, but I've been a little leery after reading about Dan Luu's experience a couple of years ago: http://danluu.com/julialang/

I'm interested in reasoned criticisms of Julia as it stands now, and what modern practical alternatives people have found.

Re:How to speed up the Rust compiler in 2018 by rkangel on Monday April 30, 2018 @08:17AM (#16957899)
Because Hacker news has a large population of systems programmers, and we are desperate for something to liberate us from C and C++. We have watched programming languages advance apace in other areas, helping engineers be more productive and produce a higher quality output, but in the systems space nothing has come along that provides enough benefit for a low enough adoption cost for it to be a worthwhile choice over C and C++.

Rust shows some promise of being that language, and so we hold out hope and enjoy reading about it.

Re:How to speed up the Rust compiler in 2018 by staticassertion on Monday April 30, 2018 @12:53PM (#16960187)
To give a somewhat different reason than what I'm seeing, I don't care too much about the 'memory safety plus speed' thing. I'm often building services that would be "fast enough" in Java. Is it nice to be faster? Yes, definitely, and that's part of why I write Rust, but not the whole story by any means.

I like rust for a few reasons.

* I really like Rust developers - I've met many, talked with many, and we get along and they've helped me through many technical problems, both big and small.

* I found rust extremely easy to get started with. I knew I'd have to learn the language, I did not also want to learn build tooling, package management, etc. These barriers exist in many other languages, it's frustrating because I just want to focus on programming. Cargo is excellent and I am a huge fan of how rust manages crates.

* I find it very easy to express what I want in rust, to reason about the code, etc. I know when a function might error, I know when I need to handle some unforseen case, I can express how a variable is used, when it is usable, whether it can be mutated. I can cut down on boilerplate with generics and macros.

The last point is what keeps me coming back. I find rust extremely easy to write, because it makes the things I care about easy to express.

Re:How to speed up the Rust compiler in 2018 by olavk on Monday April 30, 2018 @05:49AM (#16957176)
I find it interesting because of the novel approach to memory management. It is deterministic and zero-overhead like C, C++ and similar, while at the same time safe like garbage collected languages. I think of it like a compile-time garbage collection.

I wouldn't use it as an alternative to garbage collected languages since garbage collection is just simpler overall, but I would consider using it as a safer alternative to C or C++.

Re:How to speed up the Rust compiler in 2018 by danieldk on Monday April 30, 2018 @06:13AM (#16957288)
I wouldn't use it as an alternative to garbage collected languages since garbage collection is just simpler overall,

I do not disagree, but I think one could argue to the contrary as well.

Since most garbage collected languages do not guarantee that objects are actually (timely) garbage collected, you cannot tie the lifetime of other resources (file descriptors, sockets, locks) to object lifetimes. So, the burden is on the programmer to ensure that resources are correctly finalized. Whereas in RAII languages you can properly tie all finalization to object lifetimes.

Note: I am not arguing that GC-ed languages cannot do RAII. AFAIR D has a GC and supports RAII.

Re:How to speed up the Rust compiler in 2018 by olavk on Monday April 30, 2018 @06:26AM (#16957344)
This is true - for example, C# has the `using` block to ensure resources are deterministically released when they go out of scope, not when they at some point later are garbage collected. I would still argue C# is much simpler than Rust since for most object you don't have to worry about this. But I guess there is a certain extra complexity in C# because you actually have to know if a class owns some external resource or not, while this distinction is not necessary in Rust.
Re:How to speed up the Rust compiler in 2018 by moomin on Monday April 30, 2018 @08:15AM (#16957881)
In practice that's rarely an issue, because a) if it has a resource it'll implement IDisposable and b) my IDE screams when I don't dispose an IDisposable.

This is not as good as the Rust model, but it's not awful, either.

Re:How to speed up the Rust compiler in 2018 by olavk on Monday April 30, 2018 @08:30AM (#16957990)
Yes but that is just the compiler offloading some of the static analysis to the IDE. The difference might not matter if you are always in an IDE anyway, but the language would be safer if this was an actual compiler error.
Re:How to speed up the Rust compiler in 2018 by jerf on Monday April 30, 2018 @09:17AM (#16958306)
In most modern languages, there is some way to tie object cleanup to a scope, even for a GC'd value. Note I say "cleanup", as in "I closed the file handle" or something, not "finalization" which is a GC-specific term. It isn't necessarily as rigorous as RAII but it works in principle in much the same way. "with" in Python, for instance, "defer" in Go (less automatic but if used properly fits the 80/20 nature of Go), Haskell has a motley crew of solutions, most other languages you can put something together yourself if nothing is provided.

Where things get complicated is when you don't have a clear scope to tie lifetime to and so you can't use these, but then, that applies to RAII too.

I'm not saying C++ doesn't have a bit of an advantage here, but I think it often gets oversold as "C++ has RAII and other languages have nothing even remotely resembling it", which isn't true.

In practice this isn't a problem that I encounter in GC'd languages anywhere near often enough to justify even a slight preference for a "true RAII" language.

Re:How to speed up the Rust compiler in 2018 by danieldk on Monday April 30, 2018 @10:42AM (#16958894)
It isn't necessarily as rigorous as RAII but it works in principle in much the same way.

I would say that in principle they work very differently ;).

They work superficially in the same way in that if you tie a particular object to the current scope in a RAII language, the cleanup happens at the same point as defer, with, try-with-resource, etc. would. However, there are cases where you really want cleanup to be tied to the object's lifetime.

For example, I have a Tensorflow binding for Go. However, I cannot pass Go-allocated memory (e.g. memory allocated to a slice), because Go does not allocate slice memory on 32-byte boundaries (using Go memory would cause an allocation + memcpy in Tensorflow to align the memory). So, you allocate memory in C-land and have Go structs that wrap your pointers. However, now cleanup becomes interesting. You do not want to rely on finalizers, since they are not guaranteed to run. However, using a Close method is also an annoyance. For tensors that live for the duration of a graph run, it is fine (you can use defer), but other tensors live longer and are reused between runs, shared by models, etc. It becomes unclear pretty quickly who is responsible for closing the model.

I also use a Tensorflow binding for Rust, which is drastically more convenient in this respect. Since ownership is clear, the lifetime of a tensor is bound to the scope or object that owns it. If the owner is dropped, the tensor is also dropped. If you need to share a tensor, you make an Rc/Arc the owner.

Re:How to speed up the Rust compiler in 2018 by jerf on Monday April 30, 2018 @10:54AM (#16959022)
Well, to be honest, my position has consistently been that using Go for scientific programming is not a good idea, and will never be a good idea because the Go team is never going to give you the features you need for it, and that you probably should just use Rust. (Or something else. Rust is not the only choice.) The Go answer is probably that, yes, you need a .Close method, and yes, I agree that in this use case that's really annoying and I would suggest this argues against using Go for this.

People tend to then get annoyed at me for expressing this opinion, but this sort of thing is the reason why. Go is really only merely adequate at interfacing with libraries in other languages [1] which scientific programming does a lot of, and Go has a type system that seems almost precisely tuned to get in your way if you try to program mathematical code in a typed manner but at the same time isn't so weak that you can pull something like a NumPy where at the Python level everything is just untyped so as long as you assemble it correctly up there, the C level can work it all out. Nor can you practically program in that manner, because while you can slather interface{} everywhere, you can't make it convenient to work with like a dynamically-typed language. I think Go is approaching maximally pessimal for scientific-type programming, personally.

I should clarify that when I say Go has "something like" RAII, I do mean pure-Go code only. And by no means is "defer" perfect. (I'm definitely in the camp that it should have been block scoped, not function scoped, and the performance hit can be quite annoying.) It's just that, as I said, it's not like the choice is "either RAII or you're in some manual-management only horrorland"... lots of languages have block-scoped constructs (not just Go) that can be used to 80/20 RAII. That last 20 may be important in some cases, but it's quite often a great deal less important than the 80.

(This post is brought to you by your friendly local "HN poster who has been accused of being unreasonably positive about Go".)

[1] Pretty much every modern language claims to have "great" interfacing with C, despite IMHO wild variances in difficulty. Go is "adequate" because it's not too difficult to simply call a C function, and with not much labor you can get binary-level-compatible structs between the two, which is a nice advantage over Python or Perl or something. But the semantic mismatch is pretty rough around memory management and threading model, and that manifests in slowness in the calls in addition to general semantic mismatch.

Re:How to speed up the Rust compiler in 2018 by mratsim on Thursday May 03, 2018 @04:40AM (#16984293)
Rust is better than Go for sure (cough Generics) but it's already hard enough to fight the mathematics, statistics and machine learning, scientists will not want to fight the Rust syntax as well.

For me, the most promising compiled and statically-typed language for scientific computing is Nim.

Disclaimer: I am the author of a Numpy/Torch/Tensorflow-like library written from scratch in pure Nim, the look and feel is pretty similar to Python Pytorch + Keras for neural networks: https://github.com/mratsim/Arraymancer

Re:How to speed up the Rust compiler in 2018 by danieldk on Monday April 30, 2018 @11:13AM (#16959241)
Well, to be honest, my position has consistently been that using Go for scientific programming is not a good idea, and will never be a good idea because the Go team is never going to give you the features you need for it, and that you probably should just use Rust. (Or something else. Rust is not the only choice.) The Go answer is probably that, yes, you need a .Close method, and yes, I agree that in this use case that's really annoying and I would suggest this argues against using Go for this.

That's a good point. Go was my camping ground while Rust was still breaking every month and I didn't want to go back to C++. Although I don't use Go anymore, I have come to appreciate its simplicity and in a lot of scenarios I would definitely recommend it.

Re:How to speed up the Rust compiler in 2018 by Const-me on Monday April 30, 2018 @02:40PM (#16961099)
> So, you allocate memory in C-land and have Go structs that wrap your pointers. However, now cleanup becomes interesting. You do not want to rely on finalizers, since they are not guaranteed to run.

I did similar thing with C# more than once. Not with TensorFlow, but with my only C++ libraries that also used SIMD and therefore required aligned memory buffers.

It worked just fine. There’s IDisposable for deterministic cleanup, and finalizers as a safety net. Unmanaged interop, i.e. [DllImport], is supported on all platforms, e.g. on Linux it imports from *.so libraries.

Re:How to speed up the Rust compiler in 2018 by kazagistar on Monday April 30, 2018 @10:42AM (#16958899)
> Where things get complicated is when you don't have a clear scope to tie lifetime to and so you can't use these, but then, that applies to RAII too.

Sure, but Rust does help here specifically: resources can safely be moved into child or parent scopes.

Re:How to speed up the Rust compiler in 2018 by Const-me on Monday April 30, 2018 @11:44AM (#16959559)
> I would consider using it as a safer alternative to C or C++

I would, too. But there’re problems for which C or C++ is just faster because of language/compiler extensions like SIMD intrinsic or OpenMP.

Also Rust can’t be used for GPU code; strictly speaking C can’t either, but practically CUDA, C++ AMP, OpenCL are very close to C and/or C++.

Also if you have to deal with lots of pointer-based data structures (trees, graphs, etc)., and it’s not just on the lowest level you can abstract away behind a safe API, I don’t think Rust is safer. To get performance comparable to C++, it’s necessary to use unsafe rust for raw pointers, and IMO modern C++ is safer that unsafe Rust.

Re:How to speed up the Rust compiler in 2018 by pcwalton on Monday April 30, 2018 @05:26PM (#16962551)
How is modern C++ safer than unsafe Rust?

In Rust, the borrow check is still active even in unsafe blocks. In C++, however, the complex rules around when destructors are called, combined with references, are a constant use-after-free footgun that you can never eliminate.

Rust projects that use unsafe code are empirically safer than C++ projects. See, for example, the Servo style system as used in Firefox.

Re:How to speed up the Rust compiler in 2018 by Const-me on Tuesday May 01, 2018 @04:37AM (#16965424)
> the borrow check is still active even in unsafe blocks

When you deal with pointer-based structures (trees, graphs, etc.) you’ll use raw pointers for them. Raw pointers are not borrow checked, and the complete list of pointer-related potential bugs applies to unsafe Rust, you can use after free, double free, mess with pointer arithmetic so you’re out of bounds, etc.

> In C++, however, the complex rules around when destructors are called, combined with references, are a constant use-after-free footgun that you can never eliminate.

C++ ecosystem has lots of stuff that help writing correct code despite unsafe language. Debug builds use special version of heap that fills freed memory with a magic number, this help to catch most UAF bugs very early in the development. There’re runtime tools like valgrind and asan. There’re static analysis tools like PVS studio, clang static analyzer, and coverity.

Unsafe Rust has none of them. Not even a debug heap.

> Rust projects that use unsafe code are empirically safer than C++ projects.

Survival bias: people who need raw pointers and other performance-related features like SIMD and manual RAM layout don’t pick Rust for their projects.

Re:How to speed up the Rust compiler in 2018 by pcwalton on Tuesday May 01, 2018 @11:50AM (#16968095)
> Unsafe Rust has none of them. Not even a debug heap.

Sure it does! I've used most of those features in Rust, except for Address Sanitizer. But even ASan is available now: https://github.com/rust-lang/rust/pull/38699

I remember spending hours using Valgrind on Rust code back in 2011 to track down codegen problems in the compiler :)

Re:How to speed up the Rust compiler in 2018 by burntsushi on Tuesday May 01, 2018 @06:49AM (#16965950)
Respectfully, you're missing one of the most important parts of Rust. Rust isn't just about reducing or eliminating the use of `unsafe`, it's the ability to build an API that might use `unsafe` internally but is safe to use externally. You can't do that with C++.

I also think many of your points over generalize. Finite state machines are graphs for example, but I've never needed to use raw pointers to achieve the performance required. Similarly, I definitely need SIMD, and I use Rust for that.

Re:How to speed up the Rust compiler in 2018 by Const-me on Tuesday May 01, 2018 @08:00AM (#16966288)
> You can't do that with C++

I can, and I do. The trick is to use some other safer language for less performance critical higher level code. C# often works well for me but there’re others, e.g. in data science community Python is quite popular for that role.

> I've never needed to use raw pointers to achieve the performance required.

Very likely, we work on different kinds of projects. One of my ongoing project is a CAD/CAM app for Windows, and I have implemented quite a lot of pointer-based stuff to optimize the performance. Technically they are mostly graphs, logically they’re multi-level hierarchical containers, LRU caches, quad-edge structures, scene trees, external indices, etc.

P.S. Why do you think Mozilla doesn’t use Rust for their DOM tree implementation, and instead relies on the JavaScript runtime and it’s GC? Don’t you think sometimes other people might also want DOM-like structures in their apps, be it for a web page, XML document, objects hierarchy in 3D space, or any other kind of data?

Re:How to speed up the Rust compiler in 2018 by burntsushi on Tuesday May 01, 2018 @10:13AM (#16967156)
You're just moving the goalposts. Pretending an entire language barrier is the same as the barrier between Rust's safe/unsafe is kind of ridiculous. The friction for use is on a completely different scale, not only in terms of convenience but performance as well. For example, a regular expression library might use unsafe internally, but forcing every use of that library to operate in a higher level language to achieve safety is simply a non-starter.

> Very likely, we work on different kinds of projects.

I work heavily with finite automata. Similar libraries written in C or C++ use pointer based stuff quite heavily, but none of it has so far turned out to be necessary in Rust while also achieving comparable performance.

This continues to miss the point that Rust permits building safe abstractions over unsafe internals. Even if you need to use raw pointers in Rust, you're not only no worse off than you are in C++, but you can actually encapsulate that use in a way that is guaranteed by the type system without resorting to using a completely different programming language.

> Why do you think Mozilla doesn’t use Rust for their DOM tree implementation

I'm not involved with that project, so I wouldn't know, and I wouldn't speculate. You shouldn't either.

Re:How to speed up the Rust compiler in 2018 by Const-me on Tuesday May 01, 2018 @06:40PM (#16972407)
> Pretending an entire language barrier is the same as the barrier between Rust's safe/unsafe is kind of ridiculous.

I’m not pretending that. Just two points.

1. If you really need unsafe code, because raw pointers, or other reasons, C++ is safer than unsafe Rust.

2. If your project has two distinct parts, unsafe lower level, and safer higher level, you don’t need to use C++ for both. Real world software use multiple languages in the same project for decades already, e.g. QuakeC was developed in 1996.

> a regular expression library might use unsafe internally

If a library wants to do that, it probably means that safe language is too slow :-) https://github.com/dotnet/corefx/tree/master/src/System.Text...

> I work heavily with finite automata.

I’m not saying Rust is useless. There are projects where it shines, and where I’d probably picked it myself. Like a web browser CSS engine, or your finite automata, or many other things.

I’m saying that there’re large problem areas out there for which, due to various reasons, other languages are still way better than Rust. I do realize Rust evolves fast; eventually these areas might shrink or disappear. But in its current state, my opinion is the applicability is limited to very narrow areas: no bare metal, no SIMD, no GPU APIs, very limited asynchronous IO, limited embedded options, very limited numeric libraries, no GPGPU…

I’ve only listed the areas where I have recently (last couple of years) developed substantial amount of code in any other language.

It just happened that I didn’t work on either finite automata, nor browser CSS engines.

Re:How to speed up the Rust compiler in 2018 by burntsushi on Wednesday May 02, 2018 @07:30AM (#16975909)
> If you really need unsafe code, because raw pointers, or other reasons, C++ is safer than unsafe Rust.

I don't agree. I've told you why. I find speaking with you very frustrating, and it's not clear to me that you've actually understood my point unfortunately. :-/

> If a library wants to do that, it probably means that safe language is too slow

That doesn't make any sense.

Re:How to speed up the Rust compiler in 2018 by Const-me on Wednesday May 02, 2018 @07:17PM (#16981992)
> I find speaking with you very frustrating

Yeah, same here. You’re insinuating things I didn’t said nor meant.

> it's not clear to me that you've actually understood my point

I disagree with your points, and I've told you why.

Re:How to speed up the Rust compiler in 2018 by littlestymaar on Wednesday May 02, 2018 @04:08AM (#16974985)
> P.S. Why do you think Mozilla doesn’t use Rust for their DOM tree implementation, and instead relies on the JavaScript runtime and it’s GC? Don’t you think sometimes other people might also want DOM-like structures in their apps, be it for a web page, XML document, objects hierarchy in 3D space, or any other kind of data?

Nothing prevents you from writing a DOM tree in Rust, but when in comes to the Web DOM you need to interact with JavaScript and with the JS GC no matter what you do. How is DOM managed in other browsers written in C++ ? I would be surprised if it wasn't also handled by the JavaScript runtime.

Re:How to speed up the Rust compiler in 2018 by steveklabnik on Monday April 30, 2018 @12:02PM (#16959720)
SIMD is coming in eight weeks, incidentally.
Re:How to speed up the Rust compiler in 2018 by Const-me on Monday April 30, 2018 @01:36PM (#16960553)
Good to know!

But even if it’ll become available in 2 months, it’ll take some time to develop Rust libraries on top of them.

E.g. in various performance-critical C++ projects I have used https://github.com/Microsoft/DirectXMath and https://eigen.tuxfamily.org

Both are quite large projects with many man-years spent to develop, they saved quite a lot of my development budget.

Re:How to speed up the Rust compiler in 2018 by steveklabnik on Monday April 30, 2018 @02:38PM (#16961089)
Yes and no, a lot of libraries have been built on top of the feature while it was unstable. It’s been in nightly for quite a while at this point.

Of course, more libraries are needed as well, but there’s already some higher level stuff. See https://github.com/AdamNiederer/faster for example. And const generics, coming to nightly near the end of the year, will be another step up. It's true overall that numeric stuff is a weakness, but we'll get there!

Re:How to speed up the Rust compiler in 2018 by SomeHacker44 on Monday April 30, 2018 @12:26PM (#16959937)
> It is deterministic and zero-overhead

I wouldn't say zero-overhead. I would say O(1) overhead in the best case, and equivalent to C-style manual memory management in the typical (which again isn't zero-overhead and isn't even necessarily always O(1) overhead with heavy allocation and deallocation).

But, yes, it isn't GC'd with the attendant challenges GC poses (or benefits it brings).

Re:How to speed up the Rust compiler in 2018 by yitchelle on Monday April 30, 2018 @05:43AM (#16957142)
Because it is has the potential to unseat C as the go to language for deeply embedded code. The safety aspect of Rust is quite compelling for Functional Safety applications in automotive, medical and aerospace domain. I can't wait for it to mature and be mass adopted.
Re:How to speed up the Rust compiler in 2018 by MikkoFinell on Monday April 30, 2018 @10:10AM (#16958675)
Are there any studies done that looks at the relative amount of bugs in C code compared to Rust? Making the claim that Rust is better for those applications isn't convincing to me until I can see the statistics that backs it up.
Re:How to speed up the Rust compiler in 2018 by staticassertion on Monday April 30, 2018 @02:56PM (#16961231)
I think you'll have a hard time finding conclusive research like this for any languages.

Many papers exist but often have conflicting results, or weird methodologies, or extreme artificiality. It's really expensive/ hard to generate good research on this topic that controls for the big variables - you basically need a company that's willing to throw away at on of developer time to build two versions of the same product in both languages, then a metric for measuring success, a way to ensure you take dev skill into account, etc.

So instead it seems a lot more worthwhile to not bother looking for objective research as it won't be found.

I think a better approach is to just use what we have - sense and anecdotes.

From a sensibility standpoint, let's take a step back from rust.

Do we expect fewer memory safety vulnerabilities in Java vs C? Probably yes - Java is a memory safe language with few escape hatches.

So what about Rust vs C? It's a bit less clear as rust has a more oft used escape hatch, but I think we can reason that it's likely to have fewer memory safety bugs.

Would we expect fewer bugs in general? That's much harder to discuss with that approach.

You can look at testaments from Servo devs, and other companies using Rust ( https://www.rust-lang.org/en-US/whitepapers.html ) and their experiences.

Re:How to speed up the Rust compiler in 2018 by pcwalton on Monday April 30, 2018 @05:27PM (#16962566)
We looked at the number of security-critical bugs in one new component of Firefox—Web Audio—a few years ago in order to determine how many of them a memory-safe language would have prevented. The answer was 100%.
Re:How to speed up the Rust compiler in 2018 by yitchelle on Tuesday May 01, 2018 @07:47AM (#16966220)
Pardon for ignorance, what language is Firefox written in?
Re:How to speed up the Rust compiler in 2018 by steveklabnik on Tuesday May 01, 2018 @01:20PM (#16969085)
At the time the analysis was done, the majority was in C++. Now there are some significant Rust components.
Re:How to speed up the Rust compiler in 2018 by oconnor663 on Monday April 30, 2018 @10:49AM (#16958963)
Apart from all the other things people are mentioning, I'd add that the development of Rust happens in the open. That means that a lot of very interesting debates are there on GitHub for everyone to read. For example, here's where arielb1 discovered that the original scoped threads design was unsound: https://github.com/rust-lang/rust/issues/24292 (which sparked a large debate about whether mem::forget should be allowed in safe code: https://github.com/rust-lang/rfcs/pull/1066).
Re:How to speed up the Rust compiler in 2018 by codetrotter on Monday April 30, 2018 @09:59AM (#16958595)
The promises about memory safety was what initially made me interested in it. When it turned out that it was actually possible to learn, it was comfortable to write for someone with Python and C/C++ experience like me, and I saw Cargo and that the ecosystem of packages was quickly growing is when I fell in love with it.
Re:How to speed up the Rust compiler in 2018 by jannes on Monday April 30, 2018 @05:31AM (#16957080)
Probably because of its memory safety, which enables easier parallelisation of workloads among other things.
Re:How to speed up the Rust compiler in 2018 by MikkoFinell on Monday April 30, 2018 @05:44AM (#16957147)
Couldn't you achieve the same thing in C++ by using message passing between threads instead of shared memory? That way, you would get safe parallelisation without having to fight the borrow checker in every part of the program. I understand that having safety statically enforced at compile time is a real gain in terms of eliminating that class of bugs. However, the mental cost a Rust programmer pays for that trade (due to borrow checker) seems too high for me if you can get the same thing simply by shifting your programming patterns slightly.
Re:How to speed up the Rust compiler in 2018 by danieldk on Monday April 30, 2018 @06:03AM (#16957237)
Couldn't you achieve the same thing in C++ by using message passing between threads instead of shared memory?

I know that the parent post used multi-threading as an argument in favor of Rust. But there are many ways to blow of your foot in single threaded C++. For example, consider this single-threaded code:

    std::vector<size_t> v;
    v.push_back(1);
    size_t *first = &v[0];

    std::cout << *first << std::endl;

    // The STL vector implementation will probably
    // reallocate the backing array at least once.
    for (size_t i = 2; i < 1000; i++)
      v.push_back(i);

    std::cout << *first << std::endl;
You wouldn't be able to introduce the same error in Rust. Once you borrow the an element of a Vec immutably, you cannot create mutable borrows during the lifetime of any immutable borrows. So the compiler would reject pushing new elements.

However, the mental cost a Rust programmer pays for that trade (due to borrow checker) seems too high for me

The thing is that most of the errors that the borrow checker will point out are potential programming errors in C or C++ as well. However, current C/C++ compilers will put most of the responsibility completely on you (plus tools like Valgrind). So, to me C++ has at least the same cognitive load if you want to program responsibly.

Re:How to speed up the Rust compiler in 2018 by rtpg on Monday April 30, 2018 @08:11AM (#16957858)
I agree with the general principle, but programming in Rust is not "program in C++, then fix errors". You really need to lay your code in away that will satisfy the checkers. That or jump into unsafe mode.

A good example of the challenge is that there's unsafe inner code in rusts own container code. If you try to build your own custom containers (or things like arenas) you'll likely work with unsafe code... Or rely on rusts container code (not a bad thing of course).

My feeling is that "C to Rust" is close to "Java to Haskell" more than anything else. The extra layers are important enough that they need a new thought process. (I say this as a proponent of rust)

Re:How to speed up the Rust compiler in 2018 by xfer on Monday April 30, 2018 @10:13AM (#16958701)
Same thing is also true in C++, the stdlib also uses "unsafe" pointers inside, but you can use unique, shared etc.

> You really need to lay your code in away that will satisfy the checkers.

There are some patterns that are common but problematic but are being addressed by non-lexical lifetimes. Other than that it's almost "program in C++, then fix errors".

Re:How to speed up the Rust compiler in 2018 by danieldk on Monday April 30, 2018 @11:08AM (#16959169)
You really need to lay your code in away that will satisfy the checkers.

But that becomes a second nature after a while. I think all the edge cases that still exist make it more problematic. E.g. I was writing some SIMD code yesterday with a loop somewhat like this (simplified):

    let mut v = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
    let mut s: &mut [f32] = &mut v;
    
    while s.len() >= 2 {
        println!("{:?}", s);
        s = &mut s[2..];
    }
Playground: https://play.rust-lang.org/?gist=104348b0edb96ca0f68d701373e...

It makes you scratch your head for a bit.

A good example of the challenge is that there's unsafe inner code in rusts own container code.

I am pretty proud that one of my first small Rust projects was a randomized ternary trie. Apparently, it does not use unsafe anywhere.

https://github.com/danieldk/rtrie/blob/master/src/ternary.rs

Not that I am proud of the code ;).

But in all seriousness, unsafe in container code is somewhat expected, because at some point you need to wrap raw memory (as e.g. in Vec). I think quite a bit of, but probably not all, unsafe use in containers such as Vec comes from that.

Re:How to speed up the Rust compiler in 2018 by stefs on Monday April 30, 2018 @07:09AM (#16957556)
> However, the mental cost a Rust programmer pays for that trade (due to borrow checker) seems too high for me if you can get the same thing simply by shifting your programming patterns slightly.

i remember reading about the stylo (multithreaded css styling) engine, something that has been tried times and times again to implement it in C++ without success: too complicated. sooner or later you'll get too-hard concurrency bugs and the project would be abandoned. and it wasn't just mozilla with firefox, google also failed to implement concurrent styling with chrome.

the blog post stated that this time they were successful _only because of rust_. the mental overhead of managing the borrow checker is far lower than the mental overhead of dealing with concurrency issues in a complex high performance project.

Re:How to speed up the Rust compiler in 2018 by Ygg2 on Monday April 30, 2018 @06:06AM (#16957260)
Mozilla was full of talented C++ programers.

They thought it worthwhile to invent a new safer language for massive parallelism and security, rather than to attempt it in C++.

Also coming from Java, the Rust experience is not that painful. It's like learning a completely foreign language.

Re:How to speed up the Rust compiler in 2018 by unrealhoang on Monday April 30, 2018 @06:12AM (#16957287)
I think you misunderstood Rust. There’s no additional mental cost compared to C++. In C++ you must do thing the same way (keep track of references, variable lifetimes) in order to write any sane program. Rust just help you to declare those things and ask the compiler to enforce it. And no, message passing is not the savior to parallelisation.
Re:How to speed up the Rust compiler in 2018 by sirclueless on Monday April 30, 2018 @06:30AM (#16957357)
There is definitely some mental cost. By making lifetimes explicit there are additional barriers in the way of doing certain things that are safe but involve invariants that are too high-level for rust's semantics. For example, taking mutable references to multiple elements of a container simultaneously.
Re:How to speed up the Rust compiler in 2018 by unrealhoang on Monday April 30, 2018 @06:52AM (#16957469)
.split_at_mut(), there you go. But I understand that there are cases when Rust rejects correct program, that is where we need unsafe to build safe abstraction. Come back to additional mental cost, it’s just the same debate between static & dynamic typed language. Either you write more, specify constraints, and have the usage checked or you write less, imply your constraints and must satisfy the constraints of usage by yourself (or with helper tools/tests). To me that’s just “when” I have to spend the mental resource, and the total cost is roughly the same. But then, knowing the separation helps to choose which tool for which type of project.
Re:How to speed up the Rust compiler in 2018 by sirclueless on Monday April 30, 2018 @07:49AM (#16957745)
I don't think this is just about being more or less verbose. It's about the awkward ways it contorts the ways you write programs. For example, in C++ you might write an asynchronous job scheduler with an API like the following:

void Scheduler::schedule(const Job& job, Result* result);

void Scheduler::wait();

The consumer of this API in C++ has an easy job. They can create an array of results and iteratively call schedule(jobs[i], &results[i]) for each job, and then call wait(). A similar API in Rust would be a giant pain in the neck to use, because there's no simple way to collect the results. You'd likely want to scrap this API entirely and have Scheduler expose some kind of queue or something.

My point is that these extra constraints are not just extra typing locally to specify how you're using lifetimes. You'll likely have to rethink the way you write APIs and whole programs in Rust because of the ways it restricts mutability. Which is OK, it's a trade-off, all I'm saying is the safety doesn't come for free.

Re:How to speed up the Rust compiler in 2018 by GolDDranks on Monday April 30, 2018 @12:12PM (#16959803)
While there might be all kinds of troubles _implementing_ that API, I don't think it wouldn't be that hard to use. You would need to have a valid "not ready" state for the results, because Rust requires that they are in some state at the moment they are constructed. From the lifetime perspective, the data structure where the results live should outlive the schedule calls – but that isn't a problem if you construct the array first. There will be a lifetime requirement but that's it.

The mutability thing isn't a problem. You can allocate a vector of results and jobs, and then have a mutable iterator over them, zip them together and then iterate over that. There's no problem passing mutable references to each of the elements.

Re:How to speed up the Rust compiler in 2018 by sirclueless on Monday April 30, 2018 @12:55PM (#16960200)
The problem is that schedule() needs to mutate result asynchronously at some point in the future. It can't do this if result is a mutable reference, since it needs to return immediately so borrowing a reference doesn't work. It also can't take ownership of result, since it has no way to give it back (short of changing the API, for example by making wait() return a collection of results).

The right way to implement the API above is for schedule() to take Arc<Mutex<Result>>, and explicitly share mutable ownership over each individual result between some unspecified asynchronous execution mechanism and the caller of schedule(). This makes the calling code significantly more complicated as it needs to incur the overhead of atomic reference counting and a mutex per result, and must try to lock each result before using it, even if it knows there are no other owners of the result due to wait() returning.

Re:How to speed up the Rust compiler in 2018 by GolDDranks on Tuesday May 01, 2018 @01:51AM (#16964840)
I don't see the problem with returning immediately after borrowing a reference, if the scheduler lives shorter than the results (if it doesn't, holding the reference would be unsound): https://play.rust-lang.org/?gist=226f92bc311dbac05c112b10ba4...
Re:How to speed up the Rust compiler in 2018 by sirclueless on Tuesday May 01, 2018 @03:09AM (#16965095)
You're exclusively borrowing res_a, res_b and res_c for the lifetime of the scheduler. Which works fine since res_a, res_b and res_c are hard-coded variables with separate lifetimes. What rust doesn't know how to do is borrow mutable references to elements of a container without borrowing the entire container.

https://play.rust-lang.org/?gist=1324a919ca5d0e2f16e445364a7...

Re:How to speed up the Rust compiler in 2018 by GolDDranks on Tuesday May 01, 2018 @11:27AM (#16967834)
This can be made to compile by using iterators: https://play.rust-lang.org/?gist=33d86898c4d16bf9bc9023a9c9a...

Rust also offers some other methods to allow multiple mutable references to containers: .split_mut() comes to mind – that splits a mutable slice into two mutable slices that don't overlap. In the future I'd like to see in the stdlib "container adapters" that take in a normal container and provide an interface to it that allows taking multiple mutable references while ensuring the soundness using dynamic checks (it can keep an array of the pointers or indexes that are borrowed out, and check against that). I created such an interface as an experiment last year: https://github.com/golddranks/multi_mut

Re:How to speed up the Rust compiler in 2018 by unrealhoang on Wednesday May 02, 2018 @11:27PM (#16983141)
The sibling comment shows how to do that in safe Rust code. But then, even when you have much more complex control that Rust compiler can not prove safety, you can still resort to unsafe, build your algo, and wrap it into a safe API, just like `split_at_mut`
Re:How to speed up the Rust compiler in 2018 by steveklabnik on Monday April 30, 2018 @06:35AM (#16957387)
This cuts both ways. Because I can offload checking from my brain to the compiler, I feel personally that the mental cost is actually reduced overall. YMMV.
Re:How to speed up the Rust compiler in 2018 by edflsafoiewq on Monday April 30, 2018 @03:40PM (#16961570)
IMO the cost is worth it for the documentation alone. What lifetime a callee expects me to uphold for the arguments I pass is very often a mystery on which the docs are absolutely silent in C/C++. In Rust, it's part of the type signature and enforced by the compiler, so I can always read it off at a glance. This is a huge win in reading a new API.
Re:How to speed up the Rust compiler in 2018 by empath75 on Monday April 30, 2018 @07:14AM (#16957581)
If you’re sure they’re safe then just put them in an unsafe block and wrap that in a safe api.
Re:How to speed up the Rust compiler in 2018 by exDM69 on Monday April 30, 2018 @05:56AM (#16957202)
> However, the mental cost a Rust programmer pays for that trade (due to borrow checker) seems too high for me

In C++ land, you'd have to use TSan thread sanitizer and a lot of other tooling (ASan, Valgrind, etc) to achieve even close to the same level of confidence. Not only is this a runtime check but all that tooling has a fairly heavy mental cost too.

Re:How to speed up the Rust compiler in 2018 by heinrich5991 on Monday April 30, 2018 @05:48AM (#16957173)
No, you can't. It's either performance or bugs – look at the big C++ projects.
Re:How to speed up the Rust compiler in 2018 by throwajay79367 on Monday April 30, 2018 @12:37PM (#16960056)
What I find an even more interesting is that every story about rust have posts whining about hn posts about rust. this is such a boring, ever-present “question” that i don’t actually believe you asked it honestly.
Re:How to speed up the Rust compiler in 2018 by catach on Tuesday May 01, 2018 @05:49PM (#16972043)
Seems to me that Rust's current point on the popularity curve suggests that the vast majority of programmers probably don't know much at all about the lang, or even that it exists. Busy people can note that there's plenty of HN threads about a thing without investigating further. Until they finally do.

Better to be charitable, I think. Doing so costs us nothing.

Re:How to speed up the Rust compiler in 2018 by coffeeacc on Monday April 30, 2018 @06:12AM (#16957286)
Has it appeared more often than eg Go?
Re:How to speed up the Rust compiler in 2018 by swsieber on Monday April 30, 2018 @09:34AM (#16958441)
I think go used top appear more often than rust (maybe as often as rust does now), but I think it's started appearing less frequently.
Re:How to speed up the Rust compiler in 2018 by DC-3 on Monday April 30, 2018 @05:44AM (#16957154)
Have you tried it? If you have - why do you think it shouldn't be as popular as it is? If not, perhaps in using it you will discover why it is popular.
Re:How to speed up the Rust compiler in 2018 by majewsky on Monday April 30, 2018 @07:12AM (#16957573)
I sort of agree, but trying everything that's new and popular just doesn't scale. At some point, everyone needs to get on with their life.
Re:How to speed up the Rust compiler in 2018 by AnIdiotOnTheNet on Monday April 30, 2018 @07:49AM (#16957746)
Maybe I'm getting old and cynical, but the fact that something is both new and popular makes me even more reluctant to try it. The commons seem to be really good at picking mediocre-at-best winners, and fad chasing is really common.
Re:How to speed up the Rust compiler in 2018 by Retra on Monday April 30, 2018 @09:21AM (#16958335)
Yes, but "mediocre" is not measurable on an absolute scale. If you're trying to obsolete 50-year old technology, today's mediocre technology is probably good enough.

Rust is a fairly conservative language. It doesn't really do anything novel, it mostly just synthesizes patterns that have existed for years. Hopefully Rust truly is mediocre (at least in hindsight). That would mean the things it is attempting to replace are seen for how primitive they truly are.

Re:How to speed up the Rust compiler in 2018 by GolDDranks on Monday April 30, 2018 @12:21PM (#16959883)
Sorry for a moot comment but.

This is so well said that I agree 100%, and couldn't say it any better.