Live data from Hacker News

Four years with Rust

words.steveklabnik.com

131–140 of 199 posts

Re: Four years with Rust

#131
post #18

Earlier quoted context omitted.

There is also the possibility that a Rust 2.0 could fragment the community much like with Python2.7 Python3.x, which would be "undesirable" at best.

I wish the notion of Rust 2.0 was definitively buried to remove the fear of Rust doing its own Python 3.

Trust me, if there's ever a Rust 2.0, it will contain minimal breaking changes (ideally no breaking changes that can't be automatically and infallibly fixed by a migration tool), and will be preceded by years and years of deprecation warnings.

Python 3 broke Python because it completely changed how strings work. Nothing of that magnitude will ever come to Rust.

Re: Four years with Rust

#132
post #64

I really like the premise of Rust. Keep at it. For my purposes, it's still a bit too immature. Last time I looked at the big 7 things, most were still not done. https://mail.mozilla.org/pipermail/rust-dev/2014-June/010139... The RustDT plugin for Eclipse makes the edit/save/compile/flag errors loop a lot tighter for me as a beginner. The autocomplete seems incomplete though and there's no hover docs or ctrl-click thr…

A quick summary of where these are at: Internationalization / Localization / Unicode (ICU): yup, no real progress. Needs some domain experts to drive it. Date/Time : chrono is the most popular. HTTP: hyper has been good for a few years now, tokio will make it async soon. Crypto: there's lots of interesting work in this space, see ring and rustls. SQL: Diesel is the gold standard here. So, some progress! You're absolu…

For ICU we have http://github.com/unicode-rs/ which covers a lot of it. There are scattered libraries for other ICU things too.

Re: Four years with Rust

#133
post #112

Earlier quoted context omitted.

I listed two things Rust doesn't handle well without unsafe code, doubly linked lists and multidimensional arrays. Here are examples of both from popular repositories with high download numbers: - https://github.com/andelf/rust-adivon/blob/master/src/deque.... - https://github.com/andelf/rust-adivon/blob/master/src/queue.... These are all the doubly-linked list problem: struct Node { item: T, next: Option >>, prev: R…

Why do you still think the compiler can't host those out of loops? LLVM is perfectly capable of doing so in many cases and you've been told as much previously, could you make your claim more specific?

Where does LLVM do that? LLVM does hoist of invariant code out of loops in the Loop Invariant Code Motion and Loop Strength Reduction phases.[1] But that's not enough. This isn't an invariant situation. Consider a matrix multiply, the most common operation in number-crunching. You're indexing through three 2D matrices along both axes. The indices are usually controlled by FOR statements, so the compiler knows the range the indices can take. If the compiler knows about multidimensional arrays, it's easy to make those checks once at FOR loop entry.

But if those checks are in asserts, it's tougher. Is LLVM allowed to fail an assert early? If the array is 0..999, and the index is 0..1000, a subscript out of range condition will occur on iteration 1001. For best performance, you want to detect the subscript out of range condition at the point it becomes inevitable, rather than checking on every iteration and failing on iteration 1001. (Although technically you could generate a special case.)

But that requires special treatment of "assert". In Rust, "assert!" is just a macro. The compiler can't optimize it that aggressively and fail early. Especially since you can now catch assertion failures during unwinding.

If all those optimizations really exist, why is there code like this (at https://github.com/SiegeLord/RustAlgebloat/blob/master/algeb...)?

    MatrixMul
    {   unsafe fn raw_get(&self, r: usize, c: usize) -> f64
	{   let mut ret = 0.0;
	    for z in 0..self.lhs.ncol()
            { ret += self.lhs.raw_get(r, z) * self.rhs.raw_get(z, c); }
            ret
	}
    }
If what you say is true, all that unsafe stuff is unnecessary.

[1] http://llvm.org/docs/Passes.html

Re: Four years with Rust

#134

Wow, four years already. Maybe you can help settle this question I've had. I'm a rubyist (like you were/are, and wycats, and a bunch of rustaceans), and I think that sort of drove my interest in rust. But after 4-5 years of ruby the dynamism which initially was super cool, has grown a little frustrating and I long for a more sophisticated type system and a compile step, since frustrating bugs crop up from time to tim…

Are you talking about strong typing or static typing? I've been using statically typed languages for 20 years (C++, Java, Objective-C) and I haven't gotten tired of it yet. Especially when working in a large code-base I didn't write, Python is rough. What's a "session"? Who knows, guess I'd better put `print type(session)` and figure out how to get that function executed.

Although, the thing that bothers me about Python (haven't used Ruby) is the fact that it is interpreted. It's really annoying to have to run my program to discover syntax errors and typos, when a compiled language would do that for me. With interpreted and dynamically typed languages, you have to have 100% test coverage, because you have no idea if your code is even syntactically valid until you run it, and of course if it isn't valid, then you throw an exception. (Hopefully that crashes the program, unless someone was brilliant enough to catch all exceptions and not print any error messages, then it looks like everything worked fine until you discover it didn't.) So every change is a potential for an exception, until you execute that line of code to make sure there wasn't a misspelled variable name or something.

So, yeah, I love the compiler. (I also love Python for scripty stuff.)

Re: Four years with Rust

#135
post #119

Wow, four years already. Maybe you can help settle this question I've had. I'm a rubyist (like you were/are, and wycats, and a bunch of rustaceans), and I think that sort of drove my interest in rust. But after 4-5 years of ruby the dynamism which initially was super cool, has grown a little frustrating and I long for a more sophisticated type system and a compile step, since frustrating bugs crop up from time to tim…

The main languages I use with work are: * C * Scheme (Gambit) * Python 3.4 * Pony I find all of them frustrating at times. Python's dynamism is nice, but it's so damn inflexible, requiring my to follow the One True Way. That can be good, and makes it easier to eliminate bad code in reviewing. But it also means that you can fight with the interpreter to do what you want. Scheme gives me both dynamism and flexibility,…

Can you talk more about using Pony in a production environment? What are the performance aspects of it? How do you find writing 'non-actor' code - like just doing some string manipulation?

I find the language fascinating but I'm learning Erlang and I don't really want to get started with Pony at the same time. Do you have experience with Erlang?

what made you choose Pony?

Sorry for the bombardment of questions but I don't hear much about Pony. As a rust user, and a burgeoning fan of Erlang, I'm fascinated.

Re: Four years with Rust

#136
post #129

What would be interesting if it would be possible to develop with GC on, but then if you benchmark and notice that it's too slow, turn on manual garbage collection for specific pointers. I don't know if it's possible, though (considering libraries).

Rust doesn't have a GC in the first place, so there's nothing to turn on. Even then, the fundamental hurdle with GC isn't the effect on your program's runtime, it's the effect that it has on the lifetimes of your data . GC (and RC) are means of dynamic lifetime determination. Manual memory management is static lifetime determination. The latter requires you to structure your code in a specific way, which may be less…

I was just thinking that most languages are either GCed (like Java or Go) or manually curated (C/C++/rust).

My idea is that if one could write in a language like Go (which has some kind of GC), but when one wants, say "I'll take care of this memory".

Re: Four years with Rust

#137
post #98

Earlier quoted context omitted.

> If you know your array will hold at most ten references, it will take at most the time to free the ten references. True. But if those references themselves contain references, it may become tricky to manage all of this. You basically don't want to think about it. But, like others mentioned, you can put the objects in a queue, and free them in the background. It would be interesting to know how such a solution stack…

Note that you don't need a GC to do that; the allocator can do it for you. A lot of folks think that optimizations like having allocation arenas and spreading out deallocation pauses are unique to garbage collectors, but they're completely orthogonal to GC. You can have GCs with these optimizations, and GCs without. You can have regular allocators with these optimizations, and regular allocators without. Jemalloc doe…

An exception (large complicated Rc-trees) is the rope in xi-editor. If you load a very large file, the operation of letting go of the last reference is potentially a large enough pause to have an effect on UI responsiveness. I've considered adding a mechanism that moves the object into a deallocation thread (or a deallocation task running in a thread pool) for this reason, although I'm not sure how important it is in the grand scheme of things.

In a GC'ed language such as Go, this would not be a problem. The flip-side is that I can safely and efficiently do updates in place, because Rust's reference counted type has a way to determine when you're holding the only reference.

Re: Four years with Rust

#138
post #112

Earlier quoted context omitted.

Why do you still think the compiler can't host those out of loops? LLVM is perfectly capable of doing so in many cases and you've been told as much previously, could you make your claim more specific?

Where does LLVM do that? LLVM does hoist of invariant code out of loops in the Loop Invariant Code Motion and Loop Strength Reduction phases.[1] But that's not enough. This isn't an invariant situation. Consider a matrix multiply, the most common operation in number-crunching. You're indexing through three 2D matrices along both axes. The indices are usually controlled by FOR statements, so the compiler knows the ran…

> If the compiler knows about multidimensional arrays, it's easy to make those checks once at FOR loop entry.

Or you could just use a little unsafe code to implement iterators and matrix multiplication on top of the array, and then never use unsafe with the matrices anyway. This is what gets done with regular arrays and vectors. Directly indexing these types is pretty rare. You would do the same with matrices. "Put it in the language" is not a solution for everything, especially when the tools are there to build it with almost the same level of ergonomics.

Requiring unsafe for designing some kinds of abstractions is not a bad thing. There's no need to shove everything into the language if it can be implemented as a library with a smattering of unsafe code.

It's almost equivalent, really. Making a mistake when writing this unsafe code and making a mistake in the builtin optimization are mostly equivalent risks. There's nothing inherently worse about doing it as a library, aside from the minor issue that the indexing syntax isn't so great.

Re: Four years with Rust

#139
post #78
post #20

Earlier quoted context omitted.

What kind of application s would Rust be an appropriate for? What languages is it largely meant to replace/improve on.

I've been using Rust to process fairly large amounts of streaming financial data. I am using Protocol Buffers (and evaluating Cap'n Proto) for network serialization and Kafka for buffering/queuing, and overall the library support is quite good. Previously I was using JVM languages for this purpose, but grew weary of the resource footprint, and especially the unpredictable GC pauses. I am aware of the Azul JVM which r…

How easy is it to get Kafka and Rust working together?

Re: Four years with Rust

#140
post #88
post #41

Rust as a language is now realizing the benefits of borrow checking. As the article points out, the syntax doesn't have to distinguish between move and assign. The borrow checker will catch a reuse of something already moved away. This turns out to be effective enough in practice that the syntax distinction isn't necessary. That wasn't obvious up front. Not having exceptions tends to generate workarounds which are ug…

> There's still too much that has to be done with unsafe code. But the unsafe situations are starting to form patterns. I think as long as those patterns can be abstracted out and moved into thoroughly-vetted libraries with a safe interface, unsafe code isn't really a problem. I expect that getting Rust's standard libraries to a place where regular applications very rarely need to create their own unsafe code blocks…

Agreed. And considering that the most common uses of unsafe are for collections, I think a limited number of vetted libraries completely realistic.

Rolling your own collections is typically not that great anyway; how much better is your linked list/hash table/skip list than everyone elses?

Post reply on HN