News for hackers. Stuff that matters.
Re:Ask HN: Why do you use Rust, when D is available? by mrfusion on Friday June 12, 2020 @12:14AM (#23495960)
I’m currently trying to get into robotics. But why does everyone want c++? Surely robots can be programmed in other languages.
Re:Ask HN: Why do you use Rust, when D is available? by blub on Friday June 12, 2020 @04:57AM (#23497366)
Because the real world doesn't really match the expectations and statements of the HN community. It's really rare that I see here anything pragmatic regarding what programming languages to learn/use.

The community lives in a bubble and is out of touch with mainstream software development.

Re:Ask HN: Why do you use Rust, when D is available? by Recurecur on Friday June 12, 2020 @09:48AM (#23499191)
I'm a very senior engineer. I've had a strong desire to find a better alternative to C++ since the 90s when I was first exposed to it (I worked with it for about a decade, after a few years with C). Now, decades later, enough bandaids have been applied that it's somewhat tolerable. Congratulations...?

The industry has needed good alternatives for a long time. Finally, they're coming, and not nearly soon enough to suit me! :-)

Re:Ask HN: Why do you use Rust, when D is available? by blub on Sunday June 14, 2020 @06:52AM (#23516682)
I believe you're right about those alternatives not coming soon enough. If all things go right, by the time Rust will be (sort of) mainstream you'll be able to set up the "Rusty Grampas League" :-)
Re:Ask HN: Why do you use Rust, when D is available? by MacSystem on Wednesday June 17, 2020 @02:50PM (#23555183)
What are thoughts on D?
Re:Ask HN: Why do you use Rust, when D is available? by vardump on Friday June 12, 2020 @07:00AM (#23498007)
"pragmatic /praɡˈmatɪk/ adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical considerations."

I consider Rust more pragmatic at this point. Perhaps it's because I code in C++ as my dayjob and have to deal with the consequences.

In theory, C++ is perfect given perfect developers. In practice, it's more sensible and realistic to write tricky, like multithreaded, code in Rust.

One rarely mentioned important factor: fear. It's much less scary to modify something written in Rust than in C++. Doubly so for less experienced developers.

Re:Ask HN: Why do you use Rust, when D is available? by danielscrubs on Friday June 12, 2020 @05:59AM (#23497671)
I'd wager we actually have a lot of clever teenagers here at HN. Well-meaning, but has never worked in a team nor has any experience of what the market rewards.
Re:Ask HN: Why do you use Rust, when D is available? by mratsim on Friday June 12, 2020 @05:12AM (#23497440)
Technically robotics isn't mainstream, Javascript/PHP/Java/C# are, at least in terms of developers. Now in terms of code deployed, C on the billions of embedded devices may be able to compete with servers?
Re:Ask HN: Why do you use Rust, when D is available? by _bxg1 on Friday June 12, 2020 @12:30AM (#23496038)
A language is more than just a technology: it's an ecosystem of libraries, platform APIs, developer mindshare and experience, familiarity, legacy codebases, product support. Don't discount the weight of all of those auxiliary, human factors.

Rust, culturally, comes from the web. That's why it has the most traction in the web server/WASM space for now. It's starting to poke its head into Systems use-cases because of the sheer weight of its memory safety benefits there. Maybe in a few years it'll get some real use in the games industry (real industry; not just enthusiasts), though Unreal remains a bastion of C++ that isn't going anywhere anytime soon. But then there are some dark corners of C/C++'s territory that move even more slowly, and where the cultural shift will take a long time. I think to a great extent, embedded falls into that category.

Re:Ask HN: Why do you use Rust, when D is available? by timw4mail on Friday June 12, 2020 @09:11AM (#23498848)
Not really. While there is a growing set of web-based application for Rust, it's not like PHP, where the very purpose of the language is the web. Rust is a system language before it is a web language.

WASM as a target is actually a great indication that it's a system language -- performance is a primary consideration.

Re:Ask HN: Why do you use Rust, when D is available? by _bxg1 on Friday June 12, 2020 @10:35AM (#23499614)
You're missing the point. The point is that Rust came from Mozilla. Its mind-share started with web people and is expanding from there. What I'm trying to get across is that those social forces can matter more for adoption than just the tech's appropriateness, considered in a vacuum.
Re:Ask HN: Why do you use Rust, when D is available? by setr on Friday June 12, 2020 @12:41PM (#23500979)
In that case, it came from Mozilla for working on a web browser, with primary goals of security, building sandboxes & language runtimes (js), and replacing an application-level cross-platform C++ core.

Which is very different than "web people", which in my mind implies webdev -- html/css/js + API server/db/caching backend.

Which also further explains why WASM is so far along (sandbox, security), much better than any association with webdev itself; but not kernel-level system development. (But if the web browser is an userspace OS... then it's probably not that far from it)

Re:Ask HN: Why do you use Rust, when D is available? by type0 on Friday June 12, 2020 @06:37PM (#23504593)
Off course it's a system language, there are even some that try to build an OS in Rust

https://www.redox-os.org/

Re:Ask HN: Why do you use Rust, when D is available? by pjmlp on Saturday June 13, 2020 @11:40AM (#23510197)
Everyone is targeting WASM nowadays.
Re:Ask HN: Why do you use Rust, when D is available? by Recurecur on Friday June 12, 2020 @09:44AM (#23499152)
> But why does everyone want c++?

Few "want" C++, but for robotics a non garbage-collected language is necessary so latency is predictable. There are few mature languages besides C/C++ in that category.

Rust is an improvement, but I'm hopeful something like Julia (Julia Robotics, https://juliarobotics.org/) or Scala Native (https://scala-native.readthedocs.io/en/v0.3.9-docs/) becomes mainstream, the productivity gains would be substantial.

Re:Ask HN: Why do you use Rust, when D is available? by WorldMaker on Friday June 12, 2020 @08:03PM (#23505260)
Garbage-collected languages can have (and some have had) latency-predictable GCs. It's not entirely an either/or, it's something of a false dichotomy. "Non-garbage collecting" languages blur the line anyway because even basic things like reference-counting are still a garbage collection technique. The trade-offs are in how many control knobs and where those knobs are/how you turn them, and a lot of developers still seem to feel much more "comfortable" manually writing all the knobs by hand than trusting a more algorithmic GC's shiny chrome knobs on the outside of (what they presume to be) a black box.

But perceived "comfort" isn't entirely reality. (The comfort of smart GC languages is immense in a different way.)

Re:Ask HN: Why do you use Rust, when D is available? by Recurecur on Saturday June 13, 2020 @10:01AM (#23509399)
Something of a false dichotomy - perhaps. The fact is that allocating at all during realtime operation is frowned upon. Given that the best approach is pre-allocation and then turning off the GC, why carry the overhead of the GC at all?

For 99% of realtime work, the Rust or Scala Native approach is just fine. No GC required. Julia users can just use the pre-allocation approach.

The important thing is avoiding language patterns that encourage needless allocation.

Re:Ask HN: Why do you use Rust, when D is available? by WorldMaker on Monday June 15, 2020 @12:46PM (#23529435)
> Given that the best approach is pre-allocation

GC languages still support stack allocation, you don't have to pre-allocate anything you can stack allocate. (That's where .NET Core has been especially burning rubber in recent releases. Span<T> is a stack allocated, GC-safe "pointer", for instance, that is doing all sorts of heavy lifting in .NET Core performance-critical work these days. It's still early too, as not everything has moved to Span<T> that can move to Span<T> and family.)

But also, not everything needs to be pre-allocated for the "best approach". There's some work to get used to the feel of any specific GC, but most modern "VM" GCs (.NET and today's Java, not yesterday's) are multi-generational and there's a lot you can do in strategies such as "focus on the nursery and the LOH" (using only [potentially many] small short-lived objects and a few, mostly stable "very large" objects, avoiding the intermediate generations).

> why carry the overhead of the GC at all?

Safety. (Why wear seatbelts?) Rust's borrow checker is great but it still requires a lot of manual adjustment and it's still possible to miss something (it's not easy, certainly, but it is possible); a GC gives you safety by default, with no manual intervention required to guarantee safety, and requires manual effort to write unsafe code.

> The important thing is avoiding language patterns that encourage needless allocation.

That's where we agree and why I'm very adamant that though some of the tools ("knobs") look scarily different in performance optimization for GC versus non-GC languages, the vast majority of the tools are the same: know the O(memory) of your algorithms, and make smart trade-offs regarding that O(memory), avoid allocating what you don't need, know your trade-offs between pre-allocation and allocation only when necessary, etc.

Re:Ask HN: Why do you use Rust, when D is available? by danielscrubs on Wednesday June 17, 2020 @04:49AM (#23549268)
> it's still possible to miss something

Could you elaborate?

Re:Ask HN: Why do you use Rust, when D is available? by WorldMaker on Wednesday June 17, 2020 @01:25PM (#23554073)
Tbf, I've not directly worked in Rust so my understanding is mostly academic of a sort. The issues I'm directly aware of are primarily in boundary conditions between unsafe and borrow-checked code, which isn't entirely fair to Rust as GC-languages of course have the same boundary conditions. My impression however is that because the borrow checker is a lot of work, there's a lot more Rust libraries in the wild with unsafe code sections than strictly need to be (as compared to similar libraries in GC-languages, and especially with modern tools like Span<T> in .NET nearly shrinking GC-unsafe blocks to non-existent in modern code).
Re:Ask HN: Why do you use Rust, when D is available? by pjmlp on Saturday June 13, 2020 @03:48AM (#23507678)
PTC and Aicas sell real time Java implementations for robotics, among other similar deployment scenarios, lack of customers is something that they don't suffer from.
Re:Ask HN: Why do you use Rust, when D is available? by rozab on Friday June 12, 2020 @11:01AM (#23499910)
For some reason Python seems to be very popular in academic robotics right now. Not a great choice
Re:Ask HN: Why do you use Rust, when D is available? by Recurecur on Friday June 12, 2020 @12:54PM (#23501153)
Being a "better, stronger, faster" Python is fairly near Julia's sweet spot... :-)
Re:Ask HN: Why do you use Rust, when D is available? by type0 on Friday June 12, 2020 @06:32PM (#23504558)
> Not a great choice

It is a great choice to prototype the ideas

Re:Ask HN: Why do you use Rust, when D is available? by DarmokJalad1701 on Friday June 12, 2020 @11:10AM (#23500020)
As a datapoint/anecdote, I work in an autonomous vehicle company and we have adopted Rust extensively in our codebase in the last six months or so.

Previously, the code base was primarily Python with some C++. Now there is a significant chunk of code, particularly related to safety, written in Rust.

Re:Ask HN: Why do you use Rust, when D is available? by MacSystem on Wednesday June 17, 2020 @03:02PM (#23555325)
That's interesting. But did your company consider using D? if so, why did chose Rust?
Re:Ask HN: Why do you use Rust, when D is available? by calaphos on Friday June 12, 2020 @07:08AM (#23498053)
Rust is very very new compared to Cpp. People have decades of experience with cpp, learned in in University. Why would you throw all of that overboard just to learn a fancy new language with a weird ownership system? Keep in mind that people often still write cpp98 and have a rely hard time getting used to newer cpp concepts and programming styles. And all of that is backwards compatible with their existing codebase.
Re:Ask HN: Why do you use Rust, when D is available? by Aeolun on Friday June 12, 2020 @07:43AM (#23498246)
> Why would you throw all of that overboard

Firstly, because 75% of all that knowledge is easily transferrable.

Secondly, because you want to take 50% of your bug count.

Re:Ask HN: Why do you use Rust, when D is available? by zucker42 on Friday June 12, 2020 @11:03AM (#23499947)
He was saying this in the context of "why do people still use C++ at all".
Re:Ask HN: Why do you use Rust, when D is available? by bjourne on Friday June 12, 2020 @09:11AM (#23498846)
But why not program in Python and take 100% of your bug count?
Re:Ask HN: Why do you use Rust, when D is available? by UncleMeat on Friday June 12, 2020 @10:44AM (#23499709)
It is slow.

It doesn’t work well for embedded programming.

It very much does not fix all bugs, especially given lack of static type checking.

Re:Ask HN: Why do you use Rust, when D is available? by dpc_pw on Friday June 12, 2020 @05:08PM (#23503942)
It will sound harsh, but people who can't up their game from C++98 to C++11, are probably not a people that I would consider hiring anyway. Generally, personally I would not hire anyone that knows just one programming language that they've learned in University and for years didn't manage to practice anything else, but that's just me.

I actually worked in Automotive, and the software higher level up the stack there is usually god damn awful piece of s*, often done by people who have almost no clue what they are doing, with plenty of misconceptions about how C/C++ even really works (using `volatile` for concurrency/atomicity and stuff like that). They are just beating their spaghetti code from segfault to segfault for decades.

This and slow delivery process easily explains why entertainment, navigation and other software-driven part of mainstream cars are so buggy, slow and generally terrible, and why Tesla could have so easily deliver way better experience.

So it doesn't matter that some people can't "get into Rust". The business that hire them will be replaced if they can't up their game, that's all.

Re:Ask HN: Why do you use Rust, when D is available? by MacSystem on Wednesday June 17, 2020 @03:07PM (#23555412)
If D have had a proper tooling, like C# and VS, do you think companies in the automative would consider to use D instead of C++?
Re:Ask HN: Why do you use Rust, when D is available? by PopeDotNinja on Friday June 12, 2020 @04:02AM (#23497093)
Probably the same reason Python is big in scientific computing. A lot of stuff has already been written for it. If scientists needed to bootstrap scientific computing from scratch, Python wouldn’t be any more established than Rust, Java, PHP, or VB6.
Re:Ask HN: Why do you use Rust, when D is available? by calaphos on Friday June 12, 2020 @07:13AM (#23498080)
Afaik pythons success in that field is relatively recent, only really taking of ~2010. The language was already 20 years old by then. Compare that to rusts first stable release in 2015.

Building ecosystem just takes time.

Re:Ask HN: Why do you use Rust, when D is available? by MacSystem on Wednesday June 17, 2020 @03:08PM (#23555428)
Python is easy to just start writing then the network effect made others use it
Re:Ask HN: Why do you use Rust, when D is available? by flor1s on Friday June 12, 2020 @04:16AM (#23497161)
Check out https://www.ros.org - it allows you to program in either C++ or Python (with some other languages being supported by the community)
Re:Ask HN: Why do you use Rust, when D is available? by jki275 on Saturday June 13, 2020 @09:12AM (#23509128)
The problem is that whIle C++ has problems, all languages have problems and C++ has the most going for it in terms of being fast and easy to write.

C++11 is a really good language. Also there are tons of libraries and things people have already built in it that you can leverage to reduce development time.