News for hackers. Stuff that matters.
Re:Facebook puts bounties on bugs in the D programming langu... by jnbiche on Friday November 15, 2013 @06:56PM (#6742887)
>Could you elaborate?

A major source of complexity, in my opinion, are the different pointers: owned pointers, managed pointers, borrowed pointers (mutable and immutable), each with its own syntax and rules for use. And all three seem to be everywhere. I actually understand pointers in C (mostly!), yet I struggle to remember all the use cases for pointers in Rust. Here's the tutorial on just borrowed pointers: http://static.rust-lang.org/doc/master/tutorial-borrowed-ptr... I'm sure I could understand learn the rules given some time, but now that I've played around with D and Nimrod, I'm wondering why I should. I can get excellent performance without using pointers, yet I can access a pointer if I absolutely need one.

>So I don't think you can really make an unqualified statement like that.

I agree that unqualified statements about the relative performances of language implementations are tenuous, and so I retract that statement. But it's clear that Nimrod can reach ballpark C++/Rust/Go speeds, even without GC specifically turned off, based on both my own usage and this benchmark:

1. http://togototo.wordpress.com/2013/08/23/benchmarks-round-tw...

Now, it's quite possible that we're not getting optimal performance out of Rust because we're not writing idiomatic Rust, but this hurdle is at least partly a function of my first point.

EDIT: I should add that I think Rust may well find itself in a very strong position among systems and embedded programmers, given the fine control and safety it offers. But for your average programmer just looking for a faster language to use when Python or Ruby won't suffice, Nimrod (and D with shared library support) is a very nice alternative.

Re:Facebook puts bounties on bugs in the D programming langu... by pcwalton on Friday November 15, 2013 @07:18PM (#6742957)
> I'm sure I could understand learn the rules given some time, but now that I've played around with D and Nimrod, I'm wondering why I should. I can get excellent performance without using pointers, yet I can access a pointer if I absolutely need one.

Because they let you avoid garbage collection and data races while remaining safe.

If you're just starting to use each language, then having just one, globally garbage collected type, will seem to make everything simpler. And benchmarks of numerics will show that hey, it doesn't seem to matter what your memory story is. But in my experience those who have struggled with garbage collection pauses or data races come to appreciate the ability to declare the ownership semantics at a fine-grained level. Large, production-quality, performance-critical software in Java, for example, very frequently starts running into issues with the garbage collector. And I don't think I need to go into the headaches of sorting out data races.

Last I looked, Nimrod in particular loses all memory safety once you share objects between threads. (I hear this is changing though; I'm interested to see what they come up with.) Go loses some memory safety around maps and slices if GOMAXPROCS>1. D remains memory safe in @safe code, but at the cost of concurrent, stop-the-world garbage collection. None of these languages offer support for avoiding data races at compile time. Those decisions have real costs (as well as benefits; they're all tradeoffs).

It's very easy to brush off features like safe manual memory management with "I don't need that feature in some other language, why would I need it here?" But everything you've posted has not indicated any understanding of why Rust has smart pointers. If you think GC, data races, or safety are not worth solving at a language level (which, to be clear, is a position that reasonable people can take!) then argue that instead of handwaving around pointer type complexity. I don't mind if you like Go/Nimrod/D better than Rust—they're all fine languages and I have great respect for their creators—but be informed with your criticisms.

> But it's clear that Nimrod can reach ballpark C++/Rust/Go speeds, even without GC specifically turned off, based on both my own usage and this benchmark:

This is a perfect example of how single benchmarks can be misleading. First of all, that benchmark was found to be mostly testing the performance of the random number generator, which is cryptographically secure by default in Rust and not in other languages. Second, that benchmark probably never even triggers the GC in any of the languages. It's totally numeric-bound. Try a benchmark of arena allocation, for example. Or compare max pause times.

Re:Facebook puts bounties on bugs in the D programming langu... by jnbiche on Friday November 15, 2013 @08:03PM (#6743107)
>Because they let you avoid garbage collection and data races while remaining safe.

Yes, and as I wrote, I think there's a very significant place for Rust among embedded and systems programmers. But for someone who's just looking for a fast alternative to C, Nimrod has been quite nice.

> ...handwaving...handwave....

I was trying to give you the specifics you asked for, not handwave. I don't think I could have answered your question any clearer. And I don't think pointing out the complexity inherent in 3 different pointer types is handwaving. It's a very specific statement.

>...but be informed with your criticisms

You asked me to elaborate on my criticisms, and then you criticize my criticisms? Look, I understand that Rust is your baby, and apologies if I've treated it unfairly, but why ask for why I found Rust complex if you're just going to discount it?

To be clear, I'm talking from the perspective of an intermediate-level programmer, with a couple years of experience, who taught himself to program in his 30s. I can certainly see the value of the design choices you've made for an expert programmer like yourself, with many years of experience, who can benefit from the kind of fine control Rust provides. But to someone like me, who's just looking for some caveman-level (but very significant) speedup from Python, and something I can call from Python, Nimrod has proven more than adequate and a whole lot easier to use than C/++.

>This is a perfect example of how single benchmarks can be misleading

So to be clear, are you saying Nimrod can't reach ballpark C/Rust/D/Go speeds?

EDIT: Wow, I've made comments critical of Apple and Google and not gotten as many downvotes as I'm getting here. But just to be clear, I'm not at all being sarcastic when I say "expert programmer". I'm aware of that pwalton is a very talented programmer and language designer.

Re:Facebook puts bounties on bugs in the D programming langu... by pcwalton on Friday November 15, 2013 @10:50PM (#6743521)
I don't disagree with you that if you're looking for a fast language that integrates well with Python, then Nimrod may be a great choice. Pervasive GC certainly makes the language easier, with a performance cost that can be totally reasonable in many scenarios.

I do think that there are applications for which GC will always be slower than alternative systems such as arena allocation that Rust provides safe support for. (As an extreme example, the binary-trees shootout benchmark.) A language that does not provide safe manual memory management will lose in either performance or safety for these applications. I prefer not to make statements like "GC is slower than manual memory management", since there are many applications for which this is not true (for example, the level generation benchmark). Rather, I'd say that manual memory management provides a level of control that can allow skilled programmers to write applications that outperform those in languages with a "one size fits all" memory management scheme.

Re:Facebook puts bounties on bugs in the D programming langu... by sandGorgon on Saturday November 16, 2013 @12:20AM (#6743743)
you may choose to go the C++ STL way for a wildly usable subset.

what I mean is this - we all knew that the rb tree implementation of stl wasn't that hot, neither was its sort (note - this is 7 years back), however that library enabled a c++ project to be jumpstarted in significantly less time than building everything from scratch.

as a language creator, you may not want to touch the design choices you made and make it more "accessible" for a simpler use case - as the previous poster wrote, upgrading from python.

however, you could potentially expose an accessible subset of the language as a standardised library. of course, this may lead to language rust (!!) at scale, but I would argue that its a good problem to have then.

I would be in your target market then - significantly better than python, inherently memory safe, easy to use, worse than c++.

Re:Facebook puts bounties on bugs in the D programming langu... by pcwalton on Saturday November 16, 2013 @02:39AM (#6744081)
> what I mean is this - we all knew that the rb tree implementation of stl wasn't that hot, neither was its sort (note - this is 7 years back), however that library enabled a c++ project to be jumpstarted in significantly less time than building everything from scratch.

It's not that simple. You can't start with a language that lacks memory safety and add it later. Nor can you start with a language that uses global concurrent GC and try to reel it back in without losing safety. C++ is in the former category and I think there is no way for them to add memory safety at this point. Languages in the latter category really have no way of going back on global concurrent GC; the entire ecosystem is built around garbage collection.

Safe manual memory management is balanced on a very delicate precipice. You must carefully design your language around it for it to work. It is not something that can just be added later, like a faster red-black tree algorithm.

Re:Facebook puts bounties on bugs in the D programming langu... by sandGorgon on Saturday November 16, 2013 @06:04AM (#6744411)
actually - I'm proposing the other way. In fact, what you just wrote above (about the RNG being cryptographically secure in Rust) makes me really, really, really excited to try out the language.

For a large portion of my career, I was building EDA (silicon design automation tools), so I have worked with trying to optimize one bit at a time with unsafe pointers biting my back constantly. IMHO partitioning an EDA netlist is a NP-hard problem, so there have been lots of very interesting startups that tried to solve that problem and failed.

I now work with Ruby and Python.

Trust me I do know the value of everything you wrote: I am just wondering - requesting even - if there is a way to bridge the "accessibility" gap. Is there a way (anything - a "quickstart" library or a safe-but-suboptimal-subset, etc.) that enables me to start hacking with Rust in a matter of minutes ?

Re:Facebook puts bounties on bugs in the D programming langu... by pekk on Saturday November 16, 2013 @01:28AM (#6743926)
Rust isn't even trying to do the same things Python has tried to do. That's not an apples to apples comparison and the fact that you would apply the two in the same cases betrays a lack of sensitivity to which languages are appropriate for what.
Re:Facebook puts bounties on bugs in the D programming langu... by zerr on Saturday November 16, 2013 @08:34AM (#6744649)
Yes, I prefer to have various built-in smart pointers over GC. But I'm not really sure where are you at the moment - One day I hear that Rust is GC-free, then there is some news that you decided to enable GC again, etc...

So how are the things now, and what are the plans for the future?

As a side note: In C++, I prefer to use raw pointers (and unique_ptr for convenience) when the ownership is 100% defined. I believe there is no raw pointers in Rust, right? But at least, built-in smart ptrs might be much easier to use (In C++ it just too much affects code, you really can't use them "transparently").

Re:Facebook puts bounties on bugs in the D programming langu... by kibwen on Saturday November 16, 2013 @09:51AM (#6744913)
I'd be interested to know where you heard that Rust was enabling GC again, because that's never been the case. The plan for quite a while now has been to move the machinery for garbage-collected pointers out of the language itself and into a library. In the bleeding-edge version of Rust, it's already the case that you have to explicitly opt-in to using the old built-in managed pointer scheme.

As for your side note, I just want to point out something: Rust's two remaining built-in pointers (owned pointers (~) and borrowed references (&)) are raw pointers at runtime. There's no dynamic overhead, all their magic happens at compile-time.

Re:Facebook puts bounties on bugs in the D programming langu... by dbaupp on Friday November 15, 2013 @07:34PM (#6743016)
FWIW, the rules about pointers are actually pretty simple. Once you've worked out what you're attempting to do with a given function, the following basically covers it:

- I need ownership (e.g. because I want to push the value onto a vector): take either directly by value (i.e. `x: Type`), or (very rarely) via an ~ (i.e. x: ~Type).

- I don't need ownership, but wish to mutate, `x: &mut Type`

- I don't need ownership and don't need to mutate: `x: &Type` (the most common case)

That is, once you've understood which values need to be owned by what, it all just falls out from there. (Note that this "ownership" concept happens in other languages (e.g. which function should free this pointer in C, which function should close this file handle in any language), it's just not explicit; Rust is just forcing the programmer into making the relationships explicit, which reduces mistakes.)

In general the most common pointer is &, then &mut, and then, if you're writing a data-structure, ~, but otherwise ~ is very rare. (Dynamically sized vectors and strings are written as ~[T] and ~str respectively, and aren't included when I say "~ is very rare" since there's no way to put them on the stack.) I've ignored @, because it's (1) rare in idiomatic code, and (2) isn't implemented fully (it's currently behind a flag, to make it clear that it's not ready for prime-time). The "Boxes" and "Move semantics" parts[1] of the main tutorial are more modern, and may help.

TL;DR; the borrowed pointer tutorial overcomplicates things.

[1]: http://static.rust-lang.org/doc/master/tutorial.html#boxes

Re:Facebook puts bounties on bugs in the D programming langu... by jnbiche on Friday November 15, 2013 @08:17PM (#6743149)
I'm not the downvoter (in fact, I upvoted you since you provided a non-emotional, useful, rational comment), but I disagree that those rules are pretty simple. They may be useful to know, but even the heuristic you provide above is fairly complicated for a beginner. But it's nice to know there are parallels in C.
Re:Facebook puts bounties on bugs in the D programming langu... by jacques_chester on Saturday November 16, 2013 @02:07AM (#6744019)
Without knowing Rust, I think it would nice if the sigils were replaced with keywords.

Eg.

    x: owned mut Type

    x: mut Type

    x: Type
Reasoning: My memory is not what it used to be. I hate having to constantly look stuff up to remind myself what what this or that sigil means in this or that language.
Re:Facebook puts bounties on bugs in the D programming langu... by pcwalton on Saturday November 16, 2013 @02:47AM (#6744098)
I agree actually—I'm not a huge fan of sigils. The GC sigil (@) is being removed, bringing us down to ~ (pointers) and & (references).