Live data from Hacker News

Web development in C: Crazy?

medium.com

91–100 of 213 posts

Re: Web development in C: Crazy?

#92
I don't think the author has offered a great argument in this article. Building a new website in C sounds like a fun learning experience, but it's not a practical choice for the typical startup CRUD app.

When you're a startup, your biggest problem 99.999% of the time isn't running out of memory or not having a fast enough app, but getting an MVP up and launched and finding enough paying customers so that you don't run out of money. Except in specialized cases where your app is very CPU intensive, C provides a major headache without a major immediate advantage.

But C is a great choice for replacing parts of your app if you start growing and when you start figuring out exactly what services need to be faster and use less memory.

Re: Web development in C: Crazy?

#93

The Fossil DVCS has a built-in web interface for reviewing commits, along with a bug tracker and a wiki. It's all written in C, albeit with a couple of custom macro preprocessors. I once wrote a toy web page in C; Lex made for nice HTML templating and with pseudOO it actually felt pretty modern, but I still wasted a whole lot of time reinventing various wheels.

Thanks for the reminder about fossil. I tend to forget that it's all c (and therefore, must contain a wiki in c). Reviewing in that code base added to todo...

Re: Web development in C: Crazy?

#94
In the early days when Perl was the CGI de jure the company I worked for wrote their cgi in C and ran on Zeus webservers. This was for performance on one of the most highly traffic'd sites at the time.

Re: Web development in C: Crazy?

#95

There are hardly any benefits in writing your web app in C ove r Java or Go. That 1% speed increase is nothing compared to the huge amount network wait these apps will be doing. If you really consider it, what 95% of people write these days is glue between various services, and the parts that do matter, where you need the most performance, are already written in C. The reason why Redis, MongoDB and Postgres have good…

> So when it comes down to it all you are really doing is string parsing and string transporting, thats really the last thing you want to leave to C.

Exactly. String parsing is the biggest shortcoming in C that always gives me a second thought when I'm about to choose a language for a higher level application (especially if it incorporates user input as strings). Even such trivial thing as AT command parser is a pain in C. Of course, there are parser generators as Bison, but still it's tedious amount of work and usually not worth it.

Re: Web development in C: Crazy?

#97
post #5

So, people can't hardly write safe web apps in PHP without spraying XSS and auth bypasses and arbitrary shell executions and arbitrary SQL injections everywhere, and you also want to hand the attackers the ability to segfault your server or possibly even straight-up run arbitrary code? Anyone smart enough to truly safely code a website in C is smart enough to learn a language to create that website which doesn't get…

Seems like the rules for C web development are the same as for any other language: don't trust user input, and delegate the sanitization to vetted library functions. It's not like it's 1991 and you have to use plain arrays and strcmp; there are really good, safe libraries for these things. That said, doing web development in a language with neither a REPL nor built-in unicode support sounds like a Bad Time.

You mean like this?

https://github.com/tyler/Bogart/blob/master/bogart.c#L53

I'm sure nothing could possibly go wrong there...

Re: Web development in C: Crazy?

#98

Earlier quoted context omitted.

Seems like the rules for C web development are the same as for any other language: don't trust user input, and delegate the sanitization to vetted library functions. It's not like it's 1991 and you have to use plain arrays and strcmp; there are really good, safe libraries for these things. That said, doing web development in a language with neither a REPL nor built-in unicode support sounds like a Bad Time.

Still an order of magnitude easier not to shoot yourself in the foot in most higher level language. Pretty sure you still have to use plain arrays and strcmp, what are these "safe" libraries you were going to use? Unless we are talking about C++ here? Also C supports unicode fine (to the extent it supports strings) and REPL can't hardly be considered a requirement for web development considering Java, .NET and PHP* d…

> Pretty sure you still have to use plain arrays and strcmp, what are these "safe" libraries you were going to use?

So, thought it would be worth giving some examples. By far the lowest level solution are things like strlcpy & strlcat, which basically still live in a NULL terminated world by try not to be stupid about it:

http://www.gratisoft.us/todd/papers/strlcpy.html

There are some specifically targeting strings and making them both more efficient and safer:

http://bstring.sourceforge.net/

There's more sophisticated runtimes like glib or APR, which almost seem like they are trying to completely replace the C runtime, but they provide very clean memory management interfaces and string & blob/block abstractions that allow you to avoid having to worry about a buffer overflow.

Then there are solutions built on top of the likes of that. Things like the GGSK: http://gsk.sourceforge.net/

There's lots more, but it's late and I'm tired. ;-)

Re: Web development in C: Crazy?

#99
post #81
post #68

Earlier quoted context omitted.

Google is so huge now, I'm not sure if that is really something that you can state unequivocally. The search engine and a lot of the plumbing that everything is built on top of is written primarily in C++, but there is a TON of both Java and Python code there (and that's not counting things like Go and specialized languages like the infamous Sawzall). Back in the day (particularly before they started doing ads), almo…

Only tools, one-offs, and small internal products at Google can use Python. In general, for production it is disallowed (with exception of YouTube). They learned with YouTube that Python doesn't scale well to hundreds or thousands of developers. Even Mondrian, the code review system started by Guido and written in python, was replaced by something more scalable.

> Only tools, one-offs, and small internal products at Google can use Python.

Also YouTube (you may have heard of it).

> with exception of YouTube

Oh, you have. ;-)

You didn't mention java though... there's a TON of stuff in Java at Google.

Re: Web development in C: Crazy?

#100
If you do want do do it in c, I think php pretty much got it right -- write an extension in c, and use something else for the rest. Se eg: http://phalconphp.com/en/

Then there's of course G-Wan -- source of a lot of speculation, and frequent border-irrational (counter)claims by it's author -- but undoubtedly a good contender for easy-to use server with c-language "scripting":

http://gwan.com/

A newer server in the same space is nxweb, which seems made for doing the kind of work the article talks about - simple, high performance web-services in c:

https://bitbucket.org/yarosla/nxweb/wiki/Home

For other languages, have a look at hello-world webservers at rosetta:

http://rosettacode.org/wiki/Hello_world/Web_server#C

Other related projects:

mongoose - small embeddable, cross platform web server w/lua scripting: http://cesanta.com/

lighttz - webserver in c using libev: http://arekzb.wordpress.com/2008/04/27/lighttz-a-simple-and-...

Still, if it were me, and I needed "c-speed", I'd probably go with cgi (or fastcgi). Forking on every request might not be the absolute fastest, but with the binary cached in ram, it's still pretty fast on Linux. Or maybe just use mongrel2 and a c handler:

https://github.com/derdewey/mongrel2_c_handler/tree/master/l...

Post reply on HN