Live data from Hacker News

A Week with Mozilla's Rust

relistan.com

101–104 of 104 posts

Re: A Week with Mozilla's Rust

#101

The example of match usage is really poor. From the looks of it there is no "pattern matching" going on at all here. I don't know the syntax, but even something like this would be a better demonstration: let computed_key = match (key.len() > self.block_size, key.len() self.zero_pad(self.hash(key).digest), (false, true) => self.zero_pad(key), (false, false) => key } At least there is some matching here, unlike in the…

You're right that it's not an ideal example. I think I said that in the post. The context of the article was the week I spent with Rust and the project I actually did with it. There was not a better example in my code to show. I could have contrived something, but it wasn't really in spirit of what I was writing about.

You probably should fix this in your code too. As noted in this thread, that's not a proper way to use pattern matching. Anyone reading your code will be confused by this usage and that's not a good thing. It probably would be best to use this:

    match key.cmp(self.block_size) {
        Equal => ..
        Greater => ..
        Less => ...
    }
Which is much prettier (and more succinct) than both your original code and my example. You could also use a `cond!()` macro here, but that would mean you don't have an example for a blog post, so I think the above code is the best option. Thanks to kzrdude for posting.

Re: A Week with Mozilla's Rust

#102
post #20

Earlier quoted context omitted.

At the bottom of the cgo command documentation [0] is an example of exporting go functions to C. I don't fully understand how those functions work when running in C land (does the GC come with?), but the implementation doesn't look difficult. [0] http://golang.org/cmd/cgo/

What you can do: - Have some C code in your Go app that calls a Go function. What you can't do: - Have some C code in your C app that calls a Go function.

The second answer to this stack overflow [0] indicates that you can run Go functions from C if you use gccgo [1].

[0] http://stackoverflow.com/questions/6125683/call-go-functions...

[1] http://golang.org/doc/install/gccgo

Re: A Week with Mozilla's Rust

#103
post #57

Earlier quoted context omitted.

I read the intro as "I like Rust, I'm going to twist my requirements to match", but that may be a bad read of the author.

That wasn't my intention. I didn't decide to like Rust before trying it, I tried it to see if I liked it. I wrote up what I've learned so far. Probably some day this post will seem naive to me, but for now it's the best I could manage.

Fair - if I were to write up what I'd want from a new systems language it would be: statically typed with some sort of generics capability, natively compiled, not GC'd (I like the idea of ObjC's ARC, though I can't say I've used it), and with first-class support for concurrent or parallel programming - this also sounds an awful lot like Rust, and I don't think I was particularly aiming for it, it's just got a good set of features and design goals for a modern systems language.

Re: A Week with Mozilla's Rust

#104

Earlier quoted context omitted.

Rust does have some new syntax, but I think most of it is justified for making programming in it nicer. The `~[u8]` would be written `std::unique_ptr ` in C++. They're used everywhere in Rust, and having to write out unique_ptr would get awfully tiresome. The `acc` on its own line is a result of "the last statement gets returned" like many functional languages do. If you were writing C++, you'd write `return acc;` in…

> The `~[u8]` would be written `std::unique_ptr ` in C++. Wouldn't it be `std::unique_ptr >`?

Indeed, it would.
Post reply on HN