News for hackers. Stuff that matters.
Re:C++ Frequently Questioned Answers (2009) by otabdeveloper4 on Sunday January 23, 2022 @07:48AM (#30045775)
> seeing a kid fresh out of college fearlessly writing performant code by leveraging the amazing Rust compiler

A nice (and very ridiculous) fantasy, but no.

As a person who hires developers to write performant code, I'd love it if there were these magical junior Rust developers who can write performant code.

But as the market exists right now, Rust developers are twice as expensive and the product they deliver is twice as bad.

The only way I can justify Rust to higher management is selling it as a vanity PR project.

Re:C++ Frequently Questioned Answers (2009) by zozbot234 on Sunday January 23, 2022 @11:35AM (#30047519)
The main point of Rust is correctness, not performance. Performant code is a nice to have - but when the two are in conflict, correct code wins every time. How can one ever be confident that your Senior C++ devs are writing code that is free of subtle bugs? Are you going to look for professional Haskell or Ocaml devs too, for a proper comparison? Those folks ain't cheap, either.
Re:C++ Frequently Questioned Answers (2009) by mbrodersen on Sunday January 23, 2022 @09:23PM (#30052959)
I maintain large scale C++ code that hasn’t had a bug in production for 5+ years. I do it using lots of system level tests. So it is very much doable. It has nothing to do with the programming language. Yes some languages (Haskell for example) completely eliminate a large class of bugs, and I would prefer to use languages like that, however the world runs on C/C++. So having solid C++ skills is great for your career.
Re:C++ Frequently Questioned Answers (2009) by dureuill on Sunday January 23, 2022 @08:52AM (#30046107)
> But as the market exists right now, Rust developers are twice as expensive and the product they deliver is twice as bad.

What? Why? I've been developing C++ for 10 years and seen firsthand the problems it causes and that are addressed by Rust. If I start writing Rust I'm going to be more productive (from build system to maintenance), write more performant and reliable code faster, so I don't see how the delivered product would be worse, as I'd have more time to iterate.

About the rate, maybe that would be more expensive, but I'd say it's still worth it. Anyway, it's not like getting competent C++ developers is cheap either.

As for GP's message, I agree it looks unrealistic that "kid fresh out of college" would magically write performant code because they're writing rust. There is more to performance than the language, and it is particularly easy to write bad performance code in rust (and in C++ I must add). That being said, I'd still be less anxious to have a junior in a rust codebase than near a C++ one.

Re:C++ Frequently Questioned Answers (2009) by otabdeveloper4 on Sunday January 23, 2022 @08:59AM (#30046160)
> If I start writing Rust I'm going to be more productive (from build system to maintenance), write more performant and reliable code faster, so I don't see how the delivered product would be worse, as I'd have more time to iterate.

Maybe it's true for you, but I can hire a competent C++ programmer to deliver code faster for less than what you'd ask.

Also, if a programmer is spending time "iterating" on a performance problem, he's already underperforming. That's okay for less experienced developers as part of the learning process, but expecting it to be the norm? No.

> About the rate, maybe that would be more expensive, but I'd say it's still worth it.

Real-world metrics do not agree.

Re:C++ Frequently Questioned Answers (2009) by spoiler on Sunday January 23, 2022 @09:29AM (#30046367)
> Also, if a programmer is spending time "iterating" on a performance problem, he's already underperforming. That's okay for less experienced developers as part of the learning process, but expecting it to be the norm? No.

I don't think the OP meant iterating on performance problems specifically, just generally iterating on code as one does when they write it.

Also, every programmer at some point iterates about performance problems, not matter their experience, or language (or implementation), or runtime that's being used.

I think the original "uni grad can write better Rust code than experience C++ dev can write C++" is a hyperbole. I don't think they meant better, but the Rust developer will need less context to implement the same feature.

The spirit of that sentence was probably "it's simpler to write performant and safe code in Rust than C++". But again, without really agreeing what "performance" means here, it's a bit silly to discuss.

Performance is such a complex that can mean so many things depending on the problem. So, I we're all nit-picking about something without even agreeing what they're specifically nit-picking about.

The default IO mode in C/C++ is buffered. Rust requires you to wrap it in `BufWriter`. For most network (or general IO, really) workloads you want buffered IO.

So sure: We could say that writing performant IO code in Rust is more difficult, if we hyper-focus on this one specific detail.

FWIW (and people who're unfamiliar with this): I think switching to buffered IO in Rust is absolutely trivial, and very well documented (in multiple places where it's relevant). In fact more so than it is to switch to unbuffered IO in C++, because you have to call `setbuf` with "special" values to disable buffering.

We can then argue that experience/wisdom diminishes most of these arguments about performance, but it diminishes them on both sides.

Re:C++ Frequently Questioned Answers (2009) by dureuill on Monday January 24, 2022 @01:44AM (#30054344)
> I don't think the OP meant iterating on performance problems specifically, just generally iterating on code as one does when they write it. Also, every programmer at some point iterates about performance problems, not matter their experience, or language (or implementation), or runtime that's being used.

Exactly, on both accounts, thanks.

It strikes me as odd that GP would describe "iterating on performance" as "underperforming", unless GP is in a very specific domain where the performance requirements are always known in advance and where they never change. Getting the last drop of performance from code is a trade-off. It impacts the readability and maintainability of code. To get the last drop, it can depend on the shape of your expected input data, and it requires looking at the produced assembly and performance profiling results to find bottlenecks and act on them. This alone implies iteration. If you're telling me that your engineers know their compiler so well that they can tell in advance what assembly code will be generated when changing seemingly unrelated parts of the code, eg they know the inlining limits of their compiler, I call BS.

Iterating on performance takes time to develop and maintain, which is why it should be done just enough to meet the requirements, in particular in the hot loop and to reduce bottlenecks. If your developers are optimizing all the code they write to the ASM instruction, they are probably underperforming (unless specific domain where so little code is written or the target is so small that the benefit is worth the cost). Understanding that trade-off is part of seniority (aka juniors will often both "prematurely pessimize" by writing inefficient code without increasing maintenability or in the hot loop and "prematurely optimize" by avoiding allocation at all costs in CLI argument parsing).

[dead]
Re:C++ Frequently Questioned Answers (2009) by mbrodersen on Sunday January 23, 2022 @09:26PM (#30052979)
It is a big part of any language promotion. I remember some Ruby guy claiming that developers are 100 times more productive in Ruby. Yeah right.
Re:C++ Frequently Questioned Answers (2009) by BenjiWiebe on Monday January 24, 2022 @02:20AM (#30054509)
It feels like at least 100x if you are trying to scrape a website and do stuff with the data, and you are comparing C and Ruby...
Re:C++ Frequently Questioned Answers (2009) by mbrodersen on Monday January 24, 2022 @08:14PM (#30066596)
And it feels like 0.0001% if you want to write a fast device driver, game, or anything else performant.
Re:C++ Frequently Questioned Answers (2009) by dureuill on Monday January 24, 2022 @04:14AM (#30055121)
I measured it. On multiple projects. Some I started writing in Rust, so this is not the "rewrite effect" at play. I observe x2 to x3 on development time alone, long term if we compound review, debugging and maintenance I wouldn't be surprised to see if it tends to an order of magnitude of difference.

Results will depend on the available ecosystem for each language for the task at hand. For instance I'd still choose C++ with qt for writing a GUI today.

The reasons why Rust is more productive are easy to understand and touch most of the development steps:

- building is trivial in Rust, adding dependencies also. Depending on how broken the CMake of your C++ dependency is, it can take several days to wrap it so it can be used sanely. The remaining time is dependency review, which must also be taken in C++.

- Development itself is much easier, thanks to Rust's expressive typesystem (mostly sum types and traits) and "functional-lite" iterators (C++ is getting there with ranges but today we're still far from the same ergonomy, we're still missing pattern matching, and views introduce lifetime issues). The sane error/warning demarcation allow to develop without the equivalent of "-WError" (which is hard to do sanely in C++ due to eg missing return being a warning), which allows to use these warnings to drive development (you can stub every function and when you no longer have any "unused variable/unused function" warning, you're done). More generally, Rust removes most of the boilerplate of C++: you don't need to maintain superfluous representations of your interface as headers (the documented interfaces are generated using cargo doc), you can derive `Hash` instead of opening the std namespace, functions and structs definition all start with a keyword so they're easy to grep for, the language being expression oriented means we don't have to rely on immediately invoked lambdas as soon as what we want is to bind a variable depending on an if, we don't have pure stupid boilerplate like the rule of five to enforce, and a thousand of other ergonomic improvements over C++. Rust feels like a language designed by a C++ developer tired of the flaws of C++.

- Since many errors are lifted at compile time, the feedback loop becomes much shorter. On the same library that has both a C++ and a Rust interface, we had memory errors several times due to a function that returns a view of its argument without that being clearly expressed or expected. In C++, this meant looking for what went wrong after a segfault, something that took an hour to two engineers. In Rust, the compiler told us that the particular variable was not living long enough, and went so far as to suggest the fix. Time spent on this: 10 seconds. And this comparison only hold for the memory errors that we did catch in C++...

- Test and documentation use standard tooling that is included by default. The ecosystem documentation is stored on a centralized website, meaning is a single place to look at to find documentation (that at least contains the interface of the library). - Review is made easier with no implicit code paths due to implicit conversions or exceptions. Error handling has the right amount of noise, a single character to pass back the error (possibly adding some context), otherwise a match construct to handle each error case. The error story is not perfect, but much better than in C++. The "dangerous patterns" are made easy to spot (unsafe, unwrap, etc) and should be confined to specific parts of the code (eg hot loops where benchmarks prove that it is necessary). Rust make code review able to focus on the problem at hand rather than the many rules you have to follow to not blow your foot off in C++. In the presence of other developers (or even for myself :-)), it is really welcome.

- Maintenance time is reduced by all of the above, over time, compounded by the ease with which one can refactor Rust code compared to C++ code. If refactoring a module without unsafe there is no chance of introducing memory issues. Generally the strong type system (no implicit conversions) makes it easier to not accidentally introduce logic errors

Now, there are drawbacks to Rust: the ease of adding dependencies means that we can have deeper dependency tree, so this make reviewing dependencies a bit more tedious (thankfully code review is easier). Occasionally the borrow checker comes in and forbid some patterns (mostly when we would write code depending on iterators not being invalidated in C++), and having done less rust than C++ sometimes I need to find the correct pattern for something. On average though, the advantage is very clear.

Re:C++ Frequently Questioned Answers (2009) by ncmncm on Monday January 24, 2022 @07:17PM (#30066106)
Which is it? Barely a day ago, you said "If I start writing Rust..." Now you claim you have been writing Rust all along, on "multiple projects", keeping measurements. Forgive my skepticism.
Re:C++ Frequently Questioned Answers (2009) by dureuill on Tuesday January 25, 2022 @09:05AM (#30071881)
Sorry for not being clear. Should have written "when I start writing Rust" at this point. I have been using Rust personally since 2016, and professionally since 2019. Most of our codebase is naturally still in C++ (we're not aiming at "rewriting the world"), so I can frequently feel the difference between the two languages, which is why my preference is so clear-cut.
Re:C++ Frequently Questioned Answers (2009) by spoiler on Sunday January 23, 2022 @08:39AM (#30046043)
> But as the market exists right now, Rust developers are twice as expensive and the product they deliver is twice as bad.

It's interesting how we have different experiences regarding this. In my experience, it's usually the opposite. And I believe it's mostly because Rust lets you focus more on the problem you're solving, rather than thinking about dos and don'ts of the language.

For example, most Rust projects (or products) seem to have much more polish than equivalent C++ projects (even for ones with years head start). By polish I mean both user experience and the developer experience when one works on the project.

Also, adding user-facing (i.e. UX) polish to Rust projects requires less ahead-of-time planning in my experience.

One reason is that when introducing new Rust code, there's less performance gotchas, and Rust code seems to compose more ergonomically than C++ code... Most of the time at least; there were times that Rust was frustrating. But I think less often probably, _and_ the frustration is compile-time, rather than runtime. Also Rust has a shorter feedback loop due to Rust's incremental compilation really helps mitigate the frustration, so you can iterate faster.

And another is because I've always felt like refactoring Rust code (even with C++ experience than Rust) tends to be easier, and faster to refactor, and I feel bolder while doing it, if that makes sense? Simply because the compiler thinks about various categories of problem domains instead of me, and it tells me about them.

Of course, it's never black and white with any of the above things I mentioned; the situation is grey in both ecosystems. But I think it's a much lighter shade of grey in the Rust space than in the C++ space. And as always, there's always exceptions on either side, too.

EDIT: I quoted OP's full sentence, but then only addressed the last bit. I hopefully clarified in comments below that I wasn't talking about the first part. Sorry about that!

Re:C++ Frequently Questioned Answers (2009) by otabdeveloper4 on Sunday January 23, 2022 @08:54AM (#30046123)
> In my experience, it's usually the opposite.

Obviously your experience doesn't involve budgeting or hiring developers.

Your subjective feelings about how nice or fast it is to write Rust code isn't what we're talking about here.

The original poster claimed that Rust can save money by letting managers hire junior devs to replace senior C++ developers.

This isn't true. Rust developers are much more expensive than C++ developers, and have vastly lower productivity. (No doubt because of their vastly inflated expectations; any Go/Python/PHP developer who upgrades to Rust suddenly thinks they are elite 10x programmers because they have a clue about performance now.)

Re:C++ Frequently Questioned Answers (2009) by lpapez on Sunday January 23, 2022 @09:29AM (#30046370)
> The original poster claimed that Rust can save money by letting managers hire junior devs to replace senior C++ developers.

This is not at all what I said, nor meant. I never said anything about the hiring market, but merely stated a personal observation why I think Senior C++ devs often dislike Rust.

Re:C++ Frequently Questioned Answers (2009) by ncmncm on Sunday January 23, 2022 @06:20PM (#30051693)
You were wrong about that, too:

Senior C++ developers are not impressed with Rust because it doesn't solve any problem they have. Switching to Rust would make them markedly less productive, with no corresponding benefit. The drain comes from slow compilation and from excess design overhead, the need to distort a simpler architecture to satisfy the borrow checker.

Put simply, the extra work to satisfy the borrow checker prevents errors they do not make.

This contradicts Rust propaganda, where a few CVE numbers are cited over and over, echo-chamber style. What these citations never mention is that they are for bugs in mostly very old code. We just don't need to write code that way anymore. It is not just error-prone, it is more work, so there is simply no temptation to write it that way.

I do hear of programmers who have elected to stop learning, and (proudly!) admit continuing to write C++98 or even "C-like C++". We used to say "you can write FORTRAN in any language"; there is no eliminating bad programmers, but plenty of reasons to avoid their product. What conclusions can we make about Rust from its worst adherents?

Re:C++ Frequently Questioned Answers (2009) by tialaramex on Sunday January 23, 2022 @09:53PM (#30053168)
> What these citations never mention is that they are for bugs in mostly very old code.

It is unavoidably true that grave security holes get found only in existing code and not hypothetical future code written with a later language revision and whatever new features will definitely avoid those "errors they do not make". That's time's arrow for you.

Can you name a few of these "Senior C++ developers" and point us to, say, a few years of their work?

Is there a specific vintage of C++ where you feel like, at last, unlike C++ 98 you "don't need to write code that way" and so Senior C++ developers won't make these errors? C++ 11 maybe?

Re:C++ Frequently Questioned Answers (2009) by pcwalton on Monday January 24, 2022 @02:49PM (#30062974)
> Put simply, the extra work to satisfy the borrow checker prevents errors they do not make.

> This contradicts Rust propaganda, where a few CVE numbers are cited over and over, echo-chamber style. What these citations never mention is that they are for bugs in mostly very old code.

Empirically this is not true. https://twitter.com/LazyFishBarrel/ is not citing "a few CVE numbers over and over"; for example, in browsers, new code is disproportionately responsible for vulnerabilities. I know most of the people at the big tech companies doing the research into where the security problems in major C++ software come from; they're not making the results up.

Re:C++ Frequently Questioned Answers (2009) by ncmncm on Monday January 24, 2022 @07:11PM (#30066041)
When I look into these CVEs and see "use after free", I know immediately it is not a problem in modern code.
Re:C++ Frequently Questioned Answers (2009) by kobebrookskC3 on Sunday January 23, 2022 @11:49PM (#30053855)
> it doesn't solve any problem they have

you mean a problem blithely ignored until the software becomes important enough to attack, at which point, it's too late to rewrite the "very old" code? https://googleprojectzero.blogspot.com/2022/01/zooming-in-on...

> errors they do not make.

bullshit. a quick look at oss-fuzz on c++ projects, many of them in modern c++, will show that they are teeming with memory unsafety.

> there is no eliminating bad programmers, but plenty of reasons to avoid their product.

on an unrelated note, what product are you responsible for, so i can avoid it?

Re:C++ Frequently Questioned Answers (2009) by ncmncm on Monday January 24, 2022 @01:20AM (#30054241)
There is no possibility you could ever afford it.
Re:C++ Frequently Questioned Answers (2009) by kobebrookskC3 on Monday January 24, 2022 @04:33AM (#30055258)
the world can't afford new code written in a blatantly memory-unsafe language
Re:C++ Frequently Questioned Answers (2009) by spoiler on Sunday January 23, 2022 @09:04AM (#30046198)
> Obviously your experience doesn't involve budgeting or hiring developers.

Ah, that is very true! :) I forgot to make clear in my comment that I wasn't referring to that bit at all.

I only participated in the hiring/interview process, but that's as far as my hiring experience goes.

> The original poster claimed that Rust can save money by letting managers hire junior devs to replace senior C++ developers.

Ah, I didn't interpret it that way. I thought the point they wanted to get across was that it's easier to get the same for less—not in terms of monetary cost, but in terms of less mental effort with regards to context/knowledge about the language itself.

But, the hiring point you're addressing can be inferred from their comment, too.

I think I agree with you on that... It probably is "easier" to hire C++ developers, since there's an older and bigger market for them.

I think Rust developers are in an interesting position right now that they're not as abundant as other developers, since Rust is probably still in "early adoption" stage. So they can use that as leverage in salary negotiations, maybe? But it also comes at a cost of a much smaller job market for them, too.

Re:C++ Frequently Questioned Answers (2009) by fisf on Monday January 24, 2022 @08:17AM (#30057206)
> I think Rust developers are in an interesting position right now that they're not as abundant as other developers, since Rust is probably still in "early adoption" stage. So they can use that as leverage in salary negotiations, maybe? But it also comes at a cost of a much smaller job market for them, too.

No, you are viewing that from a technological perspective - what you assume only holds if "Rust" was a requirement.

If staffing a project is much harder (and maybe more expensive) when using Rust as language, then Rust will not be chosen if C++ is an option.