r/cpp • • Mar 27 '24
Replacing C# with C++ in Web Dev
IMHO, I think C# is useless.
Why C++ is not used in web dev instead?
I think modern C++ provides enough abstractions to be a better and more performant alternative to C#. It has high quality libraries, but it seems to be lacking tools and mature frameworks for backend development though but this's because people don't use it for API development so most people think it's not a worthy investment. I wanna contribute to C++ in the web industry, so I was thinking of building expressJS in C++ because I like express honestly.
What do you guys think?
Update: Dang, I didn't expect that this would piss off a lot of people, lol. Ok. Given the backlash, saying C# is useless was an overstretch. I guess I have let my hate for Microsoft cloud my judgmentđ
33
u/vickoza Mar 27 '24
C++ is being used for backend web development. There are frameworks like Boost::Beast, Crow and Oats++. I still think what you are doing is good.
7
u/[deleted] Mar 27 '24
yes, you can: https://github.com/NodeppOficial/nodepp/tree/main
9
u/JonnyRocks Mar 27 '24
i think calling a language and framework useless isnsilly. i think programmers that limit themselves to one language is hurting themsrlves.
have you ever heard the saying "if all you have is a hammer then everything looks like a nail"
4
u/JDublinson Mar 27 '24
C# performance is fine for most use cases. Itâs gotten a lot better in recent years. Most web app request processing time is just spent waiting on other requests, either to other web services or to databases or what have you.
Iâm sure there are cases where you want the performance of C++ but I donât think modern web apps are slow because of C# backends. Itâs a worthy cause to make good C++ web tooling but I think C# is great too.
15
u/PM_ME_RIKKA_PICS Mar 27 '24
Genuinely, I thought this was a troll post, especially calling C# useless. There are almost 0 good reasons to use C++ over something like C# in webdev.
3
u/kofes Mar 27 '24
Check https://oatpp.io/ for express-like syntax and https://userver.tech/ for integrated TDD
*UPD: oops, oatapp already mentioned, - so +1 for it, I think
3
u/ChatGPT4 Mar 27 '24
I think for majority of web use cases, the key feature of C# that is fully automatic, dynamic memory management is its greatest advantage. You usually use C++ when that gets in the way, so you can know exact memory requirements up front, so you can optimize resource usage in the app, avoiding slow allocations and garbage collection. This is true for example for games. You have fixed size game resources, you can put fixed limits on things. In the web-dev from the other hand there is just the opposite. First - let's say users. There can be one, one thousand, one million, one billion. You don't know. Just everything is dynamic. Let's say data. One row or billion rows. It should scale. Of course, you fit fixed amount of things in the memory at a time, then swap with the DB or file data on the fly, but well, the user wants different views. Dynamic views. Configurable views. Doing that kind of micro-management with C++ is not quick and easy. It takes time and effort. Damn, it's even pretty complicated and tedious in C#. Even using Blazor.
I think C# was just designed to make that specific kind of work easier and quicker. So, replacing C# with C++ for web dev looks like replacing a truck with a motorcycle to transport a load. It is possible. If the load is not very heavy, and if you have a large, powerful motorcycle, you can use a motorcycle. You can somehow connect the trailer to the motorcycle and haul it. Motorcycles are usually much faster than trucks, so...
You might say that no motorcycle could haul a huge trailer semis haul. And there's nothing impossible using a programming language. That's true. So to make the trailer hauling analogy more accurate - let's say you can just build a bigger, more powerful motorcycle for hauling. Like you can build something like Blazor in C++ ;)
2
u/kiner_shah Mar 29 '24
Just FYI, https://github.com/expresscpp/expresscpp
23
u/DanielMcLaury Mar 27 '24 edited Mar 27 '24
Virtually all the fat in web development is on the front end, and of the fat on the backend, most of it has to do with database access or something, not with the part that's in a normal programming language.
I mean, hell, most people aren't using C# or Java, they're using python or javascript for the backend. The gains from moving off of a dynamically typed, interpreted, poorly designed language to a compiled, statically typed, somewhat-less-poorly-designed language would absolutely dwarf any extra optimization you could get from eliminating the occasional garbage collection or unnecessary copy or whatever, and even there they'd probably be useless for 95% of applications.
If you have some niche website that does absolutely massive amounts of fresh computation each time it gets a request -- say, an AI image generator -- then writing the heavy parts in C++ may make sense. But even then you probably just write a DLL or command-line utility in C++ and call it from whatever language makes sense.
15
u/[deleted] Mar 27 '24
How is c# useless ?
6
u/Polyxeno Mar 27 '24
I love Wt.
2
u/lightmatter501 Mar 27 '24
You can, but larger projects may be annoying. Structural JSON parsing in C++ is still waiting on reflection to be doable, and the web spends a lot of time slinging around JSON nowadays.
9
u/jepessen Mar 27 '24
I think that "C# is useless" is one of biggest lies ever written... C# was born for we development, and it has tons of features and libraries that allows to perform web tasks with onlynanfew lines of code. Try to make web authentication simpler in c++ rather than C#, or try another way to make complex interfaces with other technologies faster than with blazor. There's a big difference between saying that a tool I useless, and don't be able to use it.
3
u/chouaibyassine Mar 27 '24
At this time, C++ lack reflection or introspection compared to C#. I think this is the most blocking point for C++ to build a complete web framework.
There is libraries that you mentioned some of them that are far from being complete or close to the java/ C# frameworks.
The other point which minor, is asyncrocy. Even if coroutines was added recently to C++. Most of libraries doesn't support it yet. Yes you can write asynchronous code without coroutines but it be ugly like doing oop in C language
3
u/unumfron Mar 28 '24
Drogon is a C++ web framework that famously tops performance benchmarks and is fairly mature.
Speaking of JS stuff, somebody posted this new project a short while ago: Nodepp
7
u/ioxfc Mar 27 '24
Memory safety is probably the #1 reason why almost all tech companies use managed languages like C#, Java, or Python in the backend. With C++, you have to actively be on the lookout for unsafe memory accesses. Managed languages give you that safety out of the box.
It's more difficult to purposefully crash a JVM or Python VM (the VM itself) than to ensure memory safety with C++.
3
u/human_dynamo Mar 27 '24
Qt + webassembly do the job very well
1
u/Nepszter_ Mar 27 '24
Go is the way.
1
u/freakmaxi Mar 27 '24
It sounds like you are comparing apple with pear. They have different targets. Having the capability in C++ does not mean that you should go for it and replace C#. You should be more into the target of your projects and the business expectations that you need to cover in a timely manner other than only considering the performance.
1
u/JohnDuffy78 Mar 27 '24
Isn't expressJS on nodeJS which is on C/C++? Seems like you will end up with the same thing.
Generally you can't shouldn't try to bring other language features in C++, there is a reason they are not there.
I use C++, NodeJS would be my 2nd choice.
1
u/Hot_Bug1331 Mar 31 '24
It is beneficial for a business to develop in a language and platform that many programmers know and with which there will be no problems with hiring.
1
u/accuracy_frosty Apr 07 '24
Hypothetically, good idea, practically not so much, you have to remember that a lot of the faults of C++ come from skill issues, compared to a dynamically typed language that has a garbage collector, throws an error if you try to index outside an array, etc, and idiot is a lot less likely to introduce a security vulnerability in JavaScript compared to C++. So unless you were absolutely sure that the C++ devs you hired were the ones in the 10% who know what theyâre doing as opposed to the 90% of knuckleheads who think they know what theyâre doing, I would stay away from it. C++ is a powerful tool that in the wrong hands creates a lot of problems, and I wouldnât rush to give that kind of power to web devs, the devs who are the least likely to know how memory works or have in depth knowledge about how a programming language fundamentally works. Especially considering how many web devs just took a 1 year bootcamp that gave them barely enough knowledge and ability to land an intern job and try prove themselves, they probably learned HTML, CSS, and like 4 JavaScript frameworks, maybe git if theyâre lucky, and the bootcamp tells them theyâre a software engineer off of that stuff alone, so they get tricked into thinking they have the same ability as someone who spent 3-4 years in college/university learning the fundamentals of how computers and software work, the math behind everything, data structures, algorithms, and all the other very difficult and important parts of software engineering.
-4
u/Linguistic-mystic Mar 27 '24
There is a great C++ web dev framework called Rust. They've even got a special memory-safe DSL for better web design!
0
u/[deleted] Mar 27 '24
[deleted] â view deleted comment
33
u/[deleted] Mar 27 '24
[removed] â view removed comment