Live data from Hacker News

Building a Website with C++

blog.sourcerer.io

31–40 of 122 posts

Re: Building a Website with C++

#31
post #25

Bevor I'd use C++ I'd take a hard look at Go, figure out whether I really need C++ performance, or whether Go is just good enough. Go is rather performant and in contrast to C++ memory safe.

If you say that C++ is not memory safe you really don't know the modern C++. Of course you can use only `void *` everywhere... but you can also write your software in a totally different way. My C++ code has no pointers, just objects, which are automatically destroyed when I want to. The nice feature is that I know when the destructor is called, so the object will clear itself in a very nice way.

You're just wasting your energy man. People still think we live in the C++98 era.

Re: Building a Website with C++

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

I love the downvotes from the typical HN "Rust for everything" fans. Perhaps try re-reading the comment and understanding that this is not an attack on Rust, but rather a post questioning the use of a system language to build a web front-end.

Re: Building a Website with C++

#33
I'm in the early stages of a FaaS platform that uses CGI for the functions. As such, I have been collecting articles about general CGI development, and have them listed in my docs. If anyone is interested in writing large scale CGI apps (CGI is popping up a lot around here lately), these are some good resources: https://bigcgi.com/docs

Re: Building a Website with C++

#35

I'm in the early stages of a FaaS platform that uses CGI for the functions. As such, I have been collecting articles about general CGI development, and have them listed in my docs. If anyone is interested in writing large scale CGI apps (CGI is popping up a lot around here lately), these are some good resources: https://bigcgi.com/docs

Isn't cgi slow ? Don't you need something like fast-cgi (which lambda does I think) ?

Re: Building a Website with C++

#36
post #25

Bevor I'd use C++ I'd take a hard look at Go, figure out whether I really need C++ performance, or whether Go is just good enough. Go is rather performant and in contrast to C++ memory safe.

If you say that C++ is not memory safe you really don't know the modern C++. Of course you can use only `void *` everywhere... but you can also write your software in a totally different way. My C++ code has no pointers, just objects, which are automatically destroyed when I want to. The nice feature is that I know when the destructor is called, so the object will clear itself in a very nice way.

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!".

Re: Building a Website with C++

#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'm sure there are a few demanding applications out there that need it.

Since a web page's throughput is usually network bottlenecked and not CPU bound, I'm curious (just for fun) what the max possible performance benefit of going C++ is, especially behind a CGI interface?

There's probably a small latency benefit at all times, and I'd guess there's a throughput benefit that is only visible if you're doing more than a few thousand requests per second..?

Re: Building a Website with C++

#39
Pion[0] is a fairly robust and well-written HTTP server implementation in C++. You can spin up a server very quickly and reverse proxy through Apache or Nginx. Microsoft has a cross-platform offering of some sort in the works using C++11, now I don’t remember the name but I think Herb Sutter has a write-up in it from a couple years ago. It’s definitely possible to write modern web applications in C++, I feel like the cgi route is pretty old school.

[0] https://github.com/splunk/pion

Re: Building a Website with C++

#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 protects you from naive injections:

https://golang.org/pkg/html/template/

Post reply on HN