r/cpp • • Jan 09 '22

James Web Space Telescope runs on C++ code.

https://youtu.be/hET2MS1tIjA?t=1938
726 Upvotes

185 comments sorted by

View all comments

Show parent comment

63

u/sigmabody Jan 09 '22

Came here to see this, not disappointed, kinda impressed that it's the top comment (at time of this response).

Virtually all code for systems which "have to work" in the world now is written in C or C++. Industrial, automotive, finance, supply chain, space, etc.; it's a long, and nearly ubiquitous list, and it is that way for a reason. There are numerous other popular/newer languages and paradigms which are "the cool new thing", and then there are the languages which you write code in for applications which are not just for-fun or limited scope projects.

That's not to say it's impossible to write commercial applications in other languages, especially on top of solid foundations written in the "solid" languages (eg: many web services are written in managed languages running inside frameworks written in C/C++, and running on OS's written in C/C++). But for the "real" stuff, the code which needs to be robust and work predictably and reliably, C/C++ is still the gold standard.

17

u/tarranoth Jan 09 '22

Well, you wouldn't write embedded stuff in anything other than C/C++ right, which seems to be mainly the industries you are listing. I don't think this has to do with "has to work" but just that you are kindof limited in what you can even use.

3

u/hotoatmeal Jan 09 '22

Rust is gaining a lot of traction for embedded

21

u/tarranoth Jan 09 '22

It's gaining some traction, but it is a little bit limited with the llvm backend. I know there is the gcc experimental stuff, but I'm not entirely convinced that that would make people write rust instead of C. I think for stuff like raspberry (or basically any thing that at least still runs an os), it might see usage, but I don't think it makes much sense for bare metal.

7

u/rswsaw22 Jan 10 '22

I also think for any memory mapped hardware you need to use the unsafe keyword to access it. Which ruins the big selling point of Rust, its safety. And as someone who works in the embedded space, Rust is a hard selling point when it doesn't have vendor supported tools. It's a pain to self wrap a dev environment for a uC and it is just easier to reach for C++ when I want better type safety as I can just use the vendor provided IDE and debugger.

3

u/pjmlp Jan 10 '22

All systems programming languages need unsafe at some level, the issue with languages that are copy-paste compatible with C is that the whole code is unsafe.

The only way to prevent it is with help of castration standards like MISRA and AUTOSAR.

2

u/rswsaw22 Jan 10 '22

Right. I agree with all of that. But for bare metal programming that's a lot of code that ends up using unsafe in Rust when I played with it. Still like the language a lot, but for right now professionally it's just easier to reach for C or C++ and apply the above standards you mentioned.

10

u/PL_Design Jan 10 '22 edited Jan 10 '22

No, it's not. The crabs just keep saying it is and people who don't know any better repeat it. Rust has as much to do with embedded as Common Lisp does.

4

u/pjmlp Jan 10 '22

http://www.ulisp.com/

Naturally one can assert that Arduino, Adafruit M0/M4, Micro:bit, ESP8266/32, RISC-V, and Teensy 4.x boards. isn't embedded or that uLisp isn't Common Lisp.

2

u/PL_Design Jan 11 '22

You can use Rust and CL in embedded environments, but it's a niche thing. That's why I compared Rust to CL.

1

u/pjmlp Jan 11 '22

The coffeeshop around the corner is also a niche thing, yet they managed to survive for decades.

Not everything has to grow to FAANG levels to be useful.

Several niche compiler vendors have survived for years selling compilers for embedded space, so people buy the hardware, and then they actually pay for niche compilers instead of free beer C and C++ compilers, crazy.

2

u/PL_Design Jan 12 '22

blah blah blah

You missed the part where I was objecting to Rust "gaining a lot of traction". I would hardly call being as popular as embedded CL "a lot of traction".

2

u/pjmlp Jan 12 '22

Yeah, word games is a nice thing, meanwhile Expressif, ARM, Microsoft (for Azure IoT) are adopting Rust into their SDKs, and have hired core developers.

Maybe you heard of those companies, they seem to be releveant for embedded development.

1

u/PL_Design Jan 12 '22

I'm not playing word games. I'm stopping you from taking what I said out of context.

I'll wait with bated breath to see if any of those projects pan out.

→ More replies

1

u/johannes1971 Jan 10 '22

Is that the same embedded that's always posting it can't use any compilers newer than gcc 2.93?

1

u/serviscope_minor Jan 10 '22

Well, you wouldn't write embedded stuff in anything other than C/C++ right,

You might write it in Ada, too.

1

u/pjmlp Jan 10 '22

There are some BASIC, Oberon, Pascal and Ada compilers available, but probably NASA isn't their customer target.

1

u/nekokattt Jan 09 '22 edited Jan 09 '22

I would disagree with finance. I have yet to see any C++ being actively maintained in any of the places I have ever worked within fintech in backend systems. Perhaps in some performance-critical cases such as stock exchange backends, or in "off-the-shelf" tools like PostgreSQL, but the majority of code maintained by the financial sector itself is JVM/.NET/Python, or is still a legacy system running something like Fortran/COBOL.

Even LMAX uses Java for their performance-critical components. https://lmax-exchange.github.io/disruptor/ being one of their projects targeting high-throughput messaging. Majority of the banks in the UK use Java and C# stacks, as do most insurance companies that are not startups.

(Of course CPython and OpenJDK are C/++ backed, but the actual logic produced for the problem being solved only runs on top of those binaries).

As for the other examples, I cannot verify that, as I have no experience in those sectors.

Also, not out to bash C++ or anything, I like the language, and not saying it does not have a place either, nor that it isn't used in finance. I am just pointing out that other languages take the majority in terms of usage. Latency-critical components are only a small subset of components that financial applications consist of.

19

u/RockingAMullet Jan 09 '22

There is even a C++ working group (SG14) geared towards trading (low latency in particular). I have yet to see a "proper" trading platform not written in C++.

12

u/nekokattt Jan 09 '22

Trading, for sure, but that is a tiny subset of everything financial software includes, which is my point.

7

u/corysama Jan 09 '22

You have LMAX backwards. Martin Thompson has made a career out of selling Java programmed in the style of embedded C to people who should be programming embedded-style C but their managers insist they use Java.

2

u/nekokattt Jan 09 '22

I never said it was used instead of C on that basis, simply that it is used heavily.

You hit the nail on the head regarding managers asking for Java though.

8

u/sigmabody Jan 09 '22

Note: I'm not trying to say or imply that orgs don't write BL code in higher level languages. For example, a lot of the app logic for machine learning tends to be in Python.

I am saying that for the components of those systems which need to be fast, robust, deterministic, etc., C/C++ is the overwhelming choice. You can write ML config code in Python; you write the engine in C++. You can write a trading UI in Java; you write the trading execution engine in C++. You can write services in Java; you write the JVM in C++. You write you data manipulation front-end in whatever; you write the database in C++. You write orchestration apps in whatever; you write drivers, OS's, firmware, in C++. You write web apps in Javascript; the browser is written in C++. Etc.

The majority of first-party code in orgs may be in other languages; that's certainly possible, and to some extent may speak to the high quality of available components and solid frameworks in C++ to build on top of. But at the end of the day, if something is truly function-critical (ie: needs to be reliable, scalable, performant, deterministic, etc.), it's more likely than not written in C or C++.

That's all I'm asserting (although I also admit that I could be wrong).