C as a web scripting language

Discussion in 'C Programming' started by lovecreatesbeauty@gmai1.c0m, Sep 28, 2009.

  1. 0m

    0m Guest

    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
    0m, Sep 28, 2009
    #1
    1. Advertising

  2. 0m

    Seebs Guest

    On 2009-09-28, 0m <> wrote:
    > 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
    --
    Copyright 2009, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    Seebs, Sep 28, 2009
    #2
    1. Advertising

  3. 0m

    jacob navia Guest

    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.

    :)
    jacob navia, Sep 28, 2009
    #3
  4. 0m

    bartc Guest

    "0m" <> wrote in message
    news:...
    > 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.

    --
    Bartc
    bartc, Sep 28, 2009
    #4
  5. >>>>> "lcb" == lovecreatesbeauty@gmai1 c0m <>
    >>>>> writes


    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




    --
    Charlton Wilbur
    Charlton Wilbur, Sep 28, 2009
    #5
  6. 0m

    jacob navia Guest

    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?

    :)
    jacob navia, Sep 28, 2009
    #6
  7. 0m

    jacob navia Guest

    Pietro Cerutti a écrit :
    > On Mon, 28 Sep 2009 17:17:14 +0200, jacob navia wrote:
    >
    >> 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?
    >>
    >> :)

    >
    > 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!
    jacob navia, Sep 28, 2009
    #7
  8. 0m

    cognacc Guest

    On Sep 28, 5:39 pm, Pietro Cerutti <> wrote:

    > 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
    cognacc, Sep 28, 2009
    #8
  9. 0m <> wrote:
    >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
    Beej Jorgensen, Sep 28, 2009
    #9
  10. >>>>> "RH" == Richard Heathfield <> writes:

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


    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


    --
    Charlton Wilbur
    Charlton Wilbur, Sep 28, 2009
    #10
  11. 0m

    Stefan Ram Guest

    Stefan Ram, Sep 28, 2009
    #11
  12. 0m

    bartc Guest

    "Charlton Wilbur" <> wrote in message
    news:...
    >>>>>> "RH" == Richard Heathfield <> writes:

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

    >
    > 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.)

    --
    Bartc
    bartc, Sep 28, 2009
    #12
  13. "bartc" <> writes:
    [...]
    >> 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.)


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

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 29, 2009
    #13
  14. >>>>> "SR" == Stefan Ram <-berlin.de> writes:

    SR> Charlton Wilbur <> writes:

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


    SR> http://google.to/search?q="C interpreter"

    .....and if you do that, the claims that C is 400 times faster than
    Python suddenly fade away.

    Charlton


    --
    Charlton Wilbur
    Charlton Wilbur, Sep 29, 2009
    #14
  15. >>>>> "RH" == Richard Heathfield <> writes:

    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


    --
    Charlton Wilbur
    Charlton Wilbur, Sep 29, 2009
    #15
  16. On 28 Sep, 16:17, jacob navia <> wrote:
    > 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.


    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.
    Nick Keighley, Sep 29, 2009
    #16
  17. On 29 Sep, 08:29, Richard Heathfield <> wrote:
    > In <>, Charlton Wilbur wrote:
    > >>>>>> "RH" == Richard Heathfield <> writes:



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

    >
    > 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?

    > > The distinction between source code and executable is one of the
    > > reasons,

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

    > > and C's strengths -- performance and low-level control --
    > > tend not to be advantages in web programming.

    >
    > Performance is *always* nice to have.


    sometimes human cycles are more important than machine cycles
    Nick Keighley, Sep 29, 2009
    #17
  18. 0m

    bartc Guest

    "Richard Heathfield" <> wrote in message
    news:...

    >... 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).

    --
    Bartc
    bartc, Sep 29, 2009
    #18
  19. 0m

    bartc Guest

    "Richard Heathfield" <> wrote in message
    news:...
    > In
    > <>,
    > Nick Keighley wrote:
    >
    > <snip>
    >
    >> I have heard of programs that only existed in executable form.

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

    --
    bartc
    bartc, Sep 29, 2009
    #19
  20. 0m

    jacob navia Guest

    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.
    jacob navia, Sep 29, 2009
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian
    Replies:
    2
    Views:
    373
    Kevin Spencer
    Feb 6, 2006
  2. Gerald Bauer
    Replies:
    0
    Views:
    326
    Gerald Bauer
    Dec 8, 2003
  3. Ron Stephens
    Replies:
    23
    Views:
    2,832
    Ron Stephens
    Apr 12, 2004
  4. DaveInSidney
    Replies:
    0
    Views:
    414
    DaveInSidney
    May 9, 2005
  5. Petite Abeille
    Replies:
    0
    Views:
    273
    Petite Abeille
    Dec 14, 2008
Loading...

Share This Page