C as a web scripting language

L

lovecreatesbeauty

I'm going to do some work on apache plus webdav and don't want to use
a bit of php or perl. I found "ANSI C Server Scripts TrustLeap G-WAN
ANSI C Scripts (*.c)" as an example item on this wiki[1]. The G-WAN
was googled and it states the posibility/advantage of using C as a web
script[2]:

I ever wondered why sh(bsh) isn't 100% compatible with C in syntax,
and bash syntax is worse. Csh was considered harmful and I didn't try
it.

NOW! ANSI C as a dynamic web scripting language?

IS THIS..I MEAN..OK?

<quote>
....
use C rather than a 'modern' language for scripts: C is 400x faster
than PHP, 200x for Python, 8x for Java, 5x for C#; On 180,000 open-
source projects 47% use C, 28% Java, 11% PHP; C can be as safe as any
other language (see the 'crash.c' servlet).
....
</quote>

1. http://en.wikipedia.org/wiki/Server-side_scripting
2. http://trustleap.com/en_developers.html
 
S

Seebs

NOW! ANSI C as a dynamic web scripting language?

IS THIS..I MEAN..OK?

I sure wouldn't do it, normally. I have a single C web app in my collection,
for specialized reasons; in general, I would not use C for web apps, because
it's very much not a string processing language by nature.

-s
 
J

jacob navia

(e-mail address removed)0m a écrit :
I'm going to do some work on apache plus webdav and don't want to use
a bit of php or perl. I found "ANSI C Server Scripts TrustLeap G-WAN
ANSI C Scripts (*.c)" as an example item on this wiki[1]. The G-WAN
was googled and it states the posibility/advantage of using C as a web
script[2]:

I ever wondered why sh(bsh) isn't 100% compatible with C in syntax,
and bash syntax is worse. Csh was considered harmful and I didn't try
it.

NOW! ANSI C as a dynamic web scripting language?

IS THIS..I MEAN..OK?

<quote>
...
use C rather than a 'modern' language for scripts: C is 400x faster
than PHP, 200x for Python, 8x for Java, 5x for C#; On 180,000 open-
source projects 47% use C, 28% Java, 11% PHP; C can be as safe as any
other language (see the 'crash.c' servlet).
...
</quote>

1. http://en.wikipedia.org/wiki/Server-side_scripting
2. http://trustleap.com/en_developers.html

I have done a web script in plain C without any problems.

My script connects to the Mars Rovers site of NASA and looks
for new images. If there are any, it will download them into a mirror
of the Opportunity and Spirit sites in NASA.

I found very easy to handle the parsing of HTML for instance in C.

I don't do any parsing at all. I just search (with strstr) several
keywords that appear only in the images, then, do some filtering and
I get into the URL of the image. I strip the URL part and
see if the image is already there in my mirror directory hierarchy.

If it is not there I just download it and go on with the next image.

This is not server side scripting but client side scripting but the
principles are very similar.

(1) Keep it simple, just do the minimum amount of work.
(2) Use high level libraries and forget about "ansi C" or
"portability". Lcc-win for instance includes a library with the
functionality of "wget": GetHttpUrl. This is just one call and
you get the given URL. If you would need to start programming
a background downloader it would take months.
(3) Avoid much parsing if possible. And if you must, do not forget
(2). Use some library rather than a "do it yourself" approach.
(4) Forget about malloc/free if you can. Use a GC, or, if you can,
just allocate memory relying on the OS to do the cleanup when
the script ends.

And (5) and most important:

Have fun!

Having fun makes programming lighter.

:)
 
B

bartc

I'm going to do some work on apache plus webdav and don't want to use
a bit of php or perl. I found "ANSI C Server Scripts...
<quote>
...
use C rather than a 'modern' language for scripts: C is 400x faster
than PHP, 200x for Python, 8x for Java, 5x for C#; On 180,000 open-
source projects 47% use C, 28% Java, 11% PHP; C can be as safe as any
other language (see the 'crash.c' servlet).
...
</quote>

(From: http://www.timestretch.com/FractalBenchmark.html)

Strange, I found Python 7 times as slow as C for this benchmark, not 200
times.

You might want to conduct your own tests with code typical of your
application, before dismissing those other languages.
 
C

Charlton Wilbur

lcb> NOW! ANSI C as a dynamic web scripting language?

lcb> IS THIS..I MEAN..OK?

The web police won't break your door down and haul you off in the night
if you do it.

lcb> <quote> ... use C rather than a 'modern' language for scripts:
lcb> C is 400x faster than PHP, 200x for Python, 8x for Java, 5x for
lcb> C#; On 180,000 open- source projects 47% use C, 28% Java, 11%
lcb> PHP; C can be as safe as any other language (see the 'crash.c'
lcb> servlet). ... </quote>

Processor time is rarely the bottleneck in web applications; it's almost
always disk I/O or network bandwidth. Optimizing for CPU time -- which
is what you seem to be aiming at, since you cite that it's "400x faster
than PHP" -- won't improve either of those.

You also need to consider development time and maintainability. If
you're starting from scratch, you're going to need to write a *lot* of
code before you get to the point where you can match PHP, Python, Perl,
or Java's built-in functionality.

And as far as maintainability goes -- I worked in a former place that
had done web development in C. There were several applications that
simply could not be modified, as the source code had been lost. And one
of them had significant bugs in the CGI query parsing. Take that as an
object lesson, and learn from it what you will.

Charlton
 
J

jacob navia

Charlton Wilbur a écrit :
And as far as maintainability goes -- I worked in a former place that
had done web development in C. There were several applications that
simply could not be modified, as the source code had been lost. And one
of them had significant bugs in the CGI query parsing. Take that as an
object lesson, and learn from it what you will.

Incredible how much nonsense you can read in this newsgroup.

C is not maintainable because if you don't have the source you
can't modify it.

GREAT!

Now, if you don't have the source of your PHP OBVIOUSLY it
can be maintained

Or not?

:)
 
J

jacob navia

Pietro Cerutti a écrit :
I bet you know what CW meant. With PHP, you always have the source code
at disposal, since the language is interpreted. With C, you could deploy
the compiled object file and trash your source code.

Well, if you trash your only copy and you have no backup that doesn't
matter anyway. You write it again.

And (escuse me) but if ytou do that to your php script you do the same
you write it again.

I fail to understand why this is an argument *against* using C!
 
C

cognacc

I bet you know what CW meant. With PHP, you always have the source code
at disposal, since the language is interpreted. With C, you could deploy
the compiled object file and trash your source code.

Well , that could happen, but aside from that, i can't
see it says anything about the maintainability, ?

mic
 
B

Beej Jorgensen

I'm going to do some work on apache plus webdav and don't want to use
a bit of php or perl. I found "ANSI C Server Scripts TrustLeap G-WAN
ANSI C Scripts (*.c)" as an example item on this wiki[1]

When the web was young, I wrote all my CGI scripts in C... but as time
went on, I used various scripting languages more and more, as they were
easier to use and easier to make secure (e.g. built-in functions for
sterilizing user input), and were often "fast enough".

A good rule-of-thumb is to ask yourself what would happen if an expert
programmer came upon your C script. Would they say, "This is good
because in this case we needed the raw computing performance C
provides", or would they say, "Why didn't this guy write a 10-line
Python script instead of all this?"
The G-WAN was googled and it states the posibility/advantage of using C
as a web script[2]:

WHAT IS G-WAN?

G-WAN is a small-footprint (100 KB) Web server with C scripts executed
in real-time (no compiler needed).

Their FAQ contains way too much market-speak and way too few details for
my tastes. They say their server is "/provably/ safer" (emphasis
theirs), but don't release the source, so you'll never really know. And
when someone says some software is "provably" anything, I start thinking
about Knuth.

That 200x faster than Python/400x faster than PHP figure is not always
true in general--you'll note that the benchmark was on a fractal
calculation which isn't exactly a common web app.

I could go on, but I'm not going to. :)

C is lots of fun, but I've used Python and PHP when they're the right
tool for the job. (For different web fun, check out yaws!)

-Beej
 
C

Charlton Wilbur

RH> The only sensible lesson there is "look after your source
RH> code". Your anecdote carries no weight whatsoever as an argument
RH> against using C for Web scripting.

Except that in every other language listed -- PHP, Python, Perl -- the
source code is directly executable.

Charlton
 
B

bartc

Charlton Wilbur said:
RH> The only sensible lesson there is "look after your source
RH> code". Your anecdote carries no weight whatsoever as an argument
RH> against using C for Web scripting.

Except that in every other language listed -- PHP, Python, Perl -- the
source code is directly executable.

That might be true but how many of these distribute actual source code
rather than some intermediate form? (I don't know; I'm just asking.)
 
K

Keith Thompson

bartc said:
That might be true but how many of these distribute actual source code
rather than some intermediate form? (I don't know; I'm just asking.)

<OT>
All of them. To be precise, PHP, Python, and Perl software is almost
always distributed as source.
</OT>
 
C

Charlton Wilbur

RH> If, as appears to be the case, he is arguing that the danger of
RH> losing C source is a persuasive reason for not using C for Web
RH> scripting, then the same argument applies to any compiled
RH> language, so presumably he is advocating an interpreted
RH> language.

It's an issue of concern for the web, yes. There are dozens of
arguments in favor of any given language and dozens of arguments against
any given language. In each problem domain, some languages are better
than others.

While I am a fan of C -- else I would not be here -- I really think it
is a terrible choice of language for web programming. The distinction
between source code and executable is one of the reasons, and C's
strengths -- performance and low-level control -- tend not to be
advantages in web programming.

By choosing C, you're volunteering for an exercise in configuration
management and build packaging that you don't need to engage in if you
use an interpreted language, and the benefits of using C just don't
materialize.

RH> We then have two risks: losing the source code (just as with the
RH> compiled language) *and* losing the - ahem - dynamic translation
RH> program(!). So the risk is actually greater if you /don't/ use C
RH> for Web scripting.

Oddly enough, there are people all over this newfangled thing called the
Internet who are happy to keep duplicate copies of the Perl interpreter
at no direct cost to me. They seem far less willing to keep archives of
my source code for the same fee.

Now, if the whole Internet crashed and at the same time I mislaid my
copy of the interpreter, I'd be in trouble. Somehow, however, I suspect
that if that happens I will have other, larger problems.

RH> Conclusion: use C for everything. Web scripting, application
RH> development, systems development, making coffee, curing the
RH> common cold, and of course seeking the true meaning of life (if
RH> you have time).

In Perl that's a one-liner, but the last seven people who tried to
understand it are now catatonic.

Charlton
 
N

Nick Keighley

Charlton Wilbur a écrit :

use a decent configuration control system and shoot (actually hanging
drawing and quatering would be appropriate but I don't like to
over-react) anyone who fails to use it.

Incredible how much nonsense you can read in this newsgroup.

I have heard of programs that only existed in executable form.
C is not maintainable because if you don't have the source you
can't modify it.

GREAT!

Now, if you don't have the source of your PHP OBVIOUSLY it
can be maintained

Or not?

:)

:)

even python has a semi-compiled form. So you could lose
your source code for that. The only sensible thing
to do is to write your CGI code directly in binary.
 
N

Nick Keighley

I have yet to find a language that is not a terrible choice for Web
programming.

why? I'm just curious. What would an excellent web language need?
And why don't any of 'em have it?
I find that reason to be utterly risible.

I'm with you here.
If you can't keep track of
source code, what makes you think you can keep track of source code?

ah but there's a time difference. If I lose my perl code my website
stops working. Right then. I can immediately go off and search the
daily backup or the wastebin or whatever. If my C source disappears
it might be *years* before I notice I can't actually recompile
what I've got.
Performance is *always* nice to have.

sometimes human cycles are more important than machine cycles
 
B

bartc

... We then have two risks: losing
the source code (just as with the compiled language) *and* losing the
- ahem - dynamic translation program(!).

That's not the same risk.

It's like losing your wedding video, compared with someone stealing your
VCR. One is easily replaceable, the other isn't (ignoring the fact that VCRs
are near obsolete).
 
B

bartc

Richard Heathfield said:
In
Nick Keighley wrote:



I have /written/ programs that only exist in executable form. And
anyone else who has written a program in machine code has done the
same.

I tended to write mine down on paper first. Then you just had to take care
of that paper.
 
J

jacob navia

Charlton Wilbur a critics :
By choosing C, you're volunteering for an exercise in configuration
management and build packaging that you don't need to engage in if you
use an interpreted language, and the benefits of using C just don't
materialize.


Mr Wilbur

You are repeating here the views that you need to trust
the programmers as little as you can,
because they are just mostly inept.

For instance in the thread "When will C have an object model?" you said:
> the Java philosophy and approach means
> that it's possible to throw lots of people at the problem, that hordes
> of fairly low-talent and interchangeable code monkeys, organized and
> supervised by competent managers and architects, can produce reasonably
> reliable and bug-free software.

In this example is the same basic underlying view:

"C isn't that good because the monkeys can loose the C source code, so better
use a language where the monkeys notice immediately what is going on."

What is most distressing is that you fail to understand that your way of
"management" PROVOKES the problem instead of solving it!

If *I* would work with a management that shows so much *contempt* for me
I would surely loose the source code, introduce as much bugs as possible
and in general I would do as LITTLE effort as possible to people that
think that I am just another "monkey".

Then, YOUR solution is obviously NOT to understand why people are so
unmotivated, why people do not care for their work and to remedy
the root of the problem. Of course not.

Your solution is to... ban "C" because the monkeys could loose their
source code.

You *can* "manage by contempt" if you are running a farm for instance,
and you pay people by the piece of fruit they harvest...

If people are motivated or not doesn't count since all that counts is the
number of apples they harvest.

Software engineering is a little bit different, as you *may* have noticed.

Here the motivation of the employees is fundamental. And if you think
they are just stupid monkeys they will surely end up noticing your
opinion... and will act accordingly.

Yours sincerely

Jacob Navia
Programmer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top