News for hackers. Stuff that matters.
Re:What is Rust and why is it so popular? by alerighi on Tuesday January 21, 2020 @10:56AM (#22108013)
Rust is a great language if you use for what was intended, system programming and as safe substitute of C and C++.

But it's not the answer of everything, to me it's nowadays abused in a lot of projects, there are instances of project where using Rust not only doesn't make a lot of sense but also can be slower than another languages, there are cases where Go is better, other where Node.js is better, other where Python is better, other where Java is better, etc. To me the Rust community seems to want to argue that everything should be rewritten in Rust, just because Rust solves every problem, while it's not.

Re:What is Rust and why is it so popular? by steveklabnik on Tuesday January 21, 2020 @11:13AM (#22108200)
The key is in another comment on this thread:

> Lots of these things that look like syntax problems are in fact design problems surfaced by the compiler.

A lot of people are finding value in the rules Rust provides. This is irrespective of domain. The strict compiler helps you refactor code in ways that less strict languages don't. You still can do it, of course, you just have a lot less help.

The trick is, is the initial hit in productivity worth it, until you get up to speed?

That said, of course everything doesn't need to be in Rust. But there's a reason it's finding broader appeal than purely systems stuff.

Re:What is Rust and why is it so popular? by sdegutis on Tuesday January 21, 2020 @11:26AM (#22108339)
I think this is misplaced causation. Don’t discount the fact that a significant number of programmers just like novelty and like Rust because it’s new in the same way Haskell is new to a Java dev.

That said, Rust’s domain does seem wider than just systems programming. It has the right abstractions to be suitable for (edit: some) higher level things like web apps.

Personally Rust is turning into what I was assuming and hoping Go was going to turn into back in 2010: a static language that does most of what we all used dynamic languages for, without too much extra difficulty. (That is, after you get used to the borrow checker’s rules.)

Re:What is Rust and why is it so popular? by crystaldev on Tuesday January 21, 2020 @03:02PM (#22110892)
> higher level things like web apps.

Frankly any language that makes me write "some string".into(), and all of the other nonsense of Rust, is not suitable for writing string processing applications (as opposed to utilities, such as ripgrep). The business logic of any Rust application that deals mostly with strings is hopelessly obtuse and/or obscured. Languages like Perl, Python and Ruby, or even JavaScript and Java, are more suitable.

Rust focuses on and succeeds at being an improved C++, no reason to use it for everything.

Re:What is Rust and why is it so popular? by iopq on Saturday January 25, 2020 @11:46PM (#22150434)
If "some string".into() is your #1 complaint you haven't used Rust enough
Re:What is Rust and why is it so popular? by sdegutis on Tuesday January 21, 2020 @03:16PM (#22111031)
Web frameworks convert strings to business logic, web apps deal only in business logic. Fortunately the web framework is only written once to support multiple web apps.
Re:What is Rust and why is it so popular? by crystaldev on Tuesday January 21, 2020 @03:18PM (#22111058)
That sounds nice, but practically a lot of web app development can't be perfectly modeled by a type system. There's a lot of string munging and bashing, because at the end of the day we deal with messy human inputs, and the required bookkeeping makes that tedious and inexpressive in Rust.
Re:What is Rust and why is it so popular? by shepmaster on Tuesday January 21, 2020 @01:20PM (#22109718)
> because it’s new in the same way Haskell is new to a Java dev

Do you have any hypotheses about why we don't see as much publicity for Haskell then?

Re:What is Rust and why is it so popular? by sdegutis on Tuesday January 21, 2020 @02:43PM (#22110711)
Hey nice to see you here, your SO posts have tremendously helped me learn Rust.

I think Haskell is just too abstract for most of us. I love Rust traits and see how it directly came from Haskell but I couldn’t learn Haskell even after like 3 serious tries. Maybe a good portion of the problem is in the documentation and not the language? That said, the extremist purity is simply impractical compared to Rust which gets 90% of the way there without forcing all the architectural dances Haskell does. Just my opinion.

Re:What is Rust and why is it so popular? by shepmaster on Tuesday January 21, 2020 @02:58PM (#22110850)
You are quite welcome!

I can't add much to the Haskell part as I've only ever used it sparingly. In many aspects, I view Rust as only having one or two small things that are new (or at least new in a non-research programming language). Its big strength is combining a lot of existing good ideas in a principled manner.

Re:What is Rust and why is it so popular? by sdegutis on Tuesday January 21, 2020 @03:20PM (#22111076)
I’d agree, basically Haskell is focused on academic purity and abstract experimentation while Rust is focused on being equally practical and innovative at the same time.
Re:What is Rust and why is it so popular? by vperez on Tuesday January 21, 2020 @03:44PM (#22111334)
Haskell is actually used by companies to solve practical problems, a non trivial example being Facebook: https://www.youtube.com/watch?v=mlTO510zO78

Not too bad for an abstract experimentation.

Re:What is Rust and why is it so popular? by zozbot234 on Tuesday January 21, 2020 @06:32PM (#22112939)
Haskell is easier to learn than Rust because it's literally just math. There is no "dropping" variables and no need to side-step the lack of GC, because you never "drop" a variable that you've stopped using in a math proof. You just let the GC deal with all that stuff. And you don't have a "stack" vs. "heap" distinction, instead you work directly in terms of function arguments and the returned values. You have currying so you can work naturally with parameterized and partially-applied functions, just like in math, etc. Lazy evaluation for "infinite" sequences and objects. That kind of stuff.
Re:What is Rust and why is it so popular? by ncmncm on Wednesday January 22, 2020 @12:37AM (#22114922)
GC is OK if the only resource your program needs to manage is RAM; and, in particular if time is not among them. There are many such programs, including the favorites of Computer Science, such as compilers.

Add a single other resource, and now you need resource management. Once you have resource management, memory is the easiest thing to plug into it.

If you start out having resource management, you never wonder whether GC would be a good idea. GC turns into a solution desperately looking for a problem, and finding none in your neighborhood.

Re:What is Rust and why is it so popular? by sdegutis on Tuesday January 21, 2020 @07:02PM (#22113160)
> Haskell is easier to learn than Rust because it's literally just math.

That explains why it was so hard for me to learn: I'm awful at math. The most advanced math I could understand was high school algebra.

Re:What is Rust and why is it so popular? by ncmncm on Wednesday January 22, 2020 @12:43AM (#22114945)
Haskell is great if you would rather be doing maths than solving actual, real-world problems. And, either don't care about performance, or like subverting your design to get it.

There are plenty of such people, and they need something to do that keeps them out of the way of people interested in solving real problems efficiently.

Re:What is Rust and why is it so popular? by marcosdumay on Tuesday January 21, 2020 @04:21PM (#22111721)
Don't we?

I think I see more posts about Haskell than Rust here on HN. (What makes sense, since fits a larger set of applications.)

Re:What is Rust and why is it so popular? by discreteevent on Tuesday January 21, 2020 @05:44PM (#22112560)
Were you there when Haskell was new to the mainstream? For a few years there seemed to be nothing else on proggit.
Re:What is Rust and why is it so popular? by slx26 on Tuesday January 21, 2020 @02:08PM (#22110267)
sorry for the tangent, but what has Go turned into in your opinion? (I'd believe it fits quite well your definition)
Re:What is Rust and why is it so popular? by sdegutis on Tuesday January 21, 2020 @02:44PM (#22110728)
It seems to have remained pretty much exactly as it arrived.
Re:What is Rust and why is it so popular? by throwaway894345 on Tuesday January 21, 2020 @01:34PM (#22109903)
Rust is great and I'm really glad it exists; however, I'm skeptical that anyone ever "gets up to Python speed" or "gets up to Go speed", at least provided "speed" means "time to an acceptable result" and not "time to perfect" or "time to pacifying rustc". It's a laudable aim, but I don't think we're close. There's still a lot that Rust makes you think about that Python/Go/etc don't, such as memory management and lifetimes. Even if you are very good at thinking about those things, the cost isn't zero.

Of course, Rust gives you a lot in exchange for the reduced velocity--safety and performance; however, those are tradeoffs and we should talk about them as such. It feels dishonest to present Rust as "as productive as Python" even with the "(given enough experience)" caveat.

Re:What is Rust and why is it so popular? by steveklabnik on Tuesday January 21, 2020 @01:44PM (#22110005)
I feel like these days, provided there’s a library and I’m not writing stuff from scratch, I’m just as fast at Rust as I am with Ruby. I spent way more time debugging Ruby problems and fixing bugs than I pay upfront with Rust.

It really depends on how you measure productivity.

But also, I don’t think that “makes you think about memory” is that simple. I don’t have to think about memory in Rust very often at all: that’s what the compiler is for! When I make a mistake, it corrects me, and I’ve only thought about it for a few moments.

Re:What is Rust and why is it so popular? by throwaway894345 on Tuesday January 21, 2020 @03:34PM (#22111215)
Fully agree about "depends on how you measure"--that's kind of my thesis. If you're willing to trade iteration velocity to gain correctness, I would seriously consider Rust, but probably not if the value proposition was inverted.

> But also, I don’t think that “makes you think about memory” is that simple. I don’t have to think about memory in Rust very often at all: that’s what the compiler is for! When I make a mistake, it corrects me, and I’ve only thought about it for a few moments.

Ok, you don't think about it, but the back-and-forth with the compiler still takes a nonzero amount of time that you don't have to deal with in a GC language. At least not until you start to hit upon GC performance issues, at which point the value proposition shifts in Rust's favor, which ultimately brings me back to my point about it being an issue of tradeoffs and my skepticism about Rust-as-silver-bullet.

Re:What is Rust and why is it so popular? by crystaldev on Tuesday January 21, 2020 @02:32PM (#22110572)
> I pay upfront with Rust.

But you do pay up front! That's a big deal if your design is not set in stone (which is not a synonym for "prototyping").

Re:What is Rust and why is it so popular? by steveklabnik on Tuesday January 21, 2020 @03:07PM (#22110940)
I also think this is not a simple question; Rust’s rules provide critical feedback during that early phase. It’s valuable when getting started too. The prototype phase may last slightly longer, but I end up much closer to the final design with its help.

(Again, as always, YMMV.)

Re:What is Rust and why is it so popular? by sambe on Tuesday January 21, 2020 @11:40AM (#22108481)
I don't recall seeing the community arguing strongly for re-writes. I see people who want to do rewrites for fun/education. For example, just because they love the language and prefer to work in it. In some cases people make the case for re-writing sensitive libraries in Rust, but I think a) they are not in general arguing confrontationally; b) they tend to have a point technically speaking. The missing piece is whether it makes sense long-term, with different pools of potential contributors etc.
Re:What is Rust and why is it so popular? by Brave-Steak on Tuesday January 21, 2020 @11:54AM (#22108649)
> To me the Rust community seems to want to argue that everything should be rewritten in Rust

I haven't seen this. At most, I've seen the push for rewriting important libraries where security is a core issue in Rust. I don't blame them. I'm tired of C/C++ being used everywhere because of performance, leading to the current-day situation of so much fundamentally unsafe code running the world.

Re:What is Rust and why is it so popular? by CJefferson on Tuesday January 21, 2020 @11:57AM (#22108685)
I'm involved in a couple of github projects where we have had drive-by "hey, rewrite your project in Rust" PRs. Obviously not official or anything, but never seen anything like that for any other language.
Re:What is Rust and why is it so popular? by runevault on Tuesday January 21, 2020 @06:05PM (#22112737)
I feel like those are actually trolls. I don't remember the last time I saw someone serious about rust doing those types of silly stunts.
Re:What is Rust and why is it so popular? by mrec on Tuesday January 21, 2020 @01:27PM (#22109814)
Oh, back when Java first came out, Sun themselves were pushing this ("Rewrite it in Java!") line in spades. The hype train was unbelievable back then.
Re:What is Rust and why is it so popular? by ncmncm on Wednesday January 22, 2020 @12:48AM (#22114965)
There is no such language as C/C++. You and I are tired of C being used where using a more powerful, safer language would also be faster. Rust could be that language, but C++ is another, and much more likely to still be known in ten years.
Re:What is Rust and why is it so popular? by Brave-Steak on Wednesday January 22, 2020 @01:17PM (#22120305)
/ = or

As in C or C++. I didn't mean it as its own language. And C++ has plenty of issues where I'd consider it equally unsafe. Unless you're a god tier programmer, and even then, it's impossible to write safe code without insane amounts of effort that can't be expected in most projects.

Re:What is Rust and why is it so popular? by MadWombat on Tuesday January 21, 2020 @11:49AM (#22108605)
OK, I will bite. If I had to come up with a case where Python is better than Rust, I would say with rapid prototyping and scientific computing. If you just want to try a few things out, python has faster development cycle and if you want to do some super clever math python has better library support. With a bit more mind stretching, I can make a case for Go with a bit more mind stretching. If you want to write a massively parallel network server of some sort you might be better off with Go, especially if you want to use protobufs and grpc. But what would be the case for Node and Java?
Re:What is Rust and why is it so popular? by christiansakai on Tuesday January 21, 2020 @01:03PM (#22109499)
For massively parallel even with async, I still think Go is better than NodeJS. I still don't know how to do bounded parallelism in NodeJS but really easy in Go.
Re:What is Rust and why is it so popular? by lostcolony on Tuesday January 21, 2020 @01:21PM (#22109727)
https://github.com/caolan/async/blob/master/lib/internal/eac... - this is the code the async Node lib uses for every "(X)Limit" function to limit the number run at once.
Re:What is Rust and why is it so popular? by terminaljunkid on Tuesday January 21, 2020 @11:56AM (#22108675)
Ecosystem..

I don't know about node. But there's whole lot of java code and libraries out there. Otherwise why would people build other languages for the JVM?

Ease of writing; Most of code is okay having a GC. But time to produce working code (not necessarily 100% correct code) is important.

Rust is created for low level stuff. It is wrong to expect web backend programmers to deal with ownership, stack-vs-heap and all.

Re:What is Rust and why is it so popular? by MadWombat on Tuesday January 21, 2020 @12:21PM (#22108980)
> It is wrong to expect web backend programmers to deal with ownership, stack-vs-heap and all.

I am a web backend programmer. I respectfully disagree. I would much rather deal with ownerhip and related issues than deal with dynamic typing fallout. Unfortunately, I am stuck in Python land for some foreseeable future.

> But there's whole lot of java code and libraries out there.

That is true about every other popular language. Rust might not have the ecosystem, being a lot younger, but why would anyone pick Java out of all the other options?

As far as I can tell, the only two reasons people continue coding in Java are "We have an existing Java ecosystem, it is easier to continue doing what we have been doing than to switch" and "Java is what we know best and it is easier to use Java than to learn new technology stack".

Re:What is Rust and why is it so popular? by sweeneyrod on Tuesday January 21, 2020 @12:46PM (#22109292)
> I would much rather deal with ownerhip and related issues than deal with dynamic typing fallout.

Those two things aren't connected. You can avoid both of them by using one of the many statically typed languages with a GC. It might be the case that Rust has other advantages over those languages that make power-assisted manual memory management a cost worth bearing, but it is still a cost. The amount of successful web backends written in Python/Ruby shows that performance demands on a typical web app are nowhere near high enough to justify doing away with the GC.

Re:What is Rust and why is it so popular? by bcrosby95 on Tuesday January 21, 2020 @02:10PM (#22110294)
Here's why we use Java:

1. It performs well - we're a small company, so hardware costs matter to us. Its a similar performance class as Go and C# - if you want to go faster, you likely have to use Rust, C, or C++.

2. As said, the ecosystem is huge. If you need to do something, there's probably a library or tool for it. If you have a problem with one of their libs, someone else had the problem too. Unless your business is consulting, spending your time going down paths no one else has gone down just so you can use a shiny new language is a waste of resources.

3. The language isn't full of too many concepts. This makes it easier to get people up to speed with it if they're unfamiliar. I like Rust for some personal projects, but lots of the complexity of the language is completely pointless for most of what we do at my company.

4. The JVM is great.

5. We already know it.

Even ignoring #5, our priority of languages is probably C#/Java, then Go. Java is a meh language. And I feel like the annotation soup only makes it worse: it makes Java both verbose and magical, a truly shitty combination. But the ecosystem is awesome. The performance is good. The JVM is great.

With .NET Core, it might make sense to look at C#. But the language is fairly similar to Java anyways. Switching for switching's sake seems pointless. And Microsoft only relatively recently started officially supporting Linux, so I would be wary of using it for greenfield, much less switching our existing company.

Kotlin is a decent contender here too. But it's not that widespread as a backend language, at least not yet. If I could pick any language, I would choose Clojure because it benefits somewhat from Java's ecosystem and is (IMHO) the best JVM language. Immutability is killer, and I find dynamic typing with specs a good middleground between purely dynamic and purely static languages.

But Clojure makes things pretty difficult when it comes to the hiring end of things and developer familiarity. If I worked at a greenfield company solving the same problems I do today, Java would probably still be my first choice.

Re:What is Rust and why is it so popular? by ggregoire on Tuesday January 21, 2020 @01:01PM (#22109473)
> If I had to come up with a case where Python is better than Rust, I would say with rapid prototyping and scientific computing.

Scripting? I'm not gonna write a 50 LOC single-use script in Rust.

Re:What is Rust and why is it so popular? by estebank on Tuesday January 21, 2020 @01:18PM (#22109690)
I've found that a lot of scripts end up not being single use. In my case they usually do end up rewritten in Rust, with the benefits of having a proper --help command from the bother. Once you know enough Rust the obtuse parts of the language that must exist to cater for the performance critical crowd cease to be a problem.
Re:What is Rust and why is it so popular? by oconnor663 on Tuesday January 21, 2020 @01:49PM (#22110043)
I do write a lot of Python and Bash scripts, even in my Rust projects. They're perfect for gluing together a build. But I'd add that as soon as I want an external dependency (often a more featureful command line flag parsing library), I usually RIIR.
Re:What is Rust and why is it so popular? by jayd16 on Tuesday January 21, 2020 @12:14PM (#22108886)
Can Rust do things like heap compaction? You could do it by hand I guess but its not exactly trivial. There's probably a whole class of problems the GC still excels at.

JVM tooling is also pretty nice. Can you trivially get deep app metrics from any Rust program?

Re:What is Rust and why is it so popular? by steveklabnik on Tuesday January 21, 2020 @12:19PM (#22108949)
I think you're asking rhetorically, but just in case:

1. Rust-the-language doesn't know anything about allocations, so strictly speaking, it cannot. Furthermore, without a GC, it's unclear how it could in the first place, given that a compaction would invalidate all pointers to that memory.

2. Certainly not to the same degree as the JVM, given that there's nothing inherently to inspect, like there is in languages with a runtime. You can instrument your own application, but that does mean doing the work yourself, and you only get as good of results as you put in in the first place.

Re:What is Rust and why is it so popular? by zozbot234 on Tuesday January 21, 2020 @01:06PM (#22109538)
> Rust-the-language doesn't know anything about allocations

AIUI, Rust knows more about allocations than it should, since it's still limited to a single global allocator, and Box<> (which relies on that global allocator) is implemented via compiler magic and cannot be supplemented by equivalent library code. If Rust supported "pluggable" allocators in some fashion, fancy features (including heap compaction, although I find that a bit dubious TBH) might become easier to implement.

Re:What is Rust and why is it so popular? by steveklabnik on Tuesday January 21, 2020 @01:45PM (#22110014)
Global allocator is a standard library concern, not a language concern, and Box is magic in only one tiny way that doesn’t actually have to do with allocation. Eventually that will be available to other libraries too.
Re:What is Rust and why is it so popular? by shepmaster on Tuesday January 21, 2020 @01:22PM (#22109743)
> If Rust supported "pluggable" allocators in some fashion

It's coming, but it's still unstable and being actively developed

- https://github.com/rust-lang/rust/issues/32838

Re:What is Rust and why is it so popular? by Ar-Curunir on Tuesday January 21, 2020 @01:10PM (#22109600)
`std` data structures that are generic over type of allocator are in the works.
Re:What is Rust and why is it so popular? by Ididntdothis on Tuesday January 21, 2020 @11:01AM (#22108079)
I think that’s ok. It takes a while to figure out where a language is ok and where it’s maybe not ok. Also by doing stuff it may not be perfectly suited for right now there is an incentive for improving things.
Re:What is Rust and why is it so popular? by spamizbad on Tuesday January 21, 2020 @02:41PM (#22110691)
I find it comforting that the Rust community is casting a wide net, even if it’s not always the best fit. It’s something I always enjoy about working with Python.

There are some platforms and ecosystems that pour 90% of the effort into a handful of popular niches, but once you leave that comfort zone you’re on your own. Elixir can feel like that; Ruby/Rails too back in the day.

Re:What is Rust and why is it so popular? by s_y_n_t_a_x on Tuesday January 21, 2020 @10:57AM (#22108035)
One major reason for the recent explosion is it's first class WASM support, especially since it doesn't need a GC.

It just has language features that make sense for the web, which is a huge sector. (parallelism, memory safety, speed, JS interop)