oniony / TMSU

TMSU lets you tags your files and then access them through a nifty virtual filesystem from any other application.
Other
2.04k stars 118 forks source link

Evaluate suitability of Rust #74

Open oniony opened 8 years ago

oniony commented 8 years ago

Certain aspects of Go annoy me. I need to do some research into Rust to see if it annoys me less.

leavengood commented 8 years ago

While I'm sure you want to do the research yourself, I hope you don't mind if I give my perspective. For some context I was a long time Ruby developer who switched to Go as my primary language several years ago. My full-time job is primarily Go development, and I've been at this job for slightly over a year.

I've also been following Rust since before 1.0, but my only serious attempt to use it has been in the last two months or so. We had to convert between file formats at work, and the file format we were converting from did not have any Go libraries, but there were several for Rust. Since this was to be a single standalone tool with a very specific focus, it seemed trying Rust would be pretty low risk. Overall it was a big success and the tool works great.

Using Rust just makes Go's major flaws all the more obvious:

  1. Lack of real generics.
  2. Bad default package management.

Rust's generic system is really great, and traits are very much like Go's interfaces, one of my favorite Go features. While I did not have a large need for Rust generics in this small tool, there was one particular function where it was useful and I was very pleased. This particular case probably could have been handled in Go with interface{} but with the usual caveats. There are many other cases which can only be solved in Go with code generation. We all know Go needs generics but it has become the elephant in the room that we all just seem to ignore until the "magical" perfect solution is dropped from heaven.

As for packages, Rust's package manager Cargo is a really, really great tool. It does everything right pretty much, even allowing for different versions of the same crate to be used in the same binary, if needed (though that is actually a Rust feature.) Go's "package management" is a joke by comparison, and again, we all know that but everyone just cobbles together their own solution.

I was also really happy with Rust's closures and various functional language inspired pieces. Certain things which are awkward in Go are very elegant and readable in Rust. Sometimes Rust feels like Ruby to me.

Now on the bad side, Rust's style of memory management is just harder to deal with than a garbage collector. But I will say for my small tool it didn't cause as much problems as I would expect. I'm already gaining an intuition into how to properly do things in Rust, and that is even affecting how I think about my Go code.

Also at the moment I think goroutines are a better way to handle concurrency (if you need it.) Rust had green threads once but they abandoned them in favor of just normal threads. I assume this was due to the need for a runtime and Rust wants to have a very minimal runtime. Honestly I haven't tried making any sort of concurrency comparison between Go with goroutines and Rust with threads, maybe the difference isn't that bad. In addition Rust has crates like mio for non-blocking IO.

I still like Go and for the moment it will still be my primary work language. But I want to use Rust where I can, and am now working on several personal projects using it.

The choice between Go and Rust depends very much on the project, and overall I tend to agree with a lot of Rust fans who don't even consider Go and Rust competitors, as their primary focus is different. Go is great for web services and small local tools, Rust is great for lower level stuff and also small local tools.

I do I think for a tool like TMSU, Rust would actually be a great choice.

oniony commented 8 years ago

Wow, thanks for the very detailed insight. I've actually decided to start work on a little platform game in order to learn Rust, using the SDL2 bindings...so hopefully that will be a useful way to learn about the language's nuances without destabilising TMSU.

So far it has a lot of features I like, and am used to from C# and Ruby, but the memory management I'm currently finding confusing, as you pointed out. This concept of borrowing and thus making previous references invalid is a new paradigm to me.

Thanks again! It's nice to know that the language has potential. I'm really starting to find Go's simplicity a double-edged sword. On the one hand it's quite liberating having so little mental load whilst programming but it's also incredibly frustrating having to churn out boiler plate for where the language lacks the complexity. Surely there's a middle ground somewhere in the compile-to-native space.

Paul On 17 May 2016 15:51, "Ryan Leavengood" notifications@github.com wrote:

While I'm sure you want to do the research yourself, I hope you don't mind if I give my perspective. For some context I was a long time Ruby developer who switched to Go as my primary language several years ago. My full-time job is primarily Go development, and I've been at this job for slightly over a year.

I've also been following Rust since before 1.0, but my only serious attempt to use it has been in the last two months or so. We had to convert between file formats at work, and the file format we were converting from did not have any Go libraries, but there were several for Rust. Since this was to be a single standalone tool with a very specific focus, it seemed trying Rust would be pretty low risk. Overall it was a big success and the tool works great.

Using Rust just makes Go's major flaws all the more obvious:

  1. Lack of real generics.
  2. Bad default package management.

Rust's generic system is really great, and traits are very much like Go's interfaces, one of my favorite Go features. While I did not have a large need for Rust generics in this small tool, there was one particular function where it was useful and I was very pleased. This particular case probably could have been handled in Go with interface{} but with the usual caveats. There are many other cases which can only be solved in Go with code generation. We all know Go needs generics but it has become the elephant in the room that we all just seem to ignore until the "magical" perfect solution is dropped from heaven.

As for packages, Rust's package manager Cargo is a really, really great tool. It does everything right pretty much, even allowing for different versions of the same crate to be used in the same binary, if needed (though that is actually a Rust feature.) Go's "package management" is a joke by comparison, and again, we all know that but everyone just cobbles together their own solution.

I was also really happy with Rust's closures and various functional language inspired pieces. Certain things which are awkward in Go are very elegant and readable in Rust. Sometimes Rust feels like Ruby to me.

Now on the bad side, Rust's style of memory management is just harder to deal with than a garbage collector. But I will say for my small tool it didn't cause as much problems as I would expect. I'm already gaining an intuition into how to properly do things in Rust, and that is even affecting how I think about my Go code.

Also at the moment I think goroutines are a better way to handle concurrency (if you need it.) Rust had green threads once but they abandoned them in favor of just normal threads. I assume this was due to the need for a runtime and Rust wants to have a very minimal runtime. Honestly I haven't tried making any sort of concurrency comparison between Go with goroutines and Rust with threads, maybe the difference isn't that bad. In addition Rust has crates like mio https://crates.io/crates/mio for non-blocking IO.

I still like Go and for the moment it will still be my primary work language. But I want to use Rust where I can, and am now working on several personal projects using it.

The choice between Go and Rust depends very much on the project, and overall I tend to agree with a lot of Rust fans who don't even consider Go and Rust competitors, as their primary focus is different. Go is great for web services and small local tools, Rust is great for lower level stuff and also small local tools.

I do I think for a tool like TMSU, Rust would actually be a great choice.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/oniony/TMSU/issues/74#issuecomment-219742539

leavengood commented 8 years ago

As a tip I found that Rc solved some memory issues for me where I wanted to share some strings. But overall to get comfortable with Rust one needs to understand memory management and know when to use Rc, Arc, Cell and RefCell. And then you start to understand why C++ projects like WebKit have so many pointer types. Overall I think it is worth it because it really helps you "level up" as a programmer.

My feelings about Go are very similar to yours. Simplicity is great until its not :wink:

oniony commented 7 years ago

I've created the branch rust for starting this experimental work.

talklittle commented 6 years ago

@oniony Since you've been toying with the idea of a Rust rewrite, are you considering a crate published on crates.io that implements the core logic, and a separate application crate that implements the command-line interface?

This architecture would help with third-party extensions to TMSU, like https://github.com/talklittle/tmsu-nautilus-rs, avoiding the need to parse the command-line output.

oniony commented 6 years ago

Hi, yes, this is the plan.

On 21 Feb 2018 1:28 pm, "Andrew Shu" notifications@github.com wrote:

@oniony https://github.com/oniony Since you've been toying with the idea of a Rust rewrite, are you considering a crate published on crates.io that implements the core logic, and a separate application crate that implements the command-line interface?

This architecture would help with third-party extensions to TMSU, like https://github.com/talklittle/tmsu-nautilus-rs, avoiding the need to parse the command-line output.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/oniony/TMSU/issues/74#issuecomment-367325542, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAXB9Dg11GZ26otgbiW1x9ESWewEXaxks5tXBoTgaJpZM4IWad8 .

lefth commented 8 months ago

Did Rust kill this project? ;-)

Rust is a great language, but it is occasionally very hard. Furthermore, the strictness causes some distraction when you don't realize which errors you need to handle and which can realistically be ignored. (Propagating Result throughout your program adds an additional cognitive cost, which can be a benefit but is often a curse.)

You and I are both C# developers so we can probably agree it's a good language. I wonder if writing this tool in C# would hurt open source contributions? It has the benefit of being intuitive (fairly classic code style), compared to Rust or Go.