News for hackers. Stuff that matters.
Re:Things you can’t do in Rust (and what to do instead) by pron on Saturday May 15, 2021 @07:45AM (#27164376)
I'm watching with both amazement and amusement how Rust is undergoing the exact same process we went through with C++ in the late '80s and early '90s, pushing the belief that the same language should be used for both low-level and high-level programming. Back then, just as it is now, that idea was sold by programmers who are on the more capable end of the spectrum and who also enjoy spending a lot of time thinking about clever ways to express programs in a rich programming language. Then, as now, they were people who hadn't had much contact with the average software developer and with the realities of software mass-production. The few of them who had, also tried convincing the industry that the system should change, and that software should be developed by small elite groups who are masters of the discipline as well as discipline (I'm not talking about the people who like Rust, or C++, for that matter, for low-level programming, but about those who try to sell low-level programming for application development), but, of course, the economics always win.

Those who go down that path will experience the same disillusionment we did, and end up with applications that end up costing so much more to maintain if only because of the cost of the maintainers they require. Software costs work better when low-level and high-level programming are kept separate. The former is costlier but tends to be both smaller in size and in prevalence, while the latter is the opposite.

Of course, the number of people who make that mistake of mixing high- and low-level programming won't be nearly as high now as it was back then -- many of us have learned our lesson -- but it would still be interesting to watch this unfold again, even at a small scale. And, thirty years from now, some will be telling us why, while using Rust for high-level programming was indeed, a costly mistake, Muju is completely different, and this time a low-level language really and truly is appropriate for application programming.

Re:Things you can’t do in Rust (and what to do instead) by twic on Saturday May 15, 2021 @10:43AM (#27165632)
There's something to this. Rust was built to do low-level programming well, and as a result it's quite hard. It's fundamentally more work to do things than in a GC'd language of similar modernity. That's a perfectly reasonable tradeoff.

But somehow, Rust got cool, and now a large fraction of its community wants to use it to write web services. So there's a lot of gravity dragging the ecosystem, and even the standard library and the language, in that direction. Even though it is a poor choice for almost all web services.

One day, the shine will wear off, and it will be easy to see that it's a poor choice for almost all web services, and we will feel some regret over the amount of time and energy that went into building in that direction.

Re:Things you can’t do in Rust (and what to do instead) by steveklabnik on Saturday May 15, 2021 @01:46PM (#27167304)
> it will be easy to see that it's a poor choice for almost all web services

Time will tell. I used to think this way, but don't anymore.

That doesn't mean it's right for the majority of them, but I think it's workable for a very surprising number of them.

Re:Things you can’t do in Rust (and what to do instead) by twic on Saturday May 15, 2021 @02:55PM (#27167873)
"workable for a very surprising number of them" seems substantially the same as "a poor choice for almost all" to me!
Re:Things you can’t do in Rust (and what to do instead) by steveklabnik on Saturday May 15, 2021 @03:24PM (#27168095)
Time will tell :)
Re:Things you can’t do in Rust (and what to do instead) by the__alchemist on Saturday May 15, 2021 @11:03AM (#27165806)
Agreed - I built a rust frontend framework, and tried to use it on the backend for a while. Ended up switching back to Python and Javascript for web - I use rust for embedded mostly now.
Re:Things you can’t do in Rust (and what to do instead) by hu3 on Saturday May 15, 2021 @11:12AM (#27165912)
Like Uber, some do manage to avoid the pitfall of trying to shoehorn hard languages everywhere. I recently learned their microservice fleet is almost entirely in Go [1]. Could also have been C#, Java, Python or Node but the point is it is not Rust or C++. Probably for the reasons you stated.

[1] https://news.ycombinator.com/item?id=27120689

Re:Things you can’t do in Rust (and what to do instead) by littlestymaar on Sunday May 16, 2021 @08:38AM (#27173276)
For companies like Uber, Rust would probably be a good fit if they started today: at this scale you spend more time optimizing some otherwise simple logic in order to scale up without wasting too much resources. Go has a decent optimization story, thanks to the escape analysis diagnostic which makes it quite straightforward to avoid many allocations (much more easily than in C# for instance, even if it's also doable in C# indeed), but Rust takes it step farther, and you'll have better performance to begin with, which will drastically reduce your scaling effort.

For instance, look at what Cloudflare ended up doing to get Go working as they wanted: https://blog.cloudflare.com/go-dont-collect-my-garbage/

Rust will never be a competitor to Python or PHP (but it can enhance them, because making a native extension in Rust in way easier than in C, especially for people with a web back-end background and little C experience), but Go is losing a lot of appeal now that Rust is here ready for prime time.

Re:Things you can’t do in Rust (and what to do instead) by johnnycerberus on Tuesday May 25, 2021 @08:43PM (#27284729)
You have some unsubstantiated claims. Firstly, Go focuses on infrastructure, it is actually the bootloader of cloud-native wave. Rust is great but still, it can be replaced by C, C++ or Zig when it becomes stable. It doesn't have its own ecosystem nor there's any ROI coming out from there to say that it will replace Go tomorrow. On the other hand, when it comes to modern DevOps, Go became as irreplaceable as Python and Bash. Using Rust won't translate into better performance without effort. Because of its focus on soundness, I would say that you need to put in even more effort.
Re:Things you can’t do in Rust (and what to do instead) by littlestymaar on Monday June 07, 2021 @03:44AM (#27420081)
> On the other hand, when it comes to modern DevOps, Go became as irreplaceable as Python and Bash

Most devops don't use Go and I argue that for the ones who do, Rust is a big improvement. Sure Go is being used to make Docker and k8s, but with this reasoning Haskell is also irreplaceable since Pandoc is made with it… Ironically enough, the mere existence of docker negates the main asset of Go in a devops context: statically linked binaries. Without containers, it's a huge selling point, but as soon as you use docker it brings nothing to the table anymore.

> Using Rust won't translate into better performance without effort. Because of its focus on soundness, I would say that you need to put in even more effort.

Saying so reveals that you've probably never tried it. The biggest performance issues I've been facing where memory allocations. With Go, things are “magically” allocated or not depending on the compiler's mood of the day (or the compiler version in practice) and you need to diagnoses these by looking through the escape analysis log, see when the compiler cannot elide the allocation and refactor until it works. With Rust, you just don't allocate memory unless you're using a `Box` or heap-allocated collection (a Vec or a HashMap for instance).

In both case you can have an implementation with a good performance, but with Go you need tedious tuning, while Rust gives you an explicit control of the allocations. That's an enormous productivity difference.

Re:Things you can’t do in Rust (and what to do instead) by dathinab on Saturday May 15, 2021 @08:16AM (#27164513)
> more capable end of the spectrum

Actually rust is a grate language for programmers of the less capable end of the spectrum.

While it allows clever abstractions it generally discouraged and recommended to write simple code.

The borrow checker might seem like a clever abstraction, but it's just a build in code analytics tool you should use anyway when using C or C++ or well any language, and it generally nudges you to better structured code.

> Then, as now, they were people who hadn't had much contact with the average software developer and with the realities of software mass-production.

Except that more than just a few decisions in the rust design process where strongly influenced by the feedback of average developers, including people which just got started with programming.

Wrt. C++ I can completely agree, it's a completely over engineered language with endless gotchas with silently sneak into you code without you noticing and potentially causing UB if compiled with some compiler in some optimization levels for some target. Making such bugs completely bonkers to track down.

On the other hand in (safe) rust many of the problems user have come from the language helping you to not run into any of this and other bugs.

And all "hidden" complexity rust has is normally designed in a way so that you don't need to know it to use rust or even things related to it as long as you don't want to create some low level primitives which involve unsafe code.

Re:Things you can’t do in Rust (and what to do instead) by nindalf on Saturday May 15, 2021 @08:41AM (#27164684)
To put it simply - Rust empowers a master like dtolnay to create something as powerful, zero cost, fast and easy to use as serde … while also enabling a noob like me to write simple, relatively bug free code.

As a bonus I can pull in serde with one line and use it without worrying about shooting myself in the foot.

Re:Things you can’t do in Rust (and what to do instead) by pron on Saturday May 15, 2021 @08:33AM (#27164622)
That is exactly what we thought about C++. We, too, believed that C++ fixed all those problems with both low-level programming in C, and the "messy" programming of the "application generators" of the time; it lets you clearly express intent and yet helps you avoid shooting yourself in the foot as happens in C. Anyone who truly believes that Rust is a great language for the average applications developer, clearly has not met one.
Re:Things you can’t do in Rust (and what to do instead) by est31 on Saturday May 15, 2021 @08:51AM (#27164746)
I think you have a point that yes, programming languages depend on the domain a program is in. If the program only handles up to 10k customers, it can be programmed in javascript and can indeed keep its entire database in RAM. sqlite even has a mode for this. A LOT of custom software is in this "small" domain. However, when you get to millions or billions, maybe you have to optimize and create a backend. What should this backend be written in? Previously the answer might have been C++. But now it's Rust.

Personally, being a Rust enthusiast, I think that Rust's benefits don't just unleash when you think about performance, but also when you think about large codebases. Such codebases are usually the scene for refactorings. In a dynamic language like js, these are extremely hard to pull off. In Rust, the compiler won't stop yelling at you until you have cleanly finished the refactor. I love refactoring Rust codebases, even ones I didn't write, while in C++ or other languages it's extremely annoying.

And note that while C++ enthusiasts might have believed that everything should be C++, not everyone followed them. Many people still stayed with C. Many still do even with Rust around. But there is a small group of people for whom Rust is such a great improvement that they take the portability cost and switch to Rust. Linus is heavily anti C++ for example, but he's open to adding Rust to the kernel.

Re:Things you can’t do in Rust (and what to do instead) by hu3 on Saturday May 15, 2021 @02:00PM (#27167420)
> However, when you get to millions or billions, maybe you have to optimize and create a backend. What should this backend be written in? Previously the answer might have been C++. But now it's Rust.

Now it's Rust based on what? Uber backend is almost entirely built in Go. And so are many other services handling billion plus requests a day written in other languages.

Perhaps Rust advocates know something that Uber engineering does not.

Re:Things you can’t do in Rust (and what to do instead) by est31 on Saturday May 15, 2021 @10:38PM (#27170764)
Go usage proves my point. It's statically compiled. In fact, Google wanted a language in the same performance class as C++ but that was easier to teach to college graduates. Rust is also such a language. Furthermore, when Uber got started, Rust hasn't even been available.
Re:Things you can’t do in Rust (and what to do instead) by hu3 on Sunday May 16, 2021 @03:47AM (#27171969)
Rust being easier to teach than C++ is a very low bar to clear.

And for the record, when Uber got started Go wasn't available either.

Re:Things you can’t do in Rust (and what to do instead) by golergka on Saturday May 15, 2021 @09:56AM (#27165277)
> However, when you get to millions or billions, maybe you have to optimize and create a backend. What should this backend be written in? Previously the answer might have been C++. But now it's Rust.

Neither Facebook, nor Instagram or Slack are primarily built on C++ or Rust though. And many other products that I can't as confidently remember from the top of my head aren't.

Re:Things you can’t do in Rust (and what to do instead) by est31 on Saturday May 15, 2021 @10:36PM (#27170754)
Facebook originally did compile their PHP to C++ though. https://en.wikipedia.org/wiki/HipHop_for_PHP

Only later did they introduce Hack and HHVM, which compiles a PHP dialect in a just in time fashion. My point is that once you reach scale, and your computer bill becomes significant enough, you'll really want to use efficient languages.

Re:Things you can’t do in Rust (and what to do instead) by zozbot234 on Saturday May 15, 2021 @09:00AM (#27164803)
> Anyone who truly believes that Rust is a great language for the average applications developer, clearly has not met one.

What's a better general-purpose language for this mythical "average" developer? Java/C#? Rust has the same level of memory safety, and adds data-race safety that these languages do not have out of the box. Go is in the exact same boat, btw - memory safe for sequential code, but concurrent code is tricky since unsafe shared access is ubiquitous in real-world Go code. Haskell, Agda and Idris could provide more safety but are not approachable to the "average" dev.

Re:Things you can’t do in Rust (and what to do instead) by pron on Saturday May 15, 2021 @09:18AM (#27164933)
> Haskell, Agda and Idris could provide more safety but are not approachable to the "average" dev.

You (rightly, I think) place Idris (and Agda, although that's more a proof assistant than a PL) beyond the reach of the average developer, and also, apparently, Haskell -- arguably a simpler language than Rust, but never mind -- but not Rust. And that's my point and, I guess, our point of disagreement. If you think that, on that spectrum between, say, Python and Idris, Rust is at a good level for the average application developer to the point where maintaining high-level applications written in Rust would ever be cost effective, then I think you are out of touch with the realities of the software industry and the economic forces that shape it. I thought the exact same thing as you twenty five years ago: C++ was obviously the right language for the average developer -- even more so than, I don't know, Delphi or Visual Basic -- wasn't it?

> What's a better general-purpose language for this mythical "average" developer?

I don't believe any low-level language will be cost-effective for application development for the foreseeable future, if ever, and the average developer is anything but mythical (I mean, embodied as a single person, perhaps, but I'm talking about teams).

> Rust has the same level of memory safety

It doesn't (due to much more prevalent reliance on unsafe as well as FFI), but that's very much beside the point because, as you acknowledge, safety is not what it's about.

Re:Things you can’t do in Rust (and what to do instead) by dathinab on Saturday May 15, 2021 @01:37PM (#27167224)
> Haskell -- arguably a simpler language than Rust

From a PL research point of view maybe.

But from a POV of what is simpler to use for a average or new programmer, Haskell is far worse as far as I can tell.

> due to much more prevalent reliance on unsafe as well as FFI

Where? In embedded programming? Or programming from primitives (which I would argue a average programmer never should do, there are existing libraries)?

In some use-cases you always end up with a FFI, but that is also true for other languages.

Besides that usage of unsafe is both strongly discouraged and uncommon.

There are a lot of rust use cases where using unsafe code is never necessary to a point where people simple ban any direct usage of unsafe code in their project.

Re:Things you can’t do in Rust (and what to do instead) by ta_ca on Saturday May 15, 2021 @09:46AM (#27165182)
simplicty is important, but i believe it is not the most important metric for a PL and have no problem with complex PLs. the question; is it worth the trouble? c++s failure is not the complexity but c++ being one of the least orthogonal languages out there. in c++ you are able to compose two great things/ideas (other than my only options are c and c++ this is the biggest reason i prefer c++ over c) yet the end result is not more but less.
Re:Things you can’t do in Rust (and what to do instead) by llogiq on Saturday May 15, 2021 @11:15AM (#27165945)
Well, I have been writing both high and low level code in Rust, and I must admit I've been happily falling into that "trap". The nice thing about Rust for high level software is that it lets us specify interfaces in a way that makes them actually usable without delving into the low level details.

A lot of things that are hand waved away in C++ (who owns this? How long does this need to be alive? Can I mutate this?) are completely explicit in a Rust interface. And Rust's type system is strong enough to express a lot of rules that no one would want to write down in C++ (because overriding them is just one cast away), allowing us to write hard-to-misuse libraries.

Coding on top of such libraries is a really fun experience. That's why I call Rust an all level language.

Re:Things you can’t do in Rust (and what to do instead) by pron on Saturday May 15, 2021 @01:55PM (#27167376)
Different languages appeal to different people, and there is no doubt some individual programmers will find Rust appealing even for application programming, just as some found C++ appealing for similar purposes. But a CIO of, say, an insurance company who decides that internal applications will be written in Rust would be making a very imprudent financial decision.
Re:Things you can’t do in Rust (and what to do instead) by himujjal on Saturday May 15, 2021 @11:41AM (#27166199)
Rust is not at all a high-level language in any sense and will not replace the places Kotlin, Go, TypeScript etc occupy. If I wanted to write a super-fast server with some time constraints, I would choose Go without thinking twice. Go is fast enough. Rust is only needed when you need things to be super-duper fast and memory efficient. Those two criterias are the only reasons to use Rust.
Re:Things you can’t do in Rust (and what to do instead) by layoutIfNeeded on Saturday May 15, 2021 @08:02AM (#27164449)
Every generation must go through these cycles. Visual programming, no-code solutions, thin clients, thick clients, static typing, duck typing, functional programming, etc.

Time is a flat circle.

Re:Things you can’t do in Rust (and what to do instead) by geofft on Saturday May 15, 2021 @08:35AM (#27164641)
"Software should be developed by small elite groups" is pretty much the opposite of the Rust developers' goal. I do agree with you that it's a bad goal to have, which is why I'm optimistic about Rust's success.
Re:Things you can’t do in Rust (and what to do instead) by mjw1007 on Saturday May 15, 2021 @08:23AM (#27164551)
I observe that the last sentence of your first paragraph is strongly at variance with the Rust leadership's self-image.

(See for example the "Empowerment, empowerment everywhere" RustConf 2020 keynote.)

Re:Things you can’t do in Rust (and what to do instead) by the__alchemist on Saturday May 15, 2021 @10:33AM (#27165570)
I do mostly embedded programming. Performance and ability to access memory directly is critical! But I like taking advantage of modern tooling, and abstractions like pattern matching, traits etc, and clear syntax. Changing languages through an FFI barrier would add complications.
Re:Things you can’t do in Rust (and what to do instead) by ta_ca on Saturday May 15, 2021 @09:20AM (#27164949)
didn't lisp prove the opposite? you can go lower than c and higher than any language we currently have in the same language?
Re:Things you can’t do in Rust (and what to do instead) by hu3 on Saturday May 15, 2021 @02:08PM (#27167488)
Yes but where is Lisp market share? It's mostly an academic language these days.

If anything Lisp current adoption proves that aiming to tackle both ends of the spectrum in a single language might not be a good idea.

Re:Things you can’t do in Rust (and what to do instead) by ta_ca on Saturday May 15, 2021 @02:44PM (#27167799)
do adoption or market share matter in this context? if you can have best of the both worlds why would you want to deal with an another language?
Re:Things you can’t do in Rust (and what to do instead) by astrange on Saturday May 15, 2021 @10:32PM (#27170737)
There are downsides to using the most powerful option at all times.

https://en.wikipedia.org/wiki/Rule_of_least_power

Also, Lisp is the most powerful at constructing programs but that means it's the least powerful in the field of making sure your program actually does what you wanted it to - that's what types, borrow checking, proof assistants and so on are for.

(Some people think Lisp is declarative because it's homoiconic but that's not true - you can't find out what a Lisp macro does without executing it.)

Re:Things you can’t do in Rust (and what to do instead) by daniel42__ on Wednesday May 19, 2021 @04:49PM (#27214284)
why do high-level languages almost always run inside an interpreter/vm? (except swift/go)

is it a good or a bad thing?