> In this article, I’ll explain how you can use C++ to develop a website and some concrete reasons why you might consider doing so. I only saw one reason: performance. Did I miss some? Do people have other good use cases that justify paying the dev cost of using C++ for a web server? I'd guess with caching and a decent backend, it would be fairly hard to demonstrate a true need for performance that requires C++, but…
I doubt the performance of a c++ web site would be better than c#/java or some other compiled languages for most non-trivial web sites. Once things like jits come into play, and you see large projects (1million+ loc) the performance advantage of c++ often disappears or it becomes less performant for things like web sites. Most companies do not have the time nor ability to do all those optimizations that theoretically…
Building a Website with C++
51–60 of 122 posts
Re: Building a Website with C++
#52Really? Escaping, people! This code isn't practical or useful; it's dangerous and sloppy. cout \n"; ... cout \n"; FWIW I wrote an article about HTML escaping and shell here: http://www.oilshell.org/blog/2017/09/19.html Followup: http://www.oilshell.org/blog/2017/09/29.html Also if you want to use a native language for web sites (which I don't), Go is a better choice, as the standard library has html/template which pr…
Re: Building a Website with C++
#53Just use rust man :| why do you want to bring all your security vulnerabilities and undefined behaviors to web?
Rust would be equally unsuitable to this task. Web development in C++ or Rust? Why? There may be some advantages to writing a middle tier application server in either of these languages, but using a system language to manage a web front-end is effectively like using a hatchet to shave. Sure, the hatchet is faster at cutting wood than a safety razor, and if one is careful, it could be used to remove stubble, but chanc…
Re: Building a Website with C++
#54Using CGI is silly and slow, for all but the simplest, stateless servers. If one wishes to avoid the overhead of learning a new framework, at least FastCGI should be considered. A relevant (but dated) discussion about web frameworks in C++ can be found in [1]. I am personally a big fan of CROW [2] and have used it many times in the past. [1] https://softwareengineering.stackexchange.com/questions/5362... [2] https://…
See this 7 year old message by Richard Hipp (of sqlite):
https://www.mail-archive.com/fossil-users@lists.fossil-scm.o...
https://news.ycombinator.com/item?id=3036124
This server takes over a quarter million requests per day, 10GB of traffic/day, and it does so using less than 3% of of the CPU on a virtual machine that is a 1/20th slice of a real server.
Re: Building a Website with C++
#55Earlier quoted context omitted.
It's futile battle though to achieve both performance and safety in C++: as an example, safety requires avoiding moves, using reference counting, while achieving performance means avoiding copies and passing occasional references around, among other things. That's why advertising C++ solution as fast does not work well with "but C++ can be safe too!".
Moves can be safe, and copies can be dangerous. C++ is a language that can be used like a sawed-off shotgun propped against a developer's foot, and with a hair trigger. Granted, it does not _have_ to be used this way, but it can be. A good developer can be "safe by default" and can use profile-directed optimization to speed up areas that are performance critical. A great developer can build proofs that such performan…
This is not specific to C++, but it is worse in C and C++ given the nature of these languages.
It also doesn't help that management even cares less about QA than those devs.
Re: Building a Website with C++
#56Re: Building a Website with C++
#57I wrote my blog site in C. Runs as CGI and works just as fast as other tech stacks, say PHP. C has very low startup time compare to say Java. And process fork-exec isn't as heavy weight under Linux as in Windows.
Re: Building a Website with C++
#58Just use rust man :| why do you want to bring all your security vulnerabilities and undefined behaviors to web?
Why do people think the C++ of today is the same as the C++ of 1998? Today we have concepts such as RAII to clean up our objects when they go out of scope. We have references which are essentially safe pointers to an extent (see dangling references). References have always existed, but people insist on using raw pointers still. Finally, for those use cases where heap allocated memory is absolutely necessary , we have…
Re: Building a Website with C++
#59Just use rust man :| why do you want to bring all your security vulnerabilities and undefined behaviors to web?
Rust would be equally unsuitable to this task. Web development in C++ or Rust? Why? There may be some advantages to writing a middle tier application server in either of these languages, but using a system language to manage a web front-end is effectively like using a hatchet to shave. Sure, the hatchet is faster at cutting wood than a safety razor, and if one is careful, it could be used to remove stubble, but chanc…
There aren't many options when you just have a few hundred KB.
Re: Building a Website with C++
#60This brings me back... I was doing this exact sort of stuff at the turn of the century, although admittedly in C - not C++ - and using/linking to the Delphi CGI library. CGI in 2018 seems a bit passé...
Actually, this new hip function-as-a-service thing feels a lot like CGI/inetd… well, at least in terms of not keeping the server process up all the time, only when it's used. To combine "only running when necessary" and "not restarting for every request when there's a lot of requests", I made a thing: https://github.com/myfreeweb/soad — little wrapper listens on a socket, spawns your server with the socket passed in,…