Live data from Hacker News

Building a Website with C++

blog.sourcerer.io

51–60 of 122 posts

Re: Building a Website with C++

#51
post #37

> 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…

The performance would be notable. However, hardware is cheap these days.

Re: Building a Website with C++

#52
post #40

Really? 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…

Yeah... this example code is bad. Not to mention that CGI is slow, problematic, and chock full of potential security issues. At the very least, spawning a process per request is a DOS attack waiting to happen, even if the code were immaculate.

Re: Building a Website with C++

#53
post #26

Just 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…

Having a better and more expressive type system.

Re: Building a Website with C++

#54

Using 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://…

CGI isn't slow -- starting interpreters is slow. Starting Python or Ruby can easily be 1000x more expensive than starting a process in C, which takes MICROSECONDS, not hundreds of milliseconds.

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++

#55
post #44
post #36

Earlier 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…

The problem is that many developers don't care, they just want to do something that works and move on.

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++

#57
post #50

I 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.

Java can be C like when compiled into native code, OpenJDK isn't the only JVM around.

Re: Building a Website with C++

#58

Just 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…

I can’t speak for everyone but I think of the C++ of today as being dangerously close to the C++ of 1998 because there is so much 1998 C++ code still being linked into most C++ projects. C++17 is incredibly powerful but it’s also hard to wield correctly and most people don’t have those skills yet (and almost none did while writing that 1998-originated library you eventually find yourself need to use). It’s not just the language that matters, it’s how that language gets used and by whom.

Re: Building a Website with C++

#59
post #26

Just 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…

As replied in another thread, IoT.

There aren't many options when you just have a few hundred KB.

Re: Building a Website with C++

#60
post #5

This 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,…

You can check inetd which does exactly that and comes preinstalled and pre activated with Linux installations. Or at lest it was common once upon a time. Don't know if it still is.

https://en.wikipedia.org/wiki/Inetd

Post reply on HN