Live data from Hacker News

Web development in C: Crazy?

medium.com

111–120 of 213 posts

Re: Web development in C: Crazy?

#112
post #103

Earlier quoted context omitted.

Maybe your problem is CPU-bound. Maybe there are good C libraries that solve your problem. Maybe you just want to learn C better. Maybe you have latency limits you need to work within. Maybe you just want to be contrary. Sometimes "why not" is worth more than "why."

> Maybe your problem is CPU-bound. Maybe you have latency limits you need to work within. Unless you have lots and lots of time to spend micro-optimizing everything, you'll get better performance writing in Haskell. > Maybe there are good C libraries that solve your problem Maybe, but most of the original post is about how lacking the library ecosystem is. I can well believe that you might have some useful domain-spe…

> lots and lots of time to spend micro-optimizing everything

If you're an experienced C developer you know what's fast and what not (and you know about things like cache coherency). You don't spend that much time on 'micro optimization' because you know how to layout your memory in the first place, etc.

Re: Web development in C: Crazy?

#113
I'm mainly a C dev and I would never ever use C to write a web app. Not because I don't think it could be done, not because I don't think it could be done well but simply because string manipulations in C are a pity. Containers which are not dumb arrays in C are a pity. SQL bindings are much more tedious than the higher-level languages counterparts (I wrote quite a bunch of C interfacing with SQLite, it works well but requires a lot of LoC compared to perl for instance).

Basically 90% of what you do in a typical web framework in your scripting language of choice becomes 10 times more tedious and error-prone in C (and probably 100 times faster but frankly, who cares?)

It's already painful when I need to write sysfs and debugfs interfaces (and the linux kernel has a pretty nice API to write in those).

The only reason I can imagine for using C in a web app is performances but then:

1/ I would try to profile my app and see where the bottleneck is. If it's really CPU-bound and C would really help I'd try to write a small C library for this particular piece of code and bind it in my scripting language.

2/ If I really must write the whole thing in C for some reason I'd try to push for a subset of C++ with at least std::string, std::map, constructors and destructor to ease ressource management and maybe exceptions for error handling. Done well you'll get similar performances and with a bit of luck you might actually come up with something remotely maintainable.

Re: Web development in C: Crazy?

#114
post #87
post #69

Why C? Performance. I wrote a C webserver on a PIC32MX795F512L (80 mhz/ 128kB RAM), and it was _screaming_ fast (for what it was running on). Easily handled ~100 clients making 2-3 requests/sec continuously to a JSON based API (I really don't know how far you could push it before it got slow), which is respectable for that chip ... but this was written to the bare metal with no OS (did use libraries for IP/TCP/HTTP/J…

Modula-2, Turbo Pascal, Ada...?

... Haskell...?

Re: Web development in C: Crazy?

#115
post #114
post #87

Earlier quoted context omitted.

Modula-2, Turbo Pascal, Ada...?

... Haskell...?

I was just listing some languages that were designed as system programming languages as well.

But any language with native code compilers, that is able to have small footprint executables would do.

Re: Web development in C: Crazy?

#116
You can have the best of both worlds by writing low-level modules in C for use within a higher level framework.

For example, I've been having a great time writing this music player backend in C[1], but as soon as it's solid I'm going to write a node.js addon module and then use that as the backend for my web-based audio player[2].

[1]: https://github.com/superjoe30/libgroove

[2]: https://github.com/superjoe30/groovebasin

Re: Web development in C: Crazy?

#117
post #85

Earlier quoted context omitted.

> C and C++ compilers can produce faster execution than Go or JVMs as they support SIMD vectorization e.g. SSE/AVX. For CPU-bound workloads you can get more than 2x speed up. This is an implementation issue. Nothing prevents a compiler vendor to offer the same capabilities to their language compilers. Vectorization is not part of ANSI/ISO C or ANSI/ISO C++. For the time being, do you want vectorization in Go? Write a…

sumatra is for parallelizing mainly on GPU, not for SIMD - current C/C++ compilers neither do that. Java has SIMD support for quite a long while now, probably since Java 6 or even earlier and generally C-like Java code using raw arrays and primitives is as-fast-as-C these days. I'd be more afraid of lack of true value types in Java. This one thing makes C still a better choice for high performance stuff.

> I'd be more afraid of lack of true value types in Java

The IBM J9 VM already has them.

http://duimovich.blogspot.ca/2012/11/packed-objects-in-java....

http://www.slideshare.net/mmitran/ibm-java-packed-objects-mm...

Re: Web development in C: Crazy?

#118
libfcgi (C) + postgres worked like a charm for me. There are also things like libmicrohttpd, libevent/libev, ... that are also very useful if you want to play even more. It's not that hard if you know C.

Re: Web development in C: Crazy?

#119
post #46

WHYYYYYYYYY No, seriously, why ? As far as I can tell, his entire argument is "web development in C is terrible and limiting, but not as quite as terrible and limiting as you might think." I guess that's good news if terrorists are forcing you to write websites in C, but I don't see even an attempt at explaining why you would choose to do this.

I should think the reasons are obvious: 1) Whatever language you are most proficient in, that is often the most efficient tool for _you_ to get the job done right. 2) PHP is largely C for people who should never program in C (or PHP ;-). Depending on the nature of what you are doing, and if you use some basic support libraries (and the author mentions a few), your code needn't be that much more work to get done than…

If you need a lot of C interfacing go with something that interfaces well with C. Like Lua.

Re: Web development in C: Crazy?

#120
post #80

Earlier quoted context omitted.

> It actually worked, once I spend 20 hours in valgrind Thia is exactly the main problem with C. You need to rely on tolling outside the language to be able to write safer code. While languages like Ada and Modula-2 and their descendents, offer the same hardware capabilities as C with stronger type checking.

We use C# which allows you to write safe code. However, people still manage to fuck it up at an implementation level often enough for it to cause high risk problems.

I do mostly JVM and .NET based development nowadays, in consulting projects.

Sometimes I wish to be part of a C or C++ based project, then I try to imagine how the quality of our offshore guys would map to those languages and realize how lucky I am not to be part of such projects.

Post reply on HN