News for hackers. Stuff that matters.
Re:Announcing Rust 1.23 by papaf on Thursday January 04, 2018 @12:21PM (#16072067)
If you're using Rust -- tell me, what are you building in it? And what do you love about Rust in your experience while building it? (Get me excited)

I think that it is wrong to think of Rust in terms of internet popularity contests. Its mostly a frustrating and difficult language.

That said, I think that Rust lives up to its hype and is one of the most important languages to come out in recent times. I am writing an SMTP server and can say without doubt, that Rust enabled a much better result than I would be capable of in any other language. I have used Ada and modern C++ in the past and I consider Rust to be an improvement.

I have seen demonstrations of the language Idris that were like looking into the future. However, the larger community and good tooling make Rust a more practical option.

Bearing in mind that I find Rust to be an annoying language there are things that stand out as better than average:

1. Cargo. The only build and dependency tool that has never annoyed me.

2. A very open and welcoming community.

3. Nom, a very weird parser combinator that is a joy to use when you get used to it.

4. Multithreaded programming. For old school C++ multithreading its incredible to write something and have it work first time and not find any weird threading bugs.

5. Coming back to old code is not the painful experience that it is in other languages.

If you are interested in learning a C++ like language, I would recommend Rust. If you are a C++ programmer, I highly recommend learning Rust.

Re:Announcing Rust 1.23 by sertorius on Thursday January 04, 2018 @02:45PM (#16073399)
> If you are interested in learning a C++ like language, I would recommend Rust. If you are a C++ programmer, I highly recommend learning Rust.

Also, if you are a Scala programmer, I highly recommend learning Rust. There are major similarities, and the ownership/borrowing concept is an improvement over Scala's JVM GC issues.

Re:Announcing Rust 1.23 by bulldoa on Thursday January 04, 2018 @01:15PM (#16072589)
what kind of projects will one want to write in rust? I am going through rust right now , and I find it very difficult, simple stuff like doubly linked list or graph is not very intuitive, especially when you want to update inside rc using refcell.

Any tips for newbie like me on motivation and learning?

Re:Announcing Rust 1.23 by leshow on Thursday January 04, 2018 @01:39PM (#16072824)
I find graphs and trees are common 'exercises' that people do when they try out a new language, but you usually won't be implementing stuff like this day to day. You'd be using a well tested library, not cooking one up yourself.

My advice would be to try and write some 'real world' code instead of programming kattas to get a feel for the language.

Re:Announcing Rust 1.23 by bulldoa on Thursday January 04, 2018 @02:58PM (#16073507)
yeah, but another thing I am worried is that if I want to get a rust job, I should be able to do interview problems in rust, which mostly consist of linked list, tree and graph.
Re:Announcing Rust 1.23 by baq on Thursday January 04, 2018 @04:09PM (#16074110)
you'd use a cell/refcell/box or just wouldn't get this excercise as everyone who got past it in rust know it's not easy and critically it's not supposed to be easy.

it's difficult in rust because recurrent data structures are super hard to reason about in general in terms of borrowing and ownership when AOT compiling and you unfortunately must know this to be efficient at rust; this realization is one of the stages of learning the language.

Re:Announcing Rust 1.23 by steveklabnik on Thursday January 04, 2018 @03:07PM (#16073595)
I would argue that's a terrible interview, as anyone who's in the position to give a Rust job should know this about Rust.
Re:Announcing Rust 1.23 by mmstick on Monday January 08, 2018 @07:00PM (#16102176)
I landed a job w/ Rust, and the programming challenge I was given was a simple C programming challenge to implement a parser to parse gzip headers, to which I did it in both C and Rust.

Nobody hiring for a position that's largely Rust is going to ask you to write linked lists, trees, and graphs. They're going to want you to build something more complex & practical.

Re:Announcing Rust 1.23 by steveklabnik on Thursday January 04, 2018 @01:19PM (#16072630)
What's easy and hard in Rust isn't the same as what's easy and hard in other languages. As a beginner, don't try to learn Rust by implementing data structures, as you need to know a lot of Rust to do it correctly. Here's an entire book on writing linked lists, for example: http://cglab.ca/~abeinges/blah/too-many-lists/book/

What did you do so far to learn? How do you learn other languages, and what other languages do you know?

Re:Announcing Rust 1.23 by bulldoa on Thursday January 04, 2018 @02:52PM (#16073443)
I read the rust tutorial up to chap 16, currently reading too-many-list and have not read nomicon, I know python, javascript, golang pretty well. And I know a bit of java and scala.

Usually I learn language by implementing data structures: linked list, tree, graph.

If I can do those then I am pretty confident in doing mostly everything else.

Rust is really the first language that I have trouble with writing simple data structure, I have a bit of issue with scala on covariant and contravariant generics and monads, but they are not bad after I learned it.

For rust everything is awesome until I get to pointers since I have to wrestle with nested smart pointer that makes it insanely hard to manipulate, the rc, refcell nesting is just not very ergonomic (maybe once I learn unsafe it will be easier?).

I like rust paradigm alot since it brings safety and speed, so I was wondering if I am missing anything since I am having some trouble.

Re:Announcing Rust 1.23 by steveklabnik on Thursday January 04, 2018 @03:04PM (#16073573)
Gotcha, thanks. Based on what you know, I'd say pointers and stuff like memory layout are generally going to be where you have issues, and data structures are basically an exercise in applied pointers and memory layout. So you shouldn't feel bad! Regarding what you should do next, reading the last few chapters of the book (19 in particular will be useful for you) would be good; and chapter 20 is a project, which it seems like you are looking for. I can also highly recommend the new O'Reilly book as well.

> I was wondering if I am missing anything

Nope, I think it's just that your experience led you astray.

If I need a linked list in Rust, I... well, I don't ever use linked lists (you can read the book for why). If I had to, I'd use the one in the stdlib.

If I need a graph in Rust, I use petgraph from crates.io.

Basically, other people are good at writing data structures, so I use their work as much as possible. Only if I'm particularly interested in a specific structure, or I require one that doesn't have some implementation out there yet, do I try to write my own.

Of course, at some point you'll want to learn it, but it's just going to be frustrating until it clicks. The less frustrated you are with the rest of Rust when that happens, the less overall frustration you'll have.

> (maybe once I learn unsafe it will be easier?)

That's very possible. Often, you can take a C implementation and translate it into unsafe Rust. Many data structures use unsafe internally, and present a safe interface.

Good luck on your journey! I hope it all makes sense for you soon.

Re:Announcing Rust 1.23 by stjepang on Thursday January 04, 2018 @07:27PM (#16075436)
But... doubly-linked lists and graphs are easy in Rust! :) Here are a few examples.

Doubly-linked list: https://github.com/stjepang/vec-arena/blob/master/examples/l...

Splay tree: https://github.com/stjepang/vec-arena/blob/master/examples/s...

Re:Announcing Rust 1.23 by flukus on Thursday January 04, 2018 @10:19PM (#16076215)
Correct me if I'm wrong, but reading through the linked list code it seems as though it's just a linked list structure on top of a normal vector (via the arena class), combining the worst aspects of each.
Re:Announcing Rust 1.23 by stjepang on Friday January 05, 2018 @06:09AM (#16077907)
Yes, it is. But why 'the worst' aspects of each, though? I see it as the opposite: linked lists built on top of vectors combine good cache efficiency of vectors with algorithmic benefits of linked lists (many operations become O(1), or at least in the amortized sense).

Of course, arenas do have tradeoffs - I'll try to summarize.

Pros:

- Completely safe.

- More ergonomic than dealing with `Rc<RefCell<T>>`.

- Improved cache efficiency of linked data structures.

- Fast node allocation and deallocation.

Cons:

- Any two simultaneous node accesses must be immutable.

- Accessing a node incurs the cost of a bound and liveness check.

- Vector growth can be costly and cause a spike in latency.

- Vector growth moves all nodes in memory.

- Removing a node creates a hole in the vector, possibly wasting memory.

Generally speaking, I think anyone learning Rust and trying to implement a graph data structure should first do it on top of a vector. It's easier than other commonly suggested approaches and it's not a bad one either. In fact, that's how rustc builds some of its data structures, how conrod (a GUI toolkit) represents its widget graph, and how Way Cooler (a window manager) manages window tilings.

Re:Announcing Rust 1.23 by flukus on Sunday January 07, 2018 @06:12PM (#16093315)
> Yes, it is. But why 'the worst' aspects of each, though? I see it as the opposite: linked lists built on top of vectors combine good cache efficiency of vectors with algorithmic benefits of linked lists (many operations become O(1), or at least in the amortized sense).

That's really going to depend on the size of the list, if it's larger than the cache size then it's not as quick to iterate over as a vector because it's jumping around to random (albeit contiguous) memory.

> Generally speaking, I think anyone learning Rust and trying to implement a graph data structure should first do it on top of a vector.

That really depends on why your learning it. Typically when I'm learning/evaluating a new language I run through pain points like this because it show you the good and the bad.

Re:Announcing Rust 1.23 by michaelchisari on Thursday January 04, 2018 @01:57PM (#16073000)
I'm happy to hear that my struggles with doing data structures in Rust were not my own specific failings. A tiny bit of vindication there.
Re:Announcing Rust 1.23 by qznc on Thursday January 04, 2018 @03:39PM (#16073869)
> Cargo. The only build and dependency tool that has never annoyed me.

What exactly is annoying about other build systems?

I asked that questions a few times already and I rarely get concrete answers. This time I just started a public document [0]. Contributions welcome!

[0] https://github.com/qznc/annoying-build-systems

Re:Announcing Rust 1.23 by RazrFalcon on Thursday January 04, 2018 @04:14PM (#16074157)
If we are talking about C++ then the problem is that there a too many build systems and all of them are incompatible.

CMake is quite popular (and maybe most popular) but it's a complete horror in comparison to other build systems, especially for other languages (like Cargo for Rust).

If you need some specific example: try to add a git-based dependency with a specific branch in CMake.

Re:Announcing Rust 1.23 by pjmlp on Friday January 05, 2018 @02:57AM (#16077250)
Build systems should be agnostic from source control systems.

The unit of dependencies should be other projects or binary libraries.

Re:Announcing Rust 1.23 by qznc on Friday January 05, 2018 @11:09AM (#16079423)
I'm not sure about that. If you have dependencies to other internal repositories and to specific revisions, it is not clear who is responsible. Make can be agnostic, but Maven or NPM probably can not.
Re:Announcing Rust 1.23 by pjmlp on Friday January 05, 2018 @12:28PM (#16079991)
Maven surely can. You only depend on binary versions of Java libraries, no source code, as it should be.
Re:Announcing Rust 1.23 by qznc on Thursday January 04, 2018 @07:01PM (#16075290)
My first idea would be to use git-submodule and keep CMake ignorant of that.
Re:Announcing Rust 1.23 by papaf on Thursday January 04, 2018 @04:36PM (#16074296)
I made a pull request for some obvious ones that come to mind.

I have blanked out painful memories of cross-compiling protobufs using CMake but will add a description when I can face them.

Re:Announcing Rust 1.23 by j1elo on Thursday January 04, 2018 @05:46PM (#16074835)
Well the first thing I saw there was a critique to Ant because of aesthetics, which I'd argue is a pretty weak reason to avoid a technical tool like this.

Most probably, it will make sense to counterargument or discuss some (or most) of the anecdotes that will end up appearing in that document.

Seems a fitting use case for Arguman! (I'm not related at all)

https://arguman.org

Re:Announcing Rust 1.23 by shmerl on Thursday January 04, 2018 @05:24PM (#16074669)
> Bearing in mind that I find Rust to be an annoying language there are things that stand out as better than average

What do you find annoying in it specifically?

Re:Announcing Rust 1.23 by leetcrew on Thursday January 04, 2018 @07:16PM (#16075384)
> What do you find annoying in it specifically?

not OP, but when people say rust is annoying they are almost always talking about the borrow checker.

coming from c or c++, which allow you to play fast and loose with pointers and types, it can be frustrating to find out that a lot of stuff you would normally do in those languages is not permitted in safe rust code. the flip side is that, once you get the code to compile (in safe rust), you are guaranteed not to invoke undefined behavior. of course, you can just use unsafe blocks if you really need to play around with raw pointers a la C.

my apologies if you already understand rust and my explanation was very obvious to you.

Re:Announcing Rust 1.23 by shmerl on Thursday January 04, 2018 @07:28PM (#16075441)
I actually see it as a benefit, not something to be annoyed about. And if someone feels too restricted by the borrow checker (like for implementing some library logic), there is unsafe Rust for that.
Re:Announcing Rust 1.23 by leetcrew on Thursday January 04, 2018 @07:59PM (#16075594)
i absolutely see it as a benefit too, but i admit it annoys me sometimes. i would love to get paid to work with rust.