

Show HN: Tofu -- (Yet another) C web framework - al3xbio
https://github.com/AlexBio/Tofu

======
luser001
I've also had good success hacking a bare-bones routing infrastructure on top
of mongoose, a single-file threaded HTTP/HTTPS server.

I've had to read or step through the code a few times. It wasn't too painful.

I like Mongoose. :)

<http://code.google.com/p/mongoose/wiki/Features>

~~~
dryicerx
Another +1 for mongoose, it's great for adding a quick web interface to a
c/c++ program quickly (ie. status or quick admin interface)... but I wouldn't
use it as a web-framework for serving multiple users or to the public on the
web though.

------
unwind
I realize it's a bit nit-picky and off-topic, but it was interesting to see C
written with spaces around the "->" (access structure field through pointer)
operator.

What is almost always written as "a->b = c;" is written as "a -> b = c;" in
the Tofu code.

I guess doing so makes sense if you also promote writing "a = b + c;" (which I
do), but it was still novel-looking, to me. I guess you can treat -> as any
other binary operator.

~~~
al3xbio
I actually find "->" with spaces cleaner and easier to read (just like with
almost all the other operators). The "->" operatore without spaces around is
very popular (also in Perl code AFAICS), and I sometimes wonder why people do
put spaces around e.g. "+" and "=" but not "->".

~~~
ZitchDog
I always figured it was due to it's similarity to the . operator, which never
has spaces around it.

------
aen1
Not to criticize unnecessarily, but what would anyone want to code web apps in
C? I'm not saying rails, etc. are the be-all-end-all, but why C? To seem
extreme?

------
jcfrei
I've never really seen the benefit of using frameworks... are they as highly
customizable as php, when it comes to html code? because if not, I can save
myself a lot of work by writing the whole html by hand and then use ajax calls
to retrieve all the dynamic content... unless of course page generation is
absolutely crucial and I want as few http requests as possible...

could someone elaborate on this?

~~~
meric
What you're describing sound more like the definition of a CMS than of a
framework. With frameworks you no longer have to manage your own
sockets/sessions/connections (some servers take care of this also). Instead of
you calling on a socket to send data to clients, the framework calls your
functions that simply return the data. More elaborate frameworks come with
"helper" functions that, for example, cleans up input data for preparation of
saving to the database, (preventing SQL injections), abstracts away the
database models. i.e write only one set of models in python, so you don't have
to rewrite your database tables when you switch from MSSQL to PGSQL. Each
framework come with their own set of design patterns. While this might reduce
the flexibility in terms of the architecture design, a framework has been
tested and used many times, so the patterns a framework comes with are usually
quite suited for what the framework is designed for. e.g. with Django web
framework, you (must) use an MVC architecture. Although it is quite difficult
to diverge from the MVC pattern, the MVC pattern is a suitable choice for web
applications.

Frameworks abstracts away the bare metal of the HTTP protocol, the database,
and allows you to concentrate only on the content and logic. A framework is
basically a semi-built application; Look at your past websites, what are the
common things between all of them? If you abstract all of that into a
'library', you might have some sort of framework there.

Of course with PHP, a lot of that is already taken care of. One thing I
remember from PHP was that you write your code in a .php file, and the name of
the file becomes part of the URL the user must type into the browser. Well, a
framework can abstract away that too, so you can write your own urls and
redirect to the appropriate function/file to handle the 'visit'.

 _I might have overstated what a framework can do here, I rarely go without it
so perhaps maybe running with only a server can still provide some of the
above described functionality, especially with regards to connections and
sockets._

------
alexchamberlain
I've recently looked at extending Nginx for my own gains. This has several
advantages over such frameworks. For example, you can serve both flat files
and dynamic (C) content using the same server. I suspect, security is slightly
better too, since Nginx manage process security etc.

~~~
pjscott
Another possibility is to make your C program handle requests over ZeroMQ and
stick it behind Mongrel2:

<http://mongrel2.org/>

~~~
alexchamberlain
I'll look at this in the future, however, there are a few issues on GitHub
that I would like to see solved first, including the abolition of all warnings
on compilation.

------
adriand
So, is it super fast?

~~~
diminish
not indicative of anything, i was able to compile check using "ab" a "hello
world ap" with eventhttp;

\- sinatra request per second 442 \- tofu requests per second 5909

Note that it is not indicative of anything; just a simple quick test for
curiosity on my vaio laptop with ubuntu 11.10.

Which other C web frameworks could you suggest? Which Sequel-like ORMs for
MySQL could you suggest? I am especially curious on sinatra or rails-like
frameworks with MVC or similar architectures.

~~~
adriand
I can't suggest any others - I've never tried any.

Thanks for doing the benchmarking, though - that's fast!

