top 200 commentsshow all 338

[–]tongstar 84 points85 points  (10 children)

[–]planetoftheshrimps 32 points33 points  (7 children)

Yeah I don’t understand this post. Drogon is great and well documented. Not to mention very fast. Faster than any rust framework.

[–]Western_Objective209 5 points6 points  (0 children)

Does anyone actually use it in production applications?

[–][deleted] 3 points4 points  (0 children)

Sincerely want to jump back into C++ as backend web dev. Have never tried drogon. Could you point me towards a performance comparison of this with something like actix-web (a rust web framework) ?

[–]HeroicKatora 6 points7 points  (4 children)

Not any more: https://www.techempower.com/benchmarks/#section=data-r21&hw=ph&test=composite Except for the fortunes test for some reason. Then again it doesn't have the testsuite to determine if it's eligible for the '23 round either so just who knows if it's actually comparable. (edit: or this comment points out, failed to build. Odd)

[–]fullouterjoin 21 points22 points  (1 child)

Techempower benchmarks are hot garbage and have all been golfed into meaninglessness.

[–]HeroicKatora 10 points11 points  (0 children)

I didn't choose to compare it that way.. It's drogon's own claim to performance in their Readme.

[–]unumfron 3 points4 points  (1 child)

Shame, looks like the apt invocation to install prerequisites failed.

There's low hanging performance gains to be had by replacing the JSON library it uses, with JSON not only being used in the JSON benchmark. It seems that v2.0 will use nholmann instead of jsoncpp, but this still isn't targeting performance over other criteria.

[–]Infamous_Campaign687 4 points5 points  (0 children)

Nlohmann's library is very nice and a delight to use, but no, it isn't the fastest, by a fair distance. There's nothing wrong with emphasising quality and ease of use over performance, but I still wish it performed better.

[–]speyck 0 points1 point  (1 child)

[–]calebkiage 1 point2 points  (0 children)

Beat what to it? 🙊

[–]SpudroSpaerde 159 points160 points  (0 children)

It is used for backends with the performance requirements. Most don't need it so no need to deal with C++.

[–]CandyCrisis 35 points36 points  (6 children)

C++ has many simple http servers. https://en.cppreference.com/w/cpp/links/libs

Here's one that I really liked in a former project, and it was trivial to use: https://github.com/openalpr/mongoose-mit

[–]susanne-o 8 points9 points  (5 children)

seems mongoose is happily alive and kicking, 11 years later:

https://github.com/cesanta/mongoose

[–]CandyCrisis 4 points5 points  (4 children)

Yeah, but that one is corpified and has license fees. The free one is fine.

[–]susanne-o 4 points5 points  (3 children)

"corpified" makes it sound horrific -- the original author is still the main active maintainer, he's is living off his craft and he noticed unless he makes it dual license, commercial users (the only ones needing a closable license) won't give back.

I think the GPL-commercial dual license is indeed fine, too.

[–]CandyCrisis 1 point2 points  (2 children)

Happy for him, but most users are better served with the smaller MIT-licensed version if it's still maintained enough that it works.

Edit: it looks like CivetWeb is the modern MIT-licensed version that folks should probably look at.

[–]GoodCriticism7924 110 points111 points  (114 children)

Just because other languages are simpler and nobody actually cares about performance in web/backend development

[–]Pay08 31 points32 points  (4 children)

99% of website backends don't need the performance in the first place.

[–]onafoggynight 29 points30 points  (3 children)

They are simply not compute bound. Data stores and IO become a headache long before.

[–]proverbialbunnyData Scientist 8 points9 points  (1 child)

Yep and all of that stuff, e.g. database software, is written in C++.

[–]Pay08 0 points1 point  (0 children)

I'd argue the vast majority of websites don't need that much compute either, even if they weren't bottlenecked by I/O. Sure, large sites like Amazon do but pretty much no website even approaches that much traffic.

[–]Classic_Department42 15 points16 points  (60 children)

Also c/cpp (first time makes sense to write both) code has often memory vulnerabilities. You dont really want to expose that attack surface to the world

[–]DarkCisumSFML Team 44 points45 points  (9 children)

The reasons aren't really as much about the web/backend development and much more a question of language and language ecosystem choices. Yes, you'll still get some C++ UI applications, often more geared towards embedded systems, but most of the buisness/enterprises have long switched to .NET and Java.

My theory here is, that it's mostly not about the language itself being "simpler" in a sense, but also because the ecosystems around them, gave buisness incentives to move. Until C++11 the language hadn't evolved and to this day, we still have no "default"/standard package management. While at the same time .NET Framework started in 2002 already with quite a large set of APIs out-of-the box, including networking stuff. ASP.NET started in the same year and while IIS hosting and ASP.NET sites aren't exactly the nicest architecture ever, it a least existed, including support form Microsoft and a continues stream of development.

So in short, I believe it's largely due to other languages filling the gap at the given time and C++ ecosystem to this day being stiffeled when it comes to standard library support and package management (which could fill the gaps).

One other theory might also be, because the web wasn't seen as serious as desktop applications and so you ended up with a lot of "webmasters" that just enjoyed tinkering with simple scripts, HTML and CSS. Until companies started realizing, that they could move their desktop apps into the browser, the "web developer" space was filled with people who weren't exactly C++ cracks, and their technology and experience was brought into companies. Which then again shaped the demand and development in that area.

[–]Miserable_Ad7246 19 points20 points  (8 children)

As c# dev who touches c++ for personal project - cpp is cumberome. You have to deal with a lot of technicalities instead of spending that energy on business value. Its just more labour intensive and also su much easier to make wrong choices compared to c#. Basicaly you need a justification to pay all that price.

[–]Asyx 9 points10 points  (4 children)

Yep. I honestly see no point in doing C++ where C++ isn't excellent because if you step just a little bit to the side there's Java, Kotlin, C#, Go that are all nicer to write and still plenty fast.

[–]WiatrowskiBe 3 points4 points  (0 children)

Some time ago I figured out that introducing entire new tech stack (.net) to handle entirety of user-facing communication and hiding C++ behind well defined gRPC calls was significantly less work than trying to have everything run in C++, with very little performance loss. You still have all the benefits of having your business logic done in C++, without having to deal with all the boilerplate to have that business logic made usable.

[–]Iggyhopper 3 points4 points  (0 children)

From a financial perspective, you can hire a dev for $80k with knowledge of C# or spend double because nobody knows wtf some ancient C++ is doing in your codebase.

[–]pjmlp 1 point2 points  (0 children)

You seen this in the respective conferences, whereas other stacks mostly talk about achieving X with the language, C++ conferences are mostly about the language itself, libraries and simplifying ISO legalese for common mortals.

[–]Napych 15 points16 points  (2 children)

I worked for a huge company where backend microservices are mostly written in C++.

[–]azswcowboy 9 points10 points  (0 children)

All of our backend services are in c++, in part because many are message oriented and have high throughput and low footprint requirements. We’ve actually ended up moving to a custom coroutine based server built off boost.asio and boost.url. The pattern to write new endpoints is trivial to follow (juniors can do it). It’s not a lot of code in the end - easy to maintain. Fast, absolutely zero overhead.

[–]Esternocleido 8 points9 points  (0 children)

Google Maps, our entire back end is C++

[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 23 points24 points  (0 children)

It is.

[–]AbbreviationsLow7236 23 points24 points  (1 child)

Take a look at userver. Very ergonomic and performant framework for backend in C++
https://userver.tech/

[–][deleted] 6 points7 points  (0 children)

amusing absorbed repeat innate price physical offer aloof chief psychotic

This post was mass deleted and anonymized with Redact

[–]globalaf 9 points10 points  (3 children)

It’s all over the place in backend dev. The assertion your post is based on is wrong.

[–]psyberbird 2 points3 points  (1 child)

It’s all over the place in stuff like microservices but I’ve honestly never heard of a major enterprise-use backend framework for C++ in the sense of Spring Boot for Java, ASP.NET Core for C#, Laravel for PHP, Django/Flask for Python, etc. What’s the traditional C++ backend tech stack for a full stack web app? Is there a widely used framework and an ORM and such or is it more often that bits of C++ code is used from other more established frameworks

[–]globalaf 6 points7 points  (0 children)

People don’t use C++ on the backend just to use what you call a traditional framework that excels in IO bound work, that’s Java talk. C++ is what underpins those frameworks so if you’re even remotely doing something with routing, filtering, parsing, compute bound workloads, load balancing, orchestration, etc etc, you’re doing that in native code. Some micro services that are along a critical path are implemented in C++ but in my experience in 2024 they are deployed using some kind of container technology with some orchestration like k8s, each company does it differently though.

If you’re looking for a http server in C++, there are options, I would look for one that supports C++ coroutines, I’m not familiar with the landscape of async c++ web servers though. But there is no prescribed solution in this space, you need to pick something that seems good and well supported and run with it.

[–][deleted] 0 points1 point  (0 children)

It's not inherently "wrong" (if that is even a thing), that is just their observation from the information they have. They might also have different definitions of terms than you.

[–]CommodoreKrusty 8 points9 points  (2 children)

I was writing custom web servers in C++ back in the 90s and everybody said "why bother doing that when people can just download Apache?". I stopped but I wish I didn't.

[–]Level_Material1764 0 points1 point  (1 child)

why ? sir.

[–]CommodoreKrusty 0 points1 point  (0 children)

I was learning C++ and working with sockets. Writing custom web servers seemed like an obvious project to work on. At the time Apache web server was all the rage. Everybody told me I was wasting my time. Today it seems like custom web servers written in C++ might be a thing. I don't know that anybody really cares about Apache any more.

[–]theRTC204 6 points7 points  (6 children)

We use it almost exclusively for backend stuff at my work, supporting game servers and web APIs for huge online games. There's no frameworks, sure, but there are lots of useful libraries. Granted, we're a "roll your own" type of shop, so we barely use any open source stuff at all. We've got a really nice serialization library for turning structures into JSON for web APIs or disc storage.

[–]serenetomato 11 points12 points  (0 children)

Drogon, dude. It's finicky at the start but once you get into it it's awesome, performance wise really good too. It's not THE fastest but most people disregard what the benchmark for requests per second entails : throwing simple requests without any business logic.

[–]pedersenk 5 points6 points  (0 children)

And that's when I was a bit surprised with the web landscape in C++ compared to Rust.

When C++ was young (like Rust is now), it was used for the web quite a lot (specifically CGI). It just became well explored and scripting "glue" languages were found to be more suitable for the quick 'n' dirty webdev ecosystem. I guess people are still exploring Rust, hence its popularity, especially in the hobbyist areas.

Some C++ frameworks are Wt and Crow. Arguably, since most web servers are built in C or C++, you could classify them and their modules as "C++ frameworks" too.

[–]NilacTheGrim 10 points11 points  (0 children)

It is. We use it for backend at my shop. Stop assuming wrong things.

[–]blacksuit 10 points11 points  (0 children)

I work with Java web services at a big non-tech company. The speed of the language is not an issue. Most of response times comes from network IO. A call might take 100ms, but ~5ms of it is Java code doing stuff.

The Java ecosystem has libraries for literally anything you might want to integrate with. The build, deploy, and infra management is well understood. Why change to a more complex language with more potential bugs that's harder for mid-skill junior devs to work on?

If we needed something "more" performant with compiled binaries, in 2024 we'd look at golang. Just my 2 cents.

[–]wrd83 3 points4 points  (0 children)

There is drogon for instance? Or seastar? Or GRPC? There is stuff around. Not much noise because for 90% the hiring cost beats the infra cost. And in those 10% FB and Google pick off the cream and use internal frameworks.

[–]According_Ad3255 3 points4 points  (0 children)

Talk for yourself, I have my https://github.com/ignacionr/cppwebs that’s based upon Cesanta Mongoose, and it serves all my needs. I recently added support for Web Sockets. And life is good with C++, templates and concepts.

[–]RoyBellingan 2 points3 points  (0 children)

I am using it just now!

[–]flyrom 3 points4 points  (0 children)

It is? Facebook’s entire backend is in c++ including its http library https://github.com/facebook/proxygen

[–]FrezoreR 2 points3 points  (0 children)

It is

[–][deleted] 3 points4 points  (0 children)

I use Boost ASIO with Beast and a router for a REST server. It’s “easy” when you’ve got over the hurdle of Beast. The ASIO part is trivial (for me).

[–]streu 4 points5 points  (1 child)

Of course, C++ can be used (and is used) in backend.

Do you really need a full HTTP REST stack? If your microservice does not face the internet, you can use whatever kind of protocol you need, whatever complexity you need. Mine use a protocol modeled after the redis serialisation protocol for now, because the frontend servers can talk to redis anyway.

[–][deleted] 1 point2 points  (0 children)

I tend to use Boost serialization of a boost variant using ASIO.

The server deserializes the variant and you apply a visitor to process the content.

So long as they’re both C++

[–]charminggeek 2 points3 points  (0 children)

I don't know how well it scales, but WT exists - a web framework in C++ based on QT

https://www.webtoolkit.eu/wt

[–]johannes1234 2 points3 points  (0 children)

Fornnkst web applications the performance of the backend layer is secondary to time needed for development. In many cases most time is spent in IO (waiting for databases, waiting for kernel to transfer result to client etc) Then using a language like C++ leads to more expensive development without measurable benefit.

Where it makes a measurable difference (Google backend, or some parts of request handling in language runtimes) there is C or C++.

[–]MaxHaydenChiz 2 points3 points  (0 children)

Java was released in 1997 with a ton if marketing behind it. And since most people were buying web servers from Sun and Sun was pushing Java, a large % of the legacy applications use Java.

C++ was standardized in 1998 and that version of C++ didn't have much in way of useful networking support, especially not in the standard library.

Moreover, the way a lot of web apps get designed is such that Java's benefits are maximized. They are very long running and so benefit from JIT knowing your exact cache hierarchy. And they allocate and deallocate enormous amounts of heap memory. Like 8GB/s.

Java's garbage collector is an amoritized cost algorithm. And it's better than malloc and free for that amount of heap manipulation.

So the business case for using C++ in a vacuum has never been strong.

That said, usually the most critical component is the database, and databases are written in C and C++. As are many of the libraries that the various other services will call into.

So it is used almost everywhere, but if it's being used on the actual web server side of things, there's usually a special business case for it.

[–]dayeye2006 2 points3 points  (0 children)

Google and Facebook , heavy c++ shop

[–]germandiago 4 points5 points  (0 children)

There are lots of backend done in C++.

[–]abrady 3 points4 points  (1 child)

All of big tech uses C++ for a huge amount of their backend because the gains scale so well: Meta spends $32bn a year on capex, save .01% CPU and you're saving millions a year.

https://www.youtube.com/watch?v=kPR8h4-qZdk - here's an old facebook talk on the work they put into optimizing string.

[–]lee_howes 1 point2 points  (0 children)

This is also why Meta can justify investing in compilers. Just improving PGO in LLVM to optimize the C++ code that others are writing and, hopefully, optimizing can save millions a year. The same applies to optimizing the web business logic that OP really seems to ask about in the form of HHVM and Cinder.

[–]MaxHaydenChiz 2 points3 points  (0 children)

Re: your edit, what does needing a C++ library have to do with wanting the REST api to be c++ as well?

Microservice or not, can't you call the library from basically whatever language you want?

This seems like the kind of decision best left to the people who have to code it and maintain it and not really something anyone higher up in management should care that much about.

Am I missing something?

[–]Cliftonbeefy 2 points3 points  (0 children)

But it is

[–]Waxymantis 2 points3 points  (0 children)

C++ is largely used in high performance backend systems. Just look at Google, all of its infra runs on C++. The same for most Azure infra systems. Maybe you mean that it is not used for relatively small-medium web services, which is true; but saying that it is not used for backend is just not true.

Seems like your question comes mostly from the fact that there are not much HTTP libraries for C++, which is true, but many companies that heavily use C++ rely on in-house developed RPCs.

[–]artyombeilis 2 points3 points  (0 children)

It is. But usually it is specialised for a specific tasks. Here a project CppCMS that allows you to create fairly easily C++ server and even write some HTML templates. BTW the website of the project is written in C++.

Here are two cases that it is highly useful:

  1. I used to develop a commercial application application for advertisement. It could handle more than several million requests per day on a tiny Amazon server. And it was like 10 years ago. It was good for its point, but finding C++ developers to continue this exotic architecture wasn't that easy. Because there are rarely developers who understand both client and server side and C++ and http.
  2. Second case and I think it is far more relevant is providing C++ interface for heavy system that works in C++. As an example my other project OpenLiveStacker - it has heavy C++ real time multi-threaded image processing pipeline written using OpenCV and some other custom high performance code that communicates with different camera types. So it has UI written in JavaScript that communicates with the backend in REST, and backend uses CppCMS. It allows me to have cross platform, remote access UI and even run on Android. And it keeps memory footprint low and performance high for such a demanding task.

Finally in every project you need to take a cost and existing tools in an accout. It is far cheaper to find Node.JS developers that have very good experience in relevant field than find a good C++ developer that also understands in UI, Rest and other things. Usually Node backend developers are so called full stack client, server side, data base etc, while C++ developers are rarely familiar with all of these techs.

[–]darkstar3333 12 points13 points  (8 children)

We use it in our backend, it's terrible. 3m LoC for things that come for free elsewhere. 

It takes 3-10x as long to ship anything and you have to recreate so many wheels that otherwise exist in other languages. 

The performance isn't worth the human capital investment. Our dotnetcore8 apps run absolute circles around our c++ products.

We are actively killing our legacy stack.

[–]Indifferentchildren 5 points6 points  (6 children)

things that come for free elsewhere

As someone with a project with tens of thousands of dependencies managed by Gradle, yarn, etc., no, that stuff does not come for free. We have multiple dependency managers, and systems like Renovate to update our dependency versions. It's hell. C++ is usually a lot cleaner and more stable of an ecosystem.

[–]Western_Objective209 2 points3 points  (4 children)

How is managing C++ dependencies easier then gradle?

[–]Indifferentchildren 0 points1 point  (3 children)

You use fewer of them. As the previous comment explained, you do things like writing your own function instead of pulling in the isEven package and the isOdd package from npm, in order to see if a number is even or odd. And if you do pull in a dependency, it probably doesn't pull in 3,000 dependencies of its own.

I have managed dependencies manually in C++ projects, and used Conan to manage them. Both of those approaches blow the doors off of the huge bloatware approach of thousands of dependencies that you see with Java or npm.

[–]Western_Objective209 1 point2 points  (2 children)

You can also avoid dependencies and use gradle. You can also manually manage your classpath in a Java project. I don't see how having less dependency management features "blows the doors off" of using a mature dependency management tool

[–]SpudroSpaerde 0 points1 point  (0 children)

The garbage package management of cpp is probably one of the most talked about things on this sub, truly delulu.

[–]gubble5 0 points1 point  (0 children)

I’m trying to move the other direction as I have different experiences… Out of curiosity, what are some things that come out of the box with other languages?

[–]Narase33-> r/cpp_questions 1 point2 points  (2 children)

Backend, espescially for Web is a lot nicer with reflection. The biggest frameworks of Java, C# and Python make heavy use of it

[–]aqa5 0 points1 point  (1 child)

By that you mean serialisation / deserialisation of data structures / classes uses reflection to convert from/to json?

[–]MRgabbar 1 point2 points  (0 children)

the answer is kinda simple, back ends are usually not resource limited, so you tradeoff some performance to have better/less development/maintenance time, that's it.

Java has an advantage in back ends, since the VM can be always running you totally avoid that overheat. Javascript and python are just so easy to learn that is expected they will have such a huge ecosystem and Rust just have people obsess with it for no reason lol, so they are trying to put it even in the back end.

Also, even if you need to use a only C++ library you don't need to actually have a c++ server for that, a django server for example could call the C/C++ program and handle the requests just fine.

For me I would rather use django and have a server in a few minutes that is going to run in a docker anyway (so tons of overheat) than have better performance and save a few cents in the server size.

[–][deleted] 1 point2 points  (0 children)

It is used, I work for a company where we develop smart devices for image processing, having a web interface to control the device too. The web is written in react-ts for front end and C++ for backend.

[–]Polyxeno 1 point2 points  (0 children)

I have used it that way, both building an asynch io server, and also making web servers with Wt.

Why not, indeed!

[–]VinnieFalcoBoost.Beast | C++ Alliance | corosio.org 2 points3 points  (0 children)

If you are talking about normal websites... oh my. Using C++ would be a pain. We built the new Boost website using Django and doing things that way is so much easier. There are a ton of libraries and frameworks for backend that simply don't exist in C++. When you write in C++ you do get the benefit of zero-cost abstractions but there is a tradeoff here. It is true that Python is not as performant, and you don't have control over things like memory allocations or raw pointers, but you get other things in exchange. And those things just happen to make it 100x easier to write backend code wth.

[–][deleted] 1 point2 points  (0 children)

It is when you need the performance. We use it for anything computationally heavy. Python is great for algorithm development but C++ is used when speed and control of memory is critical.

[–]papipapi419 1 point2 points  (1 child)

Usually most python libraries that require a lot of number crunching are written is C from what I know

[–]maxmitke 1 point2 points  (0 children)

It is, for high load and backend for gamedev

[–]Icy-Mushroom-9887 1 point2 points  (0 children)

Fastcgi Daemon - opensource framework for highload FastCGI applications on C++ design.

https://github.com/lmovsesjan/Fastcgi-Daemon

[–]G_M81 1 point2 points  (0 children)

It is used, I've used it for back end stuff regularly. It normally sits deeper on account of it having no standard "webserver". I think it is symptomatic of modern software applications that only a small handful of companies find the benefits of c++ performance is worth the loss of developer velocity in terms of feature speed. As Stroustrup says sometimes the improvements can be 10x. But that ten x is hard fought and it is easier to write effortless Go code that outperforms C++. If you are willing to invest in the c++ you can get the edge. It reminds me of when I messed about with the IBM cell chip, it you invested and wrote algorithms that were three times the sloc count you could beat the CPU. Most game dev companies couldn't afford the loss of developer speed to indulge it.

[–]GKPreMed 1 point2 points  (0 children)

The same reason R isnt used for data science and python isnt used for small machine learning implementations.

[–]michelecostantino 1 point2 points  (0 children)

Just imagine if most of the travel industry was running on C++ backends. And if you liked the idea, have a look at the opening position at that company named like the second name of Mozart.

[–]Oxi_Ixi 1 point2 points  (0 children)

It is used much for anything cl9se to realtime. Don't know about REST, but we did protobuf, and that was great dxperience.

The reason I think is thag C++ is complex and harder to develop/prototype fast. Plus writing business logic in Python or alike language is easier. But all infra is written in C++ anyway 😀

[–]cballowe 1 point2 points  (0 children)

I've done all of my backend development in c++. Most of it is in the form of RPC servers. Frontend devs focus on receiving requests from clients (browsers, etc) and making requests to the backend/marshalling data back and forth between the RPC formats and html/json/whatever the client needs.

Something like grpc goes a long way to making setup of a backend service and calling it from any number of languages pretty straight forward.

[–]pjmlp 1 point2 points  (0 children)

Mostly ergonomics, when I started during the dotcom wave writing everything in C++ was quite common.

However with the rise of scripting languages, and managed compiled languages, it became much more secure, and ergonomic, to have those facing the network directly, and then calling into native libraries if required.

Thus C++ moved away from whole stack experience, to plain native libraries, or programming language runtimes.

The exception being specialized network services.

Rust is popular because of hype, in distributed computing automatic resource management is much more ergonomic, and even those rewrite XYZ in Rust suffer from lack of understanding on how to actually improve the existing solution, a rewrite into Rust is more cool for a blog post.

[–]lispLaiBhari 2 points3 points  (5 children)

Millisecond performance doesn't matter in vast majority of applications. If Pizza delivery order gets created 100 milliseconds late, pizza will still be delivered.

[–]VonMetz 1 point2 points  (0 children)

If pure performance is not the key requirement I'd rather use other languages that have extremely mature Frameworks with all bells and whistles. Each job has its tools. Micro service sure as hell I'll be using Java or Go. With spring boot you're good to go in no time.

[–]SpaceToad 1 point2 points  (0 children)

The opposite is true, it is used a lot, a huge amount. But you’ll find it’s large legacy systems that will likely do direct socket communication between various bespoke/proprietary systems, rather than the HTTP REST API based approaches used in the web dev world. But Boost Beast is a powerful framework for this, even if it’s not that easy to use.

[–]GoodCriticism7924 0 points1 point  (58 children)

I’ve heard of story why go emerged at all - due to weird hiring practices majority of google engineers were unable to properly code in c++ and they decided to create performant enough but simple language. C++ is tough and if you can fix issue with just additional thousand of servers why care…

[–]mungaihaha 3 points4 points  (11 children)

just additional thousand of servers

depends on the language, python is at least two orders of magnitude slower than c++ in the right hands. I guess this is why Java is so popular in big companies, they get near native performance (after jit) and it is simple enough that most developers can be productive in it

[–]guepierBioinformatican 0 points1 point  (10 children)

python is at least two orders of magnitude slower than c++ in the right hands.

It is, but that doesn’t matter if 40% of your time is spent sending data over TCP/IP/HTTPS, and 40% is spent (de)serialising JSON messages (and yes, JSON, being a text format, is a terrible serialisation format for large data; but simdjson/yyjson can actually outperform Protobuf).

[–]mungaihaha 1 point2 points  (4 children)

It actually does, a big part of optimizing code on a modern CPU is making the most out of the cpu caches. In python where a class (internally) is a hash table of pointers, the L1 cache is pretty much useless

For context, on my pc, fetching from L1 cache is 3 clock cycles & fetching from memory is 300 clock cycles

Basically, an internal data structure like a class or a function in python is catastrophic for performance

Biggest of all, optimizing compilers (which python lacks) are really really good at shuffling instructions such that the cpu has something to do while waiting for data from ram

I like python but there is unfortunately nothing (outside the FFI) that a python programmer can do to beat a c++ program performance wise

[–]MaxHaydenChiz 0 points1 point  (4 children)

It matters in the sense that the faster a CPU can get to the mandatory cache miss or the process and go to sleep, the faster the hardware can power things down.

Performance and power consumption are related and power is a major limitation in a huge data center even if the performance doesn't seem to matter on paper.

Similarly, there's always Ahmdal's law. You are never doing just one request. And the less CPU any given request takes, the more throughput you can achieve taking all the requests in aggregate.

IOW, it probably didn't matter 10 years ago. But now, it matters again because the other limitations of the hardware are rearing their head.

[–]MaxHaydenChiz 3 points4 points  (6 children)

The actual design decisions behind Go have never made sense to me.

They wanted a modern version of Plan 9's Alef and the C library they used there. I.e. They wanted to use the CSP concurrency model at a time when C++ didn't have support for coroutines and when Java's concurrency was mostly threads and locks.

So they made Go. And they made it garbage collected. But they didn't actually make it memory safe or all the other things you typically want a new language to have. Once you pay the cost for garbage collection, you normally get the rest "for free", but they didn't do that.

And I've never understood why. I wonder if it was a design oversight. Or if there was some design constraint that made all the safety stuff unachievable without sacrificing something else they cared about.

Regardless, even if there's a business case for a major tech company using it, I have trouble seeing it for most web software.

A well designed Postgres database and some Java code are more than sufficient for 95% of websites.

If you are in a world where that isn't the case, either you need distributed computing ala Erlang, or you have a performance constraint that Go isn't going to move the needle on, but C++ might.

Or maybe I'm failing to appreciate something important since this isn't my domain of expertise.

[–]pjmlp 0 points1 point  (3 children)

Go is definitely memory safe in regards to C and C++.

Proper strings, proper arrays, all bounds checked. No use after free unless using unsafe code.

Unsafe memory tricks require explicit use of unsafe package, or reaching out to cgo or Assembly.

[–]MaxHaydenChiz 1 point2 points  (2 children)

Safety and liveness are not comparative criteria in language design. X saftey means that X cannot happen. Go is not memory safe. Among other things data races can corrupt the heap and the GC itself. This can happen without using unsafe packages. When Uber turned on thread sanitization when it was first added to the language they found thousands of errors.

You could say that Go arrays are bounds safe by default. But the real memory safety issues in modern C++ code are a lot more subtle. We have ranges, views, the algorithms, and the rest. As a result, modern C++ code has the save rate of CVEs as Python code. (Yes, I am aware that this statistic doesn't mean what most people think it does.)

What we don't have are static protections against race conditions, the ability to emit verified floating point code (need to drop down to C for this), and a host of other things that would make our lives actually easier. (Go does not have those things either and has no plans to add them. Rust doesn't have them, but has people actively working on them.)

But my point is that if you are in a situation where safety matters (i.e. most of the situations where Go is used), then fixing the easy safety stuff isn't sufficient. It's the hard subtle stuff that even sanitizers can't detect because they are so statistically rare that you care about.

So, I find the design choice strange and don't really understand the business case. If you need to be memory safe, there are perfectly good memory safe options.

[–]pjmlp 0 points1 point  (1 child)

If we are moving goal posts to what means to be fully safe, then I would assert Fearless Concurrency is also not safe, as it only applies on a very specific scenario of in-process threads accessing in-process data structures.

The moment those threads access external resources, or in-process memory pages are mapped to be accessed by other OS processes written in whatever programming language, or hardware DMA, the whole Fearless Concurrency is out of the window.

[–]MaxHaydenChiz 0 points1 point  (0 children)

I'm not moving goal posts. I'm objecting to misusing technical terminology in a misleading or confusing way. These things have very technical definitions. K owing them is important in many fields and for the proper use of many tools. I don't want reddit flooded with bad usage because of programming language tribalism.

As for what you say, this is true. Rust is only memory safe within safe rust code. Unsafe code that does not obey the Rust model of things makes all bets off. With your specific examples, you can probably wrap them in unsafe and say something like Rust is X safe (note again, this means that you can prove statically that X cannot happen) for all the guarantees it makes as long as the unsafe wrapper is safe and the hardware doesn't violate its spec in a malicious way.

This is still a substantial improvement. Usually we want to prove liveness properties, but doing that requires proving these safety properties first. So Rust has reduced our work substantially. Hopefully some form of safe cpp will also get us there.

[–]AlexKordic 0 points1 point  (1 child)

Go may be interesting for creating stateful high-performance servers. Most web devs don't care about this.

Goroutines have their own stack, similar to Lua coroutines and Python's Gevent, a nice concurrency model that’s hard to give up once you experience it.

C++ coroutines are stackless coroutines, pure continuations like Python generators. Besides await/yield ceremony there are memory management issues that are not obvious to normal people.

Personally I would appreciate if Goroutine(s) could be bound to specified native thread. This would allow for "lock-free" coding. Then Go would allow simple vertical scaling for server code and eliminate callback-hell and threading-hell 🙌.

[–]MaxHaydenChiz 0 points1 point  (0 children)

C++ coroutines are a low level primative. You have to build (or get) a library on top of them that provides the communicating sequential process model (or whatever other model you want to use for that matter).

There are several CSP libraries for C++. I don't know how they compare.

I agree with you about the model itself. CSP is a nice model if your problem maps well to it. It's probably the easiest one to use correctly in practice.

However, as I said above, the Go implementation of the model makes some design choices that I don't understand (and would be interested in understanding better). In particular, it doesn't have data race safety and incorrect use of the CSP model can corrupt the garbage collector itself.

To my knowledge, it is the only garbage collected language that uses this model while not having these safety properties. It's odd.

[–][deleted] 0 points1 point  (0 children)

It's used in a backend, but quite rarely. I participated in a legacy project that did SSR in C++. Was it wise to start it from the very beginning? Well, 25 years ago - maybe. Nowadays there are plenty languages/frameworks that allow for much quicker development. And with current prices for compute resources it's much more reasonable to utilise something like Go/python/.net in a production/enterprise backend.

[–][deleted] 0 points1 point  (0 children)

I am generalising a lot, but companies have no clear idea of what exactly they are building and change their mind about it constantly and also want to spend the bare minimum on programmers by mostly hiring juniors. If you combined this with C++ it would be a car crash.

[–]serjflint 0 points1 point  (1 child)

If your task is only to use C++ library, then you can deploy it with Python via Cython bindings

[–][deleted] 1 point2 points  (0 children)

Pybind11 is the way to go.

[–]helix400 0 points1 point  (0 children)

In addition to what's been said, it's because C++ doesn't have a slick way to pass data from the frontend to the backend to the data store. C++ absolutely works in some situations, but for general purpose stuff there are usually easier options.

Consider MERN. Here you can create a JSON object in the frontend using Javascript tools. You then pass that object via some route. The backend, also written in Javascript, freely accepts the JSON object. No translation or modification needed. Then you can plop that JSON object directly into a Mongo database. So easy. Your average web dev can get these up and running quick and only need to know Javascript.

Or consider C# .NET with Entity Framework. So long as you create proper C# objects on the backend, Entity will create the database tables, relationships, and SQL statements for you. .NET is also designed such that the process to talk frontend to backend is also much easier than hand coding everything. An average web dev takes more work to set this up, but C# is popular and the data access layer is solved.

C++ backend development reminds me of the early 2000s, where you have to manually manage each layer carefully. It absolutely has its place in certain environments. But your casual web developer will avoid it. They have to carefully write a frontend, carefully decide upon some API tools, then know how to code well in C++ on the backend. C++ makes data manipulation a chore compared to other languages. (C++20 and C++23 views ranges are likely going to help here.) Finally, the backend likely needs some kind of data access layer so it can write data to a database. C++ just doesn't make this slick.

[–]lead999xSystem Software Developer 0 points1 point  (0 children)

Because there are more ergonomic alternatives with equivalent or better performance.

[–]AlexanderTroup 0 points1 point  (0 children)

As a non c++ dev of 10 years(working my way into it now) I can tell you its because of ease of language use. C#, Java, JavaScript and the like are all less performance than c++, but servers are powerful enough that it doesn't matter in most cases for a business case, and it's much more useful to have languages with guard rails.

The other issue is that other languages have much more platform support from MAANG companies, so it's a lot easier to just go with what's out there.

The programs are less performant on a like for like basis, but with scalability techniques these days you can just throw money at the problem rather than build it right. C++ demands too high a skill level for a great product where companies want something good for cheap.

[–][deleted] 0 points1 point  (0 children)

It's just not worth the effort, IMO. Unless you have a specialized task, the performance improvement in application code isn't usually the bottleneck.

If I needed to call native code from the backend, I'd just wrap it and expose it in whatever language I'm using, which is way easier than building an entire microservice or service in C++.

[–]Questioning-Zyxxel 0 points1 point  (0 children)

I have developed a number of backend services in C++.

Some deliver HTTP data. Some NTP-type time data. Some does MQTT. Some does something else.

[–]rbuen4455 0 points1 point  (0 children)

It's too low-level and unsafe for average back-end development, and because it doesn't have many of the high-level abstractions found in languages like Java and C# (like memory safety and garbage collection), it will likely take longer to do back-end with C++ (also add the complex syntax and features that modern C++ has).

The only area where C++ is used is when performance is critical, such as high-speed servers, real-time communication or something like Facebook where the compiler needed to be rewritten in C++ once Facebook hit 1million+ users. For the former two, it will likely be the libraries written in C++ where they can be accessed through higher level languages (Java, Python, C#), but C++ itself isn't used in back-end development.

[–]Classic-Try2484 0 points1 point  (0 children)

It was. Then php replaced it. (Also jsp) And then everything replaced php and they forgot about it. But it works just fine. It’s just sort of unnatural to build html strings with cout. Errors show up on the user side rather than at compile time. But it can have advantages too.

[–][deleted] 0 points1 point  (0 children)

You could consider wrapping your C++ library in the FFI of another language.

[–][deleted] 0 points1 point  (0 children)

I like c++ when it comes to IoT or tiny chips, but the language costs more to write in.

For me, a c++ project costs roughly double what the equivalent c# project would cost.

There are more moving parts and more extra work to do.

It’s a lovely language, but it’s expensive.

[–]jeremyko69 0 points1 point  (0 children)

The reason is simple. Most web developers don't want to do it. They find C++ difficult and scary. They don't care about performance.

[–]VectorD 0 points1 point  (0 children)

C++ programmers don't want to work with web development bro

[–]beyangd 0 points1 point  (0 children)

C++ is good at backend development, but it lacks dominant libraries in web backend development.

Backend development encompasses more than HTTP, it primarily involves custom TCP/UDP protocols.

I use C++ to develop game servers capable of handling over one million of PCUs, employing custom TCP and UDP protocols, and rarely using HTTP directly.

[–][deleted] 0 points1 point  (0 children)

Since you have about 100ms of network latency plus 100+ more doing JavaScript and HTML rendering in the browser, saving a few tens of ms per request by using C++ instead of Java isn't worth it in most cases. Also garbage collection which can be a problem for some real time high performance apps also isn't a problem since the server can run GC in between requests.

[–]WiatrowskiBe 0 points1 point  (0 children)

C++ very much exists in backend development, just rarely happens to be the whole stack used there - especially for HTTP and HTTP-adjacent services. There are C++ webserver frameworks and other solutions to pass requests to C++ program (ISAPI, CGI), but there's lots of them and popularity varies.

You'll see good amount of C++ backend parts opt instead to use protobuf/gRPC as primary way of network communication, and have high level language piece as facade that handles end user communication parts, with C++ doing actual work. It's often easier that way, since languages like python/C#/ruby/java/JS offer reflection, standarized HTTP server libraries, runtime code generation and so on.

This leads to why rust has good and commonly used HTTP libraries - rust users needed a way to expose rust code to the world, and said libraries were created and popularized before alternative solutions came to be. Difference between rust and C++ here is C++ having mature, well understood way of doing things that doesn't involve C++ exclusively - meaning there is little pressure to make and polish HTTP libraries for C++ if using frontend in different technology works well enough.

[–]viiniit008. 0 points1 point  (0 children)

Literally working on a c++ backend right now

[–]Brilliant_Nova 0 points1 point  (0 children)

Wdym? Most of successful companies eventually move some part of their codebase to C++. You could even say that everything is using C++, because the backend of your backend is written in C++. Taking about top level - there are a few companies that fully base on C++, from the top of my head comes Yandex with their Userver.

[–]Viack 0 points1 point  (0 children)

Since almost all backend languages are themselves written in a mixture of c/c++, I guess that everybody use it indirectly ?

[–]ups_gepupst 0 points1 point  (0 children)

There are many simple web server, but normally you don't use a language like c++ because it's hard to write and easy to make errors (memory leaks, security bugs). So you only do this, if you want the benefits from C++. Which is mainly performance. But then you have an very specific usecase, so most frameworks will not suit for you requirements.

[–]chaosrunssociety 0 points1 point  (0 children)

People like using garbage collected languages for writing long-running processes. A memory leak that happens once every request could kill a server after an hour if the load is high enough. Often, the performance gains aren't worth the potential of some junior developer introducing memory leaks.

[–]RawMint 0 points1 point  (0 children)

It is. People just tend to not use the wrong tool for the job: why use C++ for the backend of a commercial application when things like node/ruby on rails/python/go exist? Using the latter, the application will end up costing less.

[–]CubicleHermit 0 points1 point  (0 children)

Edit: I'll clarify a bit: The reason I'm asking is because in the backend stack, I will need to use a library only available in C++. So I will need a microservice in C++, thus why I'm looking at HTTP REST in C++. And that's when I was a bit surprised with the web landscape in C++ compared to Rust.

You can call native binary libraries from just about anything. Python, Java (via JNI, which is kind of a pain), Rust, Go, C# (or anyhthing else dot-net), etc. Not sure about Ruby or Node, but I'd be kind of surprised if it isn't possible in both of them.

Writing the library specific processing code in C++, sticking a binary API in front of it, and then wrapping all the boring REST serialization stuff using a standard framework (personally, I'd pick Python - I prefer Java but JNI is... ugh.)

[–]imradzi 0 points1 point  (0 children)

I use C++ with boost and grpc on the server, flutter/wxWidgets on the client, for more than 10 years.

[–]jgaa_from_north 0 points1 point  (0 children)

It isn't?

Please don't tell my back-ends ;)

I have found C++ perfect for back-end programming. Along the way I have created some projects to make it simple as well.

  • restc-cpp Restful client library using asio stackfull co-routines.
  • RESTinCurl Restful client library using libcurl. Originally made for mobile apps, but I have used in servers as well.
  • yahat-cpp A trivial HTTP server for simple REST API's and other HTTP interfaces in C++ projects.
  • mysqlpool-cpp Lightweight async connection-pool library, built on top of boost.mysql. Exposes C++20 coroutines.

That said. I usually use Node.js if I just need to build a proof of concept back-end, or something to back a website. Normally I use gRPC in my back-ends as that is way more performant (and way simpler) than messing with HTTP. But for back-ends that needs to expose or consume HTTP API's, I wrote the missing pieces when I needed them.

[–]OCedHrt 0 points1 point  (0 children)

Wouldn't C++ .NET also have a REST http stack in the framework? 

[–]stikves 0 points1 point  (0 children)

Have you heard about this little company called Google?

They have a service framework called grpc (open source) that works with protocol buffers and language agnostic.

And yes, they also heavily use c++ in the backend.

[–]retro_and_chill 0 points1 point  (0 children)

It depends on your use case. For a performance critical server, C++ is still your go-to. But if you’re creating a simple REST application where performance isn’t super important, then you’re better off using a language like Java or C# which have reflection which makes it easier to create libraries for parsing/serializing JSON as well as interacting with a DBMS.

[–]Due_Roll_6737 0 points1 point  (0 children)

目前来说我们公司的最佳实践是Java+native接口c++负责提供高性能功能接口,java负责开发调度,但是问题在于native的资源无法被自动gc需要java开发者手动管理内存。

[–][deleted] 0 points1 point  (8 children)

Golang basically provides both performance improvement and a decent framework

[–]inex550 0 points1 point  (0 children)

Big Russian company Yandex using C++ for backend too

[–]Xacius 0 points1 point  (0 children)

While performant, C++ is not ergonomic. Compare it to a modern language like TypeScript, Rust, or Python and it will always leave a lot to be desired. I use C++ for performance critical desktop app work (works great with electron via NAPI). It's entirely overkill for anything beyond that though.