How Bad of an Idea is C++ Backend - Learning Full Stack Web Design
Posted by willbennnn@reddit | learnprogramming | View on Reddit | 9 comments
Let me preface by saying before I started this project I had zero knowledge of web dev. I am a data engineering undergrad who has taken an entry level programming class (one in python, one in C++) and a DSA class (C++).
My rowing organization was in need of a management tool better than the super messy google sheet we’ve been using (similar to crew lab if you’ve heard of that), so I decided to take on the project for myself as a learning experience.
My front end stack is TS/Vite/React, but (for the sake of learning, and because it’s the language I am most familiar with) I chose to use C++ with the Drogon framework for the backend. Now that I am deep in the weeds with the backend and feel like I actually understand a good bit, I am starting to get really annoyed by how tedious it is to code new handlers, especially due to their repetitive nature and my refusal to copy and paste from ChatGPT so I actually “learn”.
I know that I probably should’ve used one of the suggested backend frameworks for a project of the scale I’m working on (node, rails, django, etc.), but I feel like I’m too deep to turn back now. My backend build contains like 15 different headers/cpp files and close to 2000 lines of code at this point, I’m not really sure what I should do.
Very open to suggestions and opinions
Alikont@reddit
I was never fan of C++ back-ends. If you want to do a high performance thing, make it a C++ library, and call it from a safe, GC-friendly language, like C#/Node/Python that will handle HTTP part easily and more importantly - safely.
SolemnEmberGames@reddit
Backend can be very complicated and C++ has a lot of footguns.
I know C++ but hate using it, it's ultra performance but I avoid it when I can. Also you don't really need it for a backend since most the time you're blocked by IO bound tasks not CPU.
If you wanna do backed, Python is easiest imo, but C# is a good middle ground that's not slow but also not an utter cesspool of a language (I'm being polite)
Objective-Elk2501@reddit
I actually don't understand the argument that python, would be the easiest. I'm going to most specifically be referring to django, as that seems to be the most popular framework. Coming from the position of someone who has written backend services in C# and even typescript, python always seemed horrendous both syntactically and in terms of it's ecosystem. I feel like djangos attempt at abstractions are just unpleasant and if you learn it as a framework you're essentially learning just that, not how backends, APIs, etc, actually work in most cases. Writing a minimal rest API in asp.net maps pretty nicely onto express or laravel comceptually, but I couldnt say the same about dango.
Suspicious-Basis-885@reddit
2000 lines really is not too deep to turn back if you decide the tooling is fighting you more than teaching you. But finishing it in C++ is kind of a flex at this point.
I’d probably keep going until you hit MVP, then rebuild one service in something like Go or Django later just to compare the experience. You’ll learn a ton either way.
BranchLatter4294@reddit
It will be difficult, but doable.
Beregolas@reddit
I don't like C++ for backend. It 100% can work, especially if you have prior experience in C++, but the ecosystem is just worse than for other languages, and it's way easier to fuck up.
also, most backend tasks really don't need performance in the language, as even with a single threaded python backend, I can server thousands of users. Most of the time is spent either in transit, or in round trips to the database anyways. The most complex parts of most backends are just slighly rearranging the data a little.
If you want low level for the backend, I would suggest rust / axum. It has some advantages over C++, for example that many classes of runtime errors get pushed to compile time, meaning no downtime if you run into null pointer shenanigangs (which are not a thing in rust).
Otherwise, any of C#, Kotlin and Python would be my suggestions/picks. They all have good frameworks for backend development and an active developer community. I would avoid JS backends, ~~mostly due to them just being shit.~~ The most often stated advantages for JS in the backend is, that you can share code between front and backend. This works sometimes, but I have worked on multiple JS fullstack apps as a backend dev now, and the amount of code you actually re-use is miniscule. And all other languages are just way nicer to use IMHO.
SchemeWestern3388@reddit
If your goal is to learn C++ better, and learn the dirty details of backend, go nuts. Be aware, you might not ever get there.
Django could probably replicate the functionality your 2000 line C++ codebase has in a hundred lines. And it would do it right and securely. Having things like authentication and time stuff smoothly handled is priceless for mental sanity.
Unless I’m writing a driver, or something that clearly needs C++ power (gods forbid), I always start in Python, leverage as many libraries as possible, and maybe wind up rewriting a function or three in C.
Massive-Pirate744@reddit
Honestly, it is not a bad idea at all if your goal is to really understand how systems work, but it is definitely playing the game on hard mode. Most people just use Python, Node, or Go for backend stuff because you can ship features so much faster and the ecosystem is massive. If you try to build a full backend in C, you will spend half your time fighting memory management and the other half debugging things that wouldn't even be an issue in a higher-level language. It is a great learning experience for sure, but if you actually want to get a job in web dev soon, you might be better off sticking to a language that is actually used in production for backends today.
willbennnn@reddit (OP)
What do you suggest I use if I switch? Something built on python probably makes the most sense since I actually know the language, but I’m just doing this for fun so I wouldn’t mind teaching myself another language if it’ll benefit me in the long-run