News for hackers. Stuff that matters.
Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Friday January 14, 2022 @08:57AM (#29934436)
C++ is one of my favourite languages, however there is a big difference bettwen being able to write modern C++ in side projects, and what most companies consider C++.

Enjoy a sample of AOSP source code, https://android.googlesource.com/platform/art/+/refs/heads/m...

Re:We used C++20 to eliminate a class of runtime bugs by maccard on Friday January 14, 2022 @09:28AM (#29934795)
Just because some companies write ancient C++ code doesn't mean all companies do. I write mostly C++17 these days for a company, and my previous job wasn't exactly afraid of modern C++ but they could have embraced more of it. The post I shared is from Microsoft about writing modern C++ .
Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Friday January 14, 2022 @10:13AM (#29935408)
I know, and I can provide similar quality reference from Microsoft own samples if you wish.
Re:We used C++20 to eliminate a class of runtime bugs by maccard on Friday January 14, 2022 @10:47AM (#29935865)
I don't get the point you're trying to make, sorry. "Big companies sometimes write crappy code" is of course going to be true.
Re:We used C++20 to eliminate a class of runtime bugs by bborud on Friday January 14, 2022 @02:40PM (#29939290)
It would be interesting to see statistics on use of newer C++ in companies known to have relatively stringent coding standards and code review regimens. I suspect that it (still) isn't so much about crappy code as much of the value of C++ being sunk into legacy code that determine the constraints put on *new* codebases.
Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Friday January 14, 2022 @02:35PM (#29939232)
Most companies still write C++ crappy code, regardless of the advocacy many of us in the community try to make.

In fact, if we focus on traditional enterprise shops they are stuck in what I call the C+ mindset.

Those of us that bother to live in HN, Reddit, attend CppCon, C++Now, C++ on Sea, ACCU in whatever form, are 3lit3. A tiny minority that actually cares about quality.

That is the point.

Re:We used C++20 to eliminate a class of runtime bugs by flumpcakes on Friday January 14, 2022 @04:19PM (#29940585)
It doesn't sound like much of a point. The same thing is going to be true for all programming languages widely used in industry. It's not a C++ issue.

In fact, see Python 2 vs 3 for probably the most impactful case of people being slow to take up new language versions/features.

There's going to be shops writing C89. Some reasons might be well founded, some reasons might be less well founded.

Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Saturday January 15, 2022 @02:35AM (#29944495)
Correct, so now imagine Python 3 as the adoption of Core Guidelines, which is basically what modern safe C++ is all about.

Lasted surveys, which are anyway only answered by people that are active enough to care about stuff outside job, places use of tooling to validate modern practices at about 20%.

Now do some statistical extrapolation and it is relatively easy to find out how much "modern C++" is actually used in practice.

Bjarne hasn't dedicated two CppCon to the subject to improve adoption of better C++ practices just by accident.

Re:We used C++20 to eliminate a class of runtime bugs by flumpcakes on Saturday January 15, 2022 @10:05AM (#29946843)
I agree. I think perhaps the one thing that does more uniquely affect C++ is the compatibility with C (at least not newer versions of C) and the strict backwards compatibility with C++ before it. Which is a little strange to say because compilers _do_ deprecate features, so it's not strict-strict, just strict enough for the standards committee to use it as an excuse.
Re:We used C++20 to eliminate a class of runtime bugs by maccard on Friday January 14, 2022 @05:58PM (#29941673)
The people who write crappy modern C++ will write crappy C++03, crappy java and crappy golang.
Re:We used C++20 to eliminate a class of runtime bugs by still_grokking on Saturday January 15, 2022 @06:40AM (#29945642)
Well, 50% of programmers are at most mediocre—or worse. And only maybe 1% of programmers is able to write significantly better code than all others.

So in result, just by the means of statistics, all code is necessarily crap. (Besides the extremely seldom pearls written by some independent geniuses).

Frankly this is unavoidable on an industrial scale of production, I guess. At least as long as we can't clone "10 x programmers".

Re:We used C++20 to eliminate a class of runtime bugs by jjnoakes on Friday January 14, 2022 @06:02PM (#29941710)
Perhaps, but crappy Java and crappy Go won't have memory corruption concerns, which is a huge plus in and of itself.
Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Saturday January 15, 2022 @02:11AM (#29944367)
Indeed, unfortunately they get to play with sharp knives.
Re:We used C++20 to eliminate a class of runtime bugs by gruez on Friday January 14, 2022 @09:52AM (#29935138)
>Enjoy a sample of AOSP source code, https://android.googlesource.com/platform/art/+/refs/heads/m...

What am I looking for? Is it just the use of smart pointers?

Re:We used C++20 to eliminate a class of runtime bugs by bentcorner on Friday January 14, 2022 @03:09PM (#29939666)
+1 it looks ok, although the stylistically I would personally prefer to split this file up into smaller parts (although maybe it's all related). I'm also not a big fan of macros but again without knowing more it's not too unreasonable.

Personally I wouldn't like to slog through this on a moment's notice but it seems named well and there are a lot of comments, and appears to have been through clang-tidy.

Re:We used C++20 to eliminate a class of runtime bugs by throwawaybbqed on Friday January 14, 2022 @09:20AM (#29934689)
Wow ... I want to pull my eyes out now. Is this really some uber critical path in the code or did the author(s) have too much time on their hands/optimizing some other metric (e.g. promotion, proving how smart they are, attempting to get job security). I am also astounded by two things related to documentation .. it is nearly non-existent, and where it exists, seems to provide almost no context to someone other than the original authors.

You posted this for a reason .. would be good to get your thoughts.

edit: adding one more point. I went to a fairly high-ranked university(top-20). We would get graded based on how clear our code was, comments (both for functions and inline comments). This code would get a zero on those metrics.

Re:We used C++20 to eliminate a class of runtime bugs by emteycz on Friday January 14, 2022 @09:26AM (#29934763)
Hmm... I can't see how the code is unreasonable, given the complexity of the task at hand. Could you tell me what could be improved about this code (code itself, not docs etc)?
Re:We used C++20 to eliminate a class of runtime bugs by jcelerier on Friday January 14, 2022 @03:47PM (#29940210)
just opened a file and...ugh

https://android.googlesource.com/platform/art/+/refs/heads/m...

like, just this, basically C:

    if (strncmp(argv[arg_idx], "-XXlib:", strlen("-XXlib:")) == 0) {
       ...
is just so complicated and error-prone over

    if(std::string_view{argv[arg_idx]}.starts_with("-XXlib:"))  
       ...
(which I guess is the intent)
Re:We used C++20 to eliminate a class of runtime bugs by jmgao on Friday January 14, 2022 @04:13PM (#29940524)
That code is older than C++11, let alone C++17. Also, your proposal isn't as efficient, since it calls strlen on construction of string_view (not that cost of parsing command line arguments is going to be measurable).
Re:We used C++20 to eliminate a class of runtime bugs by jjnoakes on Friday January 14, 2022 @06:03PM (#29941725)
> your proposal isn't as efficient, since it calls strlen on construction of string_view

The code it replaces also had a strlen in it.

Re:We used C++20 to eliminate a class of runtime bugs by jmgao on Friday January 14, 2022 @06:07PM (#29941764)
A strlen of a compile-time constant, which will certainly get turned into a constant by the compiler. It does not get the length of the input string.
Re:We used C++20 to eliminate a class of runtime bugs by jjnoakes on Saturday January 15, 2022 @12:02PM (#29947999)
Why wouldn't the string_view constructor be inlined and get the same treatment?
Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Saturday January 15, 2022 @02:37AM (#29944502)
Certainly isn't a fact unless proven by examining the generated machine code.
Re:We used C++20 to eliminate a class of runtime bugs by jmgao on Saturday January 15, 2022 @04:29AM (#29945091)
This is a worthless statement. Do you examine all of your generated machine code to ensure that it generates correct code? Any compiler that you cannot trust to inline 3 for strlen("foo") is not one you should trust to compile anything, let alone modern C++.
Re:We used C++20 to eliminate a class of runtime bugs by maccard on Saturday January 15, 2022 @11:06AM (#29947405)
> Do you examine all of your generated machine code to ensure that it generates correct code?

(not OP). I examine the output if someone tells me it's slower, or if I care about performance. I did a very rough benchmark which says in this case they're equivalent [0], however that's not necessarily representative of the places it's called in. There's definitely a compile time overhead though [1]. On my current project there's ~20k files. On an 8 core machine (as an example), adding 150ms per file would add 7 minutes onto a clean build (before optimising the builds).

[0] https://quick-bench.com/q/LBarCDIigwpmXcwZSx-RgV2x4_4 [1] https://build-bench.com/b/OH8qf9AgEB_l-BhANV5qP_uSCys

Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Saturday January 15, 2022 @03:48PM (#29950093)
ISO C++ abstract machine and what a random C++ compiler generates out of it, don't require at any moment the realisation of your assertion.

So you either validate it actually takes place or believe in fairy tales.

Re:We used C++20 to eliminate a class of runtime bugs by ncmncm on Friday January 14, 2022 @04:14PM (#29940538)
The code is ancient, and Google (like most) sees no value in modernizing old code, particularly for non-revenue-generating product. Furthermore, Google long ago locked themselves into an idiotically anti-RAII coding standard.

So, the example is of bad old code, at a place that enforces bad coding practice. The intent appears to be to suggest this is typical practice, which is not supported.

Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Saturday January 15, 2022 @02:41AM (#29944519)
Google seats at ISO C++, is a major contributor to clang and LLVM, and belongs to the group of companies with largest C++ code in production.

If this what a company with deep roots in C++ world is doing, what are the large majority of "dark matter" software factories doing, specially the sweetshop ones.

Re:We used C++20 to eliminate a class of runtime bugs by ncmncm on Saturday January 15, 2022 @06:48AM (#29945682)
A minuscule fraction of the people coding what they call C++ at Google come to the committee meetings. Google's ancient, idiotic prohibition on RAII is not a thing the current attendees, or other employees, have a say about. Many, attending or no, would rather be coding sensibly. And, in any case, the ancient code you present is not how code is being written even at Google today. So, your point is hopelessly muddled.

There are shops where people still write new C++ like it's 2011, or 2003, or 1998, or 1992, or C. There are plenty of shops where people code the best way their current production compiler allows. There are plenty where different people do some of each of those. Vanishingly few shops make an effort to rewrite ancient code according to current best practice.

I guess a sweetshop company is one with Oompa-loompas.

Re:We used C++20 to eliminate a class of runtime bugs by pjmlp on Saturday January 15, 2022 @04:00PM (#29950205)
One day I would appreciate to know where that perfect C++ world of yours exist in real world.

I guess I need to catch up with some Twilight Zone episodes.

Re:We used C++20 to eliminate a class of runtime bugs by ncmncm on Monday January 17, 2022 @12:03AM (#29963495)
Try "Willy Wonka and the Chocolate Factory"?
Re:We used C++20 to eliminate a class of runtime bugs by still_grokking on Saturday January 15, 2022 @07:06AM (#29945761)
> just opened a file and...ugh

Looks just like regular PHP. So what's the point? Or did I miss something?

/s