Slashdot Mirror


Web Programming by printf()

An anonymous reader writes "Art & Logic has posted an article titled 'Why CGI is Evil'. CGI might be an obvious way to create a simple web application, but this article provides some excellent high-level reasons why CGI rarely makes long-term sense. A nice review especially for new web programmers."

104 comments

  1. perl is even worse than printf by Horny+Smurf · · Score: 0, Funny
    Proof? Slashdot!

    1. Re:perl is even worse than printf by aridhol · · Score: 0

      Of course, the Perl method is similar to what is presented in the article. The majority of the script handles programming, while the content is embedded within the script and sent out using some sort of print statement.

      --
      I can't say that I don't give a fuck. I've just run out of fuck to give.
  2. Evil by hackwrench · · Score: 1

    First GOTO and now CGI. Why doesn't someone call C evil so we can call it a night

    1. Re:Evil by Anonymous Coward · · Score: 0

      C is evil!

      'night!

  3. cgi underrated by Anonymous Coward · · Score: 1, Insightful

    One of the author's complaints against cgi was the slowdown and overhead of having to fork a separate process. Let's look at that claim.
    There is a penalty to forking, but there is also a penalty to running interpreted code (java, php, perl, etc). Additionally, for scripting languages like perl and php, there is also cost of parsing and validating the code -- something that doesn't need to be done with compiled C code, and which takes a much longer time.
    Additionally, forked CGI runs in its own process space, and can't cause errors with the web server (IIS/apache).

    1. Re:cgi underrated by WoTG · · Score: 2, Interesting

      True, there is a penalty to interpreted code, but a lot of this penalty can be mitigated (in PHP at least). The folks at Zend offer their PHP accelerator, and I use the ion cube (free as in beer) on my puny home server.

      Both of these compile the scripts, and parse, and validate _once_ (per reboot). For every subsequent call to the script, the server just runs the cached copy of the compiled code. So, you get all of the benefits of the scripted language, i.e. speed of coding, and fewer of the downsides.

  4. In case the article is slashdotted... (HAHA) by ajuda · · Score: 1

    Executive Summary: CGI is slow, and you can't really use MVC principles. The end.

  5. interesting to see... by Anonymous Coward · · Score: 0

    It's interesting to see the parallels between the traditional web development world and the "embedded web" world. Firmware engineers, dealing with less evolved (ie tiny) web development tools, are learning the same thing traditional web developers learned a few years ago.

  6. CGI still has uses by LordNimon · · Score: 2, Insightful

    What if your CGI programs need to get data from libraries that only have C and C++ interfaces? On the embedded system I'm working on, everything that talks to hardware is written in C or C++, and in many cases the only way to get the data my CGI programs need to is to call a C++ class library. No one would take me seriously if I proposed writing this stuff in PHP or Perl.

    --
    And the men who hold high places must be the ones who start
    To mold a new reality... closer to the heart
    1. Re:CGI still has uses by aridhol · · Score: 1
      You could, for example, use JSP and write a taglib that calls the C interface using RMI. Or the equivalent for whatever your server is capable of running.

      Remember, the reason that most libraries give a C interface is that most other languages can talk to C. It may not be pretty and it may not be easy, but if you can access it in C, you can almost always access it in another language.

      --
      I can't say that I don't give a fuck. I've just run out of fuck to give.
    2. Re:CGI still has uses by highcaffeine · · Score: 3, Informative

      Without much hassle, you can use XS to allow your Perl scripts to interface with C/C++ libraries in a natural way. In fact, many Perl modules are written in C/C++ and wrapped with XS. This allows you to get the best of both worlds in some situations -- streamlined C code to offload intensive operations into separate libraries, then rapidly prototypable Perl front ends to those libraries (whether it be mod_perl for web apps, Perl/GTK for GUI, or any other type of front end you need).

      It's not always the perfect solution, but your post makes it seems as if you don't think there's any way to get C and Perl to talk. Few things are further from the truth. And this isn't just some nifty Perl thing -- many of the "scripting" languages (I can't speak for PHP) offer similar ways to accessing C/C++/etc. I'm just most familiar with Perl's way.

    3. Re:CGI still has uses by LordNimon · · Score: 1

      Wouldn't that require running Java on the server? And what about the C++ interfaces? Can I call those from Java?

      --
      And the men who hold high places must be the ones who start
      To mold a new reality... closer to the heart
    4. Re:CGI still has uses by aridhol · · Score: 1
      If you're using JSP, then yes, you'll have to run Java on the server. However, JSP was just an example. If you write a plugin to PHP, you won't need to run Java.

      As for the C++ interfaces, I believe that you can interface C++ directly to Java, but I'm not positive. However, you can write some wrapper code to put a C interface in front of the C++ interface, then connect your script to the C interface. As I said, it may not be pretty, but it can be done.

      If you need to work in C and only C (for example, your embedded system doesn't have room for a PHP interpreter or for java), there may be systems that translate from a template into C code. This is how JSP works - it translates from a JSP template to a Java servlet to Java bytecode. It should be possible to write a similar system for C, but I don't know if it exists.

      --
      I can't say that I don't give a fuck. I've just run out of fuck to give.
    5. Re:CGI still has uses by Anonymous Coward · · Score: 0

      and i think it's worth mentioning, although masochistic, the converse is true: you can embed the perl interpretter within your C app.

      though doing that for a web application would be really weird...

    6. Re:CGI still has uses by Anonymous Coward · · Score: 0

      ever heard of Inline, or better yet XD?
      Duh, that'be hard...
      First think then post.

    7. Re:CGI still has uses by Anonymous Coward · · Score: 0

      You could write a PHP module in C that binds to two.

    8. Re:CGI still has uses by JavaJoint · · Score: 1
      > What if your CGI programs need to get data from libraries that only have C and C++ interfaces?

      Write a little server in C or C++ that listens on a port (local connections only). Then have mod_<favorite langauge> connect to it for data. Should be faster than CGI, but without the hassle of trying to figure out which language to embed into some other.

    9. Re:CGI still has uses by ProfKyne · · Score: 1

      What if your CGI programs need to get data from libraries that only have C and C++ interfaces?

      Python has really good interfacing with C/C++ code.

      --
      "First you gotta do the truffle shuffle."
  7. Misuse of an acronym? by Masa · · Score: 2, Interesting
    I thought that CGI stands for Common Gateway Interface and is a standard method of transferring information between a server and a client. The method doesn't say anything about the language used. The article gives an impression that CGI is equal to C programming. Isn't CGI a base for almost all WWW browser based client-server communication? What other methods are available? RMI? Bare TCP/UDP sockets? How .NET transfers data between the browser and the server? How Java Server Pages do it?

    As you can see, I'm not a web programmer and the article actually made things more unclear for me. Did I misunderstood something? Can someone clarify things up for me, please?

    1. Re:Misuse of an acronym? by aridhol · · Score: 4, Informative
      No, CGI is between the server and its subprocesses. The connection between your browser and the server is HTTP, and the connection between the server and scripts is CGI.

      I think CGI also refers only to those programs that the server calls directly passing headers in a certain format. While the script may be written in any language, they tend to be written in a language that is primarily a programming language (Perl, C, Python, etc) rather than a content-oriented language (ASP, JSP, PHP, etc).

      JSP usually runs as a separate server that may be contacted by the web server, but is also capable of answering web requests by itself. ASP and PHP are run in the same process space as the web server, and thus can spare the overhead of spawning a new script interpreter for every request. All of these languages are content-oriented, meaning that the scripting code is embedded in the document, rather than having the document embedded in the code.

      Hopefully I haven't confused matters even more ;)

      --
      I can't say that I don't give a fuck. I've just run out of fuck to give.
    2. Re:Misuse of an acronym? by Sentry21 · · Score: 4, Informative

      I think CGI also refers only to those programs that the server calls directly passing headers in a certain format.

      CGI refers to the method of executing external programs, passing parameters to them as environment variables, and then getting the result back from standard output. CGI tends to be external binaries, and thus PHP can be essentially CGI if you use it in its CGI binary form (needlessly complex, and even worse of a performance hit, but it works).

      JSP usually runs as a separate server that may be contacted by the web server, but is also capable of answering web requests by itself.

      Most of the servers I've seen tend to glob everything together, so I'd be inclined to disagree with the 'usually' here. I've usually run it as the 'tomcat' process, which is its own thing.

      You neglected to mention servlets, which are a nice cross between CGI and markup languages like ASP/JSP/PHP. Servlets are small Java programs that are mapped to a directory on the website (like /administration/). They're compiled and placed into the classpath, and then the server executes them in the JVM when a request is made. The benefit is that the code is precompiled and the JVM is preloaded, so the execution time once loaded is almost as fast as a CGI applet would be once loaded, but the load time is less because it doesn't have to fork a separate process.

      That's my imput for the day. If Aridhol hasn't confused matters enough, this hopefully will.

      --Dan

    3. Re:Misuse of an acronym? by aridhol · · Score: 4, Insightful
      Servlets are small Java programs that are mapped to a directory on the website (like /administration/). They're compiled and placed into the classpath, and then the server executes them in the JVM when a request is made.
      Yes, servlets exist, but I feel that they are closer to CGI than to template- or content-based languages. In order to create any output, you still have to use a print()-like function (haven't done much with Servlets, so I can't remember the actual method used here).

      However, a JSP is automatically preprocessed into a servlet before it's compiled into bytecode, so it actually is a halfway point ;)

      --
      I can't say that I don't give a fuck. I've just run out of fuck to give.
    4. Re:Misuse of an acronym? by sporty · · Score: 0

      See my journal entry about this. I had an entire rant about this.

      http://slashdot.org/~sporty/journal/20356

      --

      -
      ping -f 255.255.255.255 # if only

    5. Re:Misuse of an acronym? by jrumney · · Score: 2, Insightful
      Unfortunately, your rant is wrong. CGI is not an interface between a server and a browser at all. That interface is called HTTP.

      CGI is an interface between a webserver and external subprocesses that has been in decline since faster alternatives started appearing in about 1995. While it is technically possible to write CGI programs in Java, PHP or Perl, it is not common. Servlets, PHP, mod_perl and other modern ways of generating dynamic content do not use the CGI interface, instead they have their own more efficient interfaces.

    6. Re:Misuse of an acronym? by sporty · · Score: 1

      I'm sorry, but I believe you are mistaken. CGI's work over HTTP in terms of the get and post methods. In terms of their encoding and all.

      --

      -
      ping -f 255.255.255.255 # if only

    7. Re:Misuse of an acronym? by jrumney · · Score: 2, Informative
      You can beleive all you want, the HTTP protocol is what defines GET and POST methods, and URL encoding.

      CGI on the other hand defines how that information can be passed to external programs by the server (using environment variables and standard in), and how the external program passes information back to the server to be sent to the browser (via standard out).

      A full specification is available from NCSA

    8. Re:Misuse of an acronym? by cant_get_a_good_nick · · Score: 4, Informative

      CGI is pretty much the oldest method of a web server interacting with outside code, and is kind of the only standard way. The server fork/exec's a process and has the CGI process' stdin, stdout, and stderr are pointing back to the server. The web server passes information either through environment variables (for a GET request) or additionally through the process' stdin (for POST and PUT requests).
      Advantages: very clean, the process goes away after the request, so resource leaks aren't a problem. Very simple interaction, if your programming language understands stdin, stdout, and environment variables (hard to find one that doesn't) you can do CGI with it (though some are better than others obviously).
      Disadvantages: fork/exec for every request. That has some overhead, sometimes more important is that the process can't use persistent state. Resources have to be acquired on every request. Anything with a great deal of overhead, say opening a database connection, has a HUGE impact on the server.

      FastCGI is a pseudo-standard in that it has multiple people implementing it, but it never got approved by, say, the IETF. It's a client server kind of thing, where the first instantiation starts the server up and initializes it. Subsequent requests get sent to the CGI server and get returned. The CGI server never goes away. The cool thing is that there are no startup costs, and you can keep something like a DB pool. Never really used it, so can't comment much.

      Some things just get embedded into the server, like Apache modules. You can write C code and it becomes part of the server itself.
      Advantages: wicked fast. Full access to anything in the server.
      Disadvantages: if your CGI has a problem, it can bring down your server. The API's can be pretty arcane. Also, it's a different API for each web server (NSAPI vs. ISAPI vs....) and even between variants (it's wildly different from Apache 1.3 and apache 2.0).

      mod_perl is kind of like above, it's a perl interpreter bound into Apache. Gives a perl interface to pretty much everything apache has to offer. Not only requests, but configurations.
      Advantages: perl is very flexible, can do a lot of things and use perl modules from CPAN, including templating systems and the such. You're also insulated a bit from stray pointers and such. mod_perl also precompiles all of the perl code, so you don't have the compiler overhead on every request.
      Disadvantages: mod_perl can be huge sometimes, and if you have several mod_perl instances running around, you can eat memory pretty quick.

      Everything else is kind of "do what you want". Tomcat itself has several protocols to talk to Apache; some are just old, some are supported on certain platforms only, yadda yadda.

      That said, the article did confuse a bunch of things, CGI, C, and content management systems. He was pushing an agenda, hopoing that people couldn't see through it.

    9. Re:Misuse of an acronym? by Anonymous Coward · · Score: 0

      Read the HTTP RFCs.

    10. Re:Misuse of an acronym? by Anonymous Coward · · Score: 0

      That said, the article did confuse a bunch of things, CGI, C, and content management systems.

      I didn't see anything about content management systems. I don't imagine the author was intending for someone to write a content management system for an embedded device! I never heard of someone using the GoAhead WebServer for that!

    11. Re:Misuse of an acronym? by Sentry21 · · Score: 1

      Yeah, servlets are closer to CGI than preprocessed languages, but CGI is the topic of discussion.. :P

      JSP is automatically preprocessed into what could possibly be said to be a servlet, but the same basic thing happens to PHP pages, and, I expect, to ASP pages (active server page pages?), so aren't those pretty similar too?

      Man, this is making my head hurt.

      --Dan

    12. Re:Misuse of an acronym? by aridhol · · Score: 1

      Similar, except that the JSP spec actually mandates that the JSP be translated into an actual servlet (a Java class adhering to the Servlet API) to simplify debugging. There may be an intermediate form in PHP and ASP (I'd be surprised if there wasn't), but AFAIK JSP is the only one to have the intermediate form specified.

      --
      I can't say that I don't give a fuck. I've just run out of fuck to give.
    13. Re:Misuse of an acronym? by sporty · · Score: 1

      Wow.. how nice and rude. Whatever.. argue with someone who cares.

      --

      -
      ping -f 255.255.255.255 # if only

    14. Re:Misuse of an acronym? by sporty · · Score: 1

      http://cgi-spec.golux.com/cgi-120-00a.html :) tnx for playing

      --

      -
      ping -f 255.255.255.255 # if only

    15. Re:Misuse of an acronym? by Anonymous Coward · · Score: 0

      You've already made a complete fool of yourself, but I have to ask if you even read that link before you posted it.

    16. Re:Misuse of an acronym? by Anonymous Coward · · Score: 0, Offtopic

      no wonder you are so wrong, if you don't even care. next time don't post in the first place, I suppose.

    17. Re:Misuse of an acronym? by Anonymous Coward · · Score: 0

      This rant is so wrong, I don't know where to begin - it's like the clueless leading the even more clueless. I guess you are in high school, but even still, CGI doesn't have anything to do with the web browser, you don't know what a servlet is, and you've never read the HTTP specification.

      The HTTP spec tells you that GET and POST are methods for the HTTP protocol (along with PUT, DELETE, and bunch of other ones we don't use.)

    18. Re:Misuse of an acronym? by sporty · · Score: 0, Offtopic

      oOooo.. did i hurt the little boy's feelings.

      --

      -
      ping -f 255.255.255.255 # if only

    19. Re:Misuse of an acronym? by jhunsake · · Score: 0, Offtopic

      Yes, your complete ignorance of internet technologies hurts my feelings.

    20. Re:Misuse of an acronym? by Evil+Grinn · · Score: 1
      Similar, except that the JSP spec actually mandates that the JSP be translated into an actual servlet (a Java class adhering to the Servlet API) to simplify debugging.

      The idea that this simplifies debugging is a joke. Debugging of the appserver or JSP-to-Java translator, maybe, but its a pain in the ass for debugging the JSP itself.

      I personally have seen one too many message like "NullPointerException at __some.__absurdly.__long.__filename.java(65535)". Then you have to go find this intermediate form (which some appservers might've actually discarded by this point, unless you were smart enough to configure them otherwise). Once you find it, you usally see Java code that is only slightly more readable than an octal dump of the compiled class would've been.

      Then once you figure out what caused the bug and how to fix it, then you have to mentally translate your fix back into JSP from Java, because the JSP is what you have to edit to go make your fix.

      The only positive is that the whole experience is painful enough that it will encourage even the laziest person to learn a framework like Struts, so they can get as much of their code as possible out of the JSPs.

    21. Re:Misuse of an acronym? by Vengeance · · Score: 2, Informative

      Servlets and .JSPs become the same thing behind the scenes, but they are conceptually two different things.

      (The following assumes that developers are using a reasonable architecture, rather than ad-hoc throwing together of technologies)

      To take an MVC view of this, servlets are primarily used for the controller portion of an application. As straight Java code written to a specific interface, they provide a natural linking point between .JSP view components and JavaBean model components. Typical use is one or a few controller servlets, which receive requests from .JSP forms and invoke logical operations in JavaBeans or Enterprise Java Beans. You want to avoid putting VERY much logic into the servlets, instead deferring processing to the business object layer.

      A framework like Struts enforces this by providing you with a pre-packaged controller servlet, which you extend with a combination of classes that are servlet-like and XML to bind 'em all together.

      --
      It was a joke! When you give me that look it was a joke.
  8. hmm... by gyratedotorg · · Score: 5, Insightful

    instead of "why cgi is evil," maybe this article should have been named "why you should buy our product."

    --
    Gyrate Dot Org - "Where high-tech meets low-life"
  9. This is a press release by legLess · · Score: 5, Insightful

    Notice how the author compares CGI unfavorably with something he calls DMF? Here it is, and it looks like one of the flagship products of this company. Imagine that.

    He's setting up a straw man, then claiming that his own (proprietary, for-profit ... not that there's anything wrong with that) solution is better. When he says "CGI" he's talking about something that few people use for anything but toys. Slashdot (e.g.) uses the Perl CGI module, but runs it under mod_perl, thus obviating most of his arguments (CGI is slow, must be compiled at run-time, and has no access to the web server internals). Slashdot, again, uses a templating system, thus taking care of his second argument (programmers must copy-paste HTML into their code).

    Both these problems have been solved for over 5 years, yet he's trying to make it sound like his beautiful DMF is the first to even discover them. *Yawn* - another press release day on /.

    --
    This isn't as much "normalization" as it is "don't take so many drugs when you're designing tables."
    1. Re:This is a press release by shadowpuppy · · Score: 1

      Yeah.. But CGI is EVIL. at least without a decent templating system. And I'm not that big a fan of the source code in HTML model used by things like PHP. Where I work we use XML and XSLT to seperate content , machanics, and formatting. It's enough to make web progamming sexy. Not as sexy as low level bit twiddling but hey what is? Oh yeah.... low level bit twiddling with girls (either context works).

    2. Re:This is a press release by Anonymous Coward · · Score: 0

      Your post seems irrelevant. The author isn't comparing his DMF to perl, Java, PHP, etc. He's talking about CGI in the context of the GoAhead WebServer.

  10. Bunk! by HRbnjR · · Score: 4, Insightful

    This is bunk! Pure FUD!

    CGI is slower?? I write CGI in C++. Compiled C++ is fast. It's on par with interpreted Perl or PHP execution speed at the very least... more likely vastly faster. And this myth about process spawn time is starting to bother me. Linux can spawn processes VERY fast. Threads on Linux have traditionally been implemented as a special form of process anyhow. And even if this was a problem...the author mentions the solution, FastCGI - but seems to somehow ignore that it obliviates his whole point!

    What people really like to ignore when developing on Windows is COM, Apartment Threading, and the whole process model. When you call a COM object in an ASP page or whatever, you are crossing process boundaries - all arguments are martialled through COM by VALUE. All these ASP programmers that create a COM object to use, for example, MSXML have obviously never tried creating a LARGE DOM tree. Let me tell you, it does NOT scale. Compiling all my code into a single CGI allows me to keep everything in the same process space, and vastly improves performance when things get large.

    And who the hell debugs using printf? For one, I like CGI because it's easy to launch one directly from GDB! Ever tried attaching a debugger to a thread for your process inside a web server? HA! GDB lets me easily script the piping of a file to stdin of my CGI. If you are still using printf, you have more problems in learning about programming than will be solved by not using CGI.

    Now, if your application is heavily template based, then yes, PHP definitely makes more sense than CGI!!! The other has a point in that you shouldn't be embedding HTML in your C code. Which brings me to my last beef...

    Their product is about using pre written features rather than writing them yourself as you need to with CGI? Uh, DUH!! There are like umpteen billion CGI LIBRARIES out there!!! I happen to like GNU CGICC. It does everything, form uploading (mime and file uploads too), cookie handling, templating, etc - and it works with FastCGI too! Write it yourself??? As if! And I have no problem linking in libraries for database access, and everything else under the sun (Boost, etc) into my CGI, just like I would link them into any other program. Who the hell writes software without using any libraries?

    This article is basically a bunch of FUD just to sell their product. You can safely ignore the whole thing!

    1. Re:Bunk! by Slorf · · Score: 2, Interesting

      Agreed, totally bunk. If you're actually doing what they suggest, cutting and pasting blocks of someone else's html into your code and/or mixing static pages and code sections, then yeah, you might be inefficient. However, most intelligent CGI programmers will write functions/methods to output the majority of the content, and then supply the data to those functions. If you write your presentation code in this manner, you can put it in a library and call that function again and again from different programs to get a consistent look and feel.

      Of course, as the previous poster implies, there are a lot of pre-written libraries out there as well, and not only in C but in Perl, Python, Ruby, and every other langauge that someone has used for building CGI programs. Templating is fine for those who really need to separate the presentation from the business logic, but if you're doing both parts it is far easier to maintain one pure CGI code base that handles the presentation through well thought out functions.

    2. Re:Bunk! by Anonymous Coward · · Score: 0

      geez, who the hell would use Perl, Python, or Ruby on an embedded system? You completely missed the point of the article.

    3. Re:Bunk! by torpor · · Score: 1

      ... and as for you, if you don't understand why using Python in an embedded system might be a good thing ...

      --
      ; -- the corruption of government starts with its secrets. a truly free people keep no secrets. --
    4. Re:Bunk! by Anonymous Coward · · Score: 1

      "And who the hell debugs using printf? For one, I like CGI because it's easy to launch one directly from GDB! Ever tried attaching a debugger to a thread for your process inside a web server? HA! GDB lets me easily script the piping of a file to stdin of my CGI. If you are still using printf, you have more problems in learning about programming than will be solved by not using CGI."

      Excuse me while I laugh.

      Smart developers use any tool availible to them. Printf is highly useful for debugging. If you don't realize how it can be useful, then perhaps you should pick up a copy of an introductory programming text.

    5. Re:Bunk! by SiMac · · Score: 1

      I doubt it's much faster than mod_perl. Mod_perl can be set to compile once at server startup, then run many times. In addition, it has no fork time at all, another benefit.

      PHP has to compile every time, so it's slightly slower, but you can do neat things like use persistent MySQL across all sorts of scripts.

      Perhaps some of this can be fixed with FastCGI, although Perl and PHP are (IMHO) much easier to learn and write. In addition, I'll bet there's a large enough IPC overhead to make this FastCGI with C/C++ less attractive than mod_perl or PHP.

    6. Re:Bunk! by Pseudonym · · Score: 1

      Didn't you read it? He writes his CGI in C++, so of course he doesn't debug using printf(). Clearly using iostreams is a far superior solution for his application.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  11. CGI != c code by zelphi · · Score: 1

    It seems like the author thinks the majority of CGI apps are written in C.

    ...when the complexity of the response grows, the C programmer is forced to emit complex blocks of HTML from C code... Requiring that the interface be generated by C code also removes the possibility of replacing or updating the web interface in the field without replacing the entire binary image of the server
    On cgi.resourceindex.com, there are 2933 Perl scripts and 165 C and C++ scripts combined.

    This would seem to disprove his point that the "binary image" on the server must be replaced every time one wants to edit the html...
    1. Re:CGI != c code by Anonymous Coward · · Score: 0

      It seems like the author thinks the majority of CGI apps are written in C

      Obviously you didn't read the article. The author is referring to the use of CGI with something called the GoAhead WebServer. He's not talking about the perl script for web sites.

      GoAhead WebServer is a server for embedded systems, and most embedded products are written in C.

      In case you never noticed, HTTP _is_ used for things other than web sites. And no, C is not obsolete.

  12. embedded systems by Anonymous Coward · · Score: 0

    Proof once again that CS > EE.

    1. Re:embedded systems by Anonymous Coward · · Score: 0

      "CS > EE"

      Does that represent bad ideas passing from Computer Science to Electrical Engineering?

  13. Lowercase middle names by Anonymous Coward · · Score: 0

    I've read the ad, it's lame but I'm wondering what kind of person publishes with a lower case middle name? ( Brett g Porter ), that just seems a little too clickish..

  14. First argument doesn't stand up by darkpurpleblob · · Score: 1
    The author argues:
    The first difficulty encountered when programming CGI applications is the practice of "web programming by printf."
    and claims either the server-side programmer needs expertise in HTML, or blocks of HTML produced by a designed need to be copy and pasted into the C code.

    Has the author never had never heard of templating systems? The issue here lies with the architecture and design of the application itself, and not the use of CGI. You surely don't write your Java servlets using out.println(), do you?

    1. Re:First argument doesn't stand up by Khalidz0r · · Score: 1

      I do :]

      --
      "What you 'seek' is what you get!"
    2. Re:First argument doesn't stand up by Anonymous Coward · · Score: 0

      Read the article before you post. The author is talking about embedded systems. For those who have no clue, there are no templating systems for web apps in the embedded world.

      Actually, this is a really useful article.

    3. Re:First argument doesn't stand up by darkpurpleblob · · Score: 2, Interesting
      Fair enough, I didn't reread the title when I viewed the article - would have helped if the full title, "Why CGI is Evil (in the context of embedded systems)" was given in the /. posting.

      I know nothing about programming embedded systems, but surely you could devise and use a very basic/simple templating system in embedded devices. Could anyone out there with experience in programming embedded devices fill me in?

  15. Hey man ... by torpor · · Score: 5, Funny

    ... back off printf();

    I'm with you on everything else though bro'!

    --
    ; -- the corruption of government starts with its secrets. a truly free people keep no secrets. --
  16. useful in the embedded systems context by JimCricket · · Score: 1, Informative

    When you consider that all (or most) web servers in the embedded systems market are currently using CGI, the author's article is quite brilliant. Remember, the embedded systems world is about 5 years behind the traditional "web development" world. The embedded guys are using many of the same technologies but for completely different purposes. For example, it looks like Art & Logic is also using XML-RPC and SOAP, but in a completely different context than most of us are used to.

  17. printf("I disagree"); by Hanji · · Score: 1

    int main(int argc, char ** argv)
    {
    printf("I disagree.\n");
    printf("CGI is great - ");
    printf("I don't see why anyone doesn't like");
    printf("writing web pages like this!\n");
    printf("CGI all the way!\n\n");
    return 0;
    }

    --
    A Minesweeper clone that doesn't suck
    1. Re:printf("I disagree"); by Anonymous Coward · · Score: 0
      #include <stdio.h>

      int main(int argc, char **argv)
      {
      printf("Content-type: text/plain\n\n"
      "I disagree\n"
      "CGI is great - "
      "I don't see why anyone doesn't like"
      "writing web pages like this!\n"
      "CGI all the way!\n\n");

      return 0;
      }
      Fixed.
  18. I'm a php fan by AssFace · · Score: 1

    I've written jsp, asp, php, cold fusion, perl, vb, and even the slightly less used shtml and of all of them, I much prefer php.

    I love perl for many things, but in terms of web page development, I can't stand it - I'd much rather have it running in the background updating files or databases and then have a frontend script like one of the **Ps come in and get the data and make it all purdy.

    JSP is retarded slow until the first time it has been loaded - which is all fine on a live system that precompiles at bootup (that always is blazing fast... right) - but for development, it could be a major pain in the ass - esp if you had anything remotely complicated in there.
    It is excellent to write in and I like that part, I just don't feel that the performance and ease of use are high enough over the others to merit me using it on any of the most recent projects that I've been doing.

    ASP is nice and relatively fast. It *can* run on a *nix system, but really, who are we kidding - it should be under IIS. I have very few complaints about it, but again, if given the choice - I'd rather use PHP.

    PHP is free, fast as hell, and has the best documentation - their site is fast, easy to use, and there is a discussion on the site at the end of each function description that allows you to post up different ways to use the code.
    It is enough like perl that I can flip flop between the two and not get too loopy trying to remember syntax, and yet it allows the easy tag manipulation that the server side scripting languages **Ps are good for.
    Did I mention it was free and retard fast?

    hot damn.

    --

    There are some odd things afoot now, in the Villa Straylight.
    1. Re:I'm a php fan by Anonymous Coward · · Score: 0

      This article is about embedded systems programming. What does PHP have to do with embedded systems programming?

    2. Re:I'm a php fan by AssFace · · Score: 1

      oh sure, like I read the article or something ;)

      --

      There are some odd things afoot now, in the Villa Straylight.
    3. Re:I'm a php fan by GrayCalx · · Score: 1

      This is like a week old now, but I had to give you some applause for your "retard fast" comment. Jesus man thats funny.

      I picture PHP flying past the other languages; running on the tips of its toes; nice shiny new helmet.

  19. On the M$ side of the fence by BladeMelbourne · · Score: 1

    I think there are many times when PHP's print/echo and ASP's Response.Write need to be used. In every project. Functions generate output, and Response.Write sends it to the output stream.

    However I was shocked to use ASP.NET and found that unless ASP compat mode was turned on. to output something to the web page I had to create a label, set the label's text, then add it to the body/form control. Talk about the long way of doing something. It isn't any more flexible. It is much harder to change.

    IO, IO, It's off to work I go, 1 bit in and 1 bit out... IO IO IO IO

  20. cgi's can be run from commandline by TheGratefulNet · · Score: 1

    I frequently run my cgi's from a shell, to debug. first set some env vars (I use the uncgi() routine so vars are coming to me as WWW_foo). then 'dot-slash' the cgi and send the output to /home/httpd/html/test.html or whatever. easy and clean to run and debug.

    plus, cgi's JUST PLAIN WORK. nothing nonstandard, nothing platform-assuming, no browser extensions required, no heavy overhead. they Just Plain Work.

    oh, and they're frequently such 'least common denominator', so they're usually 'lynx-able'. try that with java or jscript code...

    --

    --
    "It is now safe to switch off your computer."
  21. Re:CGI != c code "and do not use Templates" by Camel+Pilot · · Score: 1

    I have not used a print statements to output html directly in years of CGI programming. The use of templates completely obviates the need to use print or printing "here" documents. The article is pure gibberish.

    In fact html in the code is considered sophomoric where I work and is shunned.

    Too bad slashdot does not have a mechanism to rate the article it reviews.

  22. But why does the Linux kernel use so many 'gotos'? by Anonymous Coward · · Score: 0, Troll

    $ grep -R 'goto' /usr/src/linux-2.4.20 | wc -l
    16677
    $

  23. CGI not always runtime compiled or interpereted... by aphor · · Score: 0

    If you want to know how CGI can be made real fast, then lookee here: CGI-lib

    --
    --- Nothing clever here: move along now...
  24. Look at what else this guy has to say... by voodoo1man · · Score: 1

    Scroll down a bit and you'll find a link to another article the guy wrote, about the "the benefits of using XML-RPC and SOAP" (emphasis mine). For god's sake, even if the CGI article wasn't a promotion for his company, anyone who thinks that XML-RPC and SOAP has any kind of benefits really can't be taken too seriously.

    --

    In the great CONS chain of life, you can either be the CAR or be in the CDR.

  25. Re:CGI != c code "and do not use Templates" by perljon · · Score: 1

    Excuse my ignorance, but how do you get the HTML code back to the user?

    --
    This isn't the sig you are looking for... Carry on...
  26. Bloat-A-Tron by Tablizer · · Score: 0, Troll

    If its Java, then you have to do:

    system.utils.writable.writeManager.render.io.pri nt ("I forgot what I wanted to print");

    Just kiddin' guys........half

    1. Re:Bloat-A-Tron by Anonymous Coward · · Score: 0

      More like out.println("Etc");, or even <%= "Text" %> (in JSP). Though, I agree somewhat that the syntax can get out of hand. :)

    2. Re:Bloat-A-Tron by Anonymous Coward · · Score: 0

      Marked "troll" for tellin' the truth? Thanks

  27. CGI is not slow, and mySQL DB connections are fast by daviddennis · · Score: 2, Interesting

    I've been using C-based CGIs for years - once I started doing it and got used to coding everything in C, and developing my own libraries and what-not, it was very difficult to change.

    Seems to me the overhead's pretty low compared to the competition. People argue for things like JSP as more efficient and cleaner than CGI, but I've never seen a JSP web site that's not dog slow.

    When I started reading that opening a database connection had enormous overhead, I got worried that I was really doing something dumb. So I wrote a program to open and close a mySQL database 1000 times and it took a total of 2 seconds. That's 0.002 seconds per open/close combination.

    Then I stopped worrying and went back to work. I'd rather be right in practice and wrong in theory than vice versa.

    D

  28. Re:CGI != c code "and do not use Templates" by Camel+Pilot · · Score: 1

    The cgi application processes a template which consists of replaceable parameters, this template is then sent to standard out - no html exists in the code and the template is viewable and editable using the browser/html editor of your choice. The process is sort of like this

    cgi_app.pl --|
    -----> std_out
    Template.html --|

    There are a variety of template processors out there (at least for Perl and Python far as I know), the one I use and have grown to love is TemplateRex

  29. 1998?? by LadyLucky · · Score: 1

    Seriously, this is some kind of timewarp or something. CGI? People still use that? Holy heck.

    --
    dominionrd.blogspot.com - Restaurants on
  30. C in CGI by weicco · · Score: 0, Flamebait

    Well, C isn't propably the safest language BUT... I really think that people should learn how to write code and "safe" code. All of these nice features to prevent buffer overflows and stuff like that isn't really the answer IMO. I think it's just a great way to procude bad coders (maybe Java coders :P )

    --
    You don't know what you don't know.
  31. Re:CGI != c code "and do not use Templates" by perljon · · Score: 1

    Oh, I see.

    I guess I use a mixture.

    Most of my HTML is a table with some stuff on the top and some stoff on the left. And I have the main body of my page in the bottom right.

    Also, I want to be able to do a lot of stuff in the head, like change the title, or create meta information.

    Therefore, I create my own stuff each time. I can also change the content-type if I need to. Then I create a before template and after template. The before template is the HTML that sits before my main body and the after template sits after it. I could look for a content or something, but by splitting the page up, I avoid having to search for stuff in the page, which saves some time.

    But perl still ends up reading each line of the template in and printing each line of the template out (some lines modified), right?

    --
    This isn't the sig you are looking for... Carry on...
  32. Debugging with printfs by p3d0 · · Score: 4, Insightful
    Actually, sometimes debugging with printfs is much better than gdb. Two situations occur to me:
    • The problem is nondeterministic. If the failure occurs only once in 100 runs, you probably won't see it when you run it in gdb, especially if it's timing-dependent (in which case gdb may stop it from occurring at all). However, with a proper debug trace, you can just grab the log file when the crash does occur, and do a lot of diagnosis from that (plus possibly the core file if you get one of those).
    • The program state and state transitions are too complex. For instance, try to debug a compiler without a good debug trace facility. It's just not very practical to walk complex IR data structures manually after various optimizations have been performed.
    --
    Patrick Doyle
    I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    1. Re:Debugging with printfs by Arandir · · Score: 1

      You forget on situation: when the problem does not occur (goes away) under gdb. This is more frequent than many people realize.

      --
      A Government Is a Body of People, Usually Notably Ungoverned
    2. Re:Debugging with printfs by Karellen · · Score: 1
      I prefer debugging by syslog(3)

      Most of my web cgi code has a fair amount of syslog calls in it for various conditions, all with appropriate severities.

      On live code, I call
      setlogmask(LOG_MASK(LOG_WARNING) | LOG_MASK(LOG_ERR) | ... | LOG_MASK(LOG_EMERG));
      so that only error conditions (like being unable to contact the backend database) get logged. I then have all the live servers forward their logs to a central server, which emails me (via a tiny script I cooked up) each syslog message with a severity of LOG_WARNING or above it gets. This means I get instant notification of web errors in my inbox, which is really handy.

      But for debugging purposes, I can just comment out the initial call to setlogmask(3) on the test server, and run the program in one window while having
      tail -f /var/log/messages | less
      running in another. As soon as the error pops up, I can check the debug syslog messages in the messages file. To remove them *all*, I just put the one setlogmask() call back.

      Really handy.
      --
      Why doesn't the gene pool have a life guard?
    3. Re:Debugging with printfs by p3d0 · · Score: 1

      Not bad, until you try to port your software to Windows. :-)

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    4. Re:Debugging with printfs by Karellen · · Score: 1

      That's what cygwin is for. Alternatively, just write your own setlogmask() and syslog() - they're not too complex - a few #defines, setlogmask() sets bits in a static variable, and syslog() writes to the Windows application event log if the logmask is correct. 100 lines of code, tops.

      --
      Why doesn't the gene pool have a life guard?
  33. Adverts? by Anonymous Coward · · Score: 0

    So, how much does slashdot charge for these adverts then?

  34. Re:But why does the Linux kernel use so many 'goto by aridhol · · Score: 3, Insightful
    When you're initializing a driver, it's generally easier to do something like this:
    int driver_init() {
    if (!init_step_1()) goto error_1;
    if (!init_step_2()) goto error_2;
    if (!init_step_3()) goto error_3;
    return success;
    error_3:
    cleanup_step_2();
    error_2:
    cleanup_step_1();
    error_1:
    return failure;
    }
    Because you can't just exit a failure with half-initialized resources that won't be freed automatically on exit ('cause it won't exit until you shut down).

    Dammit, <ecode> killed my indents. Anybody know how to prevent that?

    --
    I can't say that I don't give a fuck. I've just run out of fuck to give.
  35. Internal Server Error by mikey504 · · Score: 2, Funny

    Premature End of Script Headers

  36. This is an Advertisement! by darkstar101 · · Score: 1

    This is not a news article. It is a corporate advertisement for Art and Logic's Device Management Framework. It basicly says: Don't use CGI, use our product instead.

    Also there are a bunch of inaccuracies in the article. For one, there is no reason the HTML would need to be included in the C code (if you even use C with CGI. I rarely see it). Rather you would just put it in template files that the C code reads in. HTML layout changes would not need to be reflected in the C code.

    Thank God for moderators.

  37. MOD_PERL DUH!!! by A55M0NKEY · · Score: 1
    Apache 1.* forks another process to handle web requests and it is not particularly slow. Apache 2.* uses threads. mod_perl runs under either version I believe. With mason, you aren't even writing cgis anymore either.

    As for IPC, most IPC should be done through a little piece of software called *GASP* a database. If you really need something other than that there are modules ( IPC::Sharable comes to mind ) that make IPC easy. Write a nice wrapper around your use of that and it is not hard - really.

    Purveyors of Application Servers are just marketroids that try to FUD middle managers into telling their programmers to scrap all their perfectly functional and extensible code so they can buy ( for mucho $$ ) a buzzword-compatible 'framework' that their programmers will have to learn. This framework will be closed source and won't do everything you want it to. You will find yourself wanting to change something that you can't.

    "But what's to change? Our framework has modules to speak tons of protocols and zillions of useful utilities." they say

    SO DOES CPAN! and you can look at/change the source of those! I seriously doubt there is a canned Application Server with a 'useful code' library that can compete with CPAN.

    But middle manager types make their careers by taking 'ideas' from salesmen and then taking credit for getting them implemented, so many will find themselves in charge of bigger budgets and get promotions for causing existing code to be reimplemented with an inferior product that locks their companies into spending more money. ( Look at how much money I can spend! Gee that's alot of responsibility. I need a raise or a promotion or something for pissing this much away! )

    --

    Eat at Joe's.

    1. Re:MOD_PERL DUH!!! by will_die · · Score: 1

      SO DOES CPAN! and you can look at/change the source of those! I seriously doubt there is a canned Application Server with a 'useful code' library that can compete with CPAN.
      The developer exchange and cold fusion library for cold fusion comes close, but that only include web based stuff so it looses out to CPAN because it contains alot of stuff that would is not likly to be used in web development.

  38. Re:But why does the Linux kernel use so many 'goto by Anonymous Coward · · Score: 1, Interesting
    For simple cases, this style is at least as good.
    int driver_init()
    {
    if (init_step_1()) {
    if (init_step_2()) {
    if (init_step_3())
    return success;
    }
    cleanup_step_2();
    }
    cleanup_step_1();
    return failure;
    }
  39. Re:But why does the Linux kernel use so many 'goto by aridhol · · Score: 1
    OK, so that works for a three-step initialization. And it manages to obscure the purpose of the code rather nicely.

    Try a twenty-step initialization. Or one that isn't completely linear. You'll learn to appreciate goto.

    --
    I can't say that I don't give a fuck. I've just run out of fuck to give.
  40. Re:But why does the Linux kernel use so many 'goto by Mr.+Slippery · · Score: 3, Insightful
    Because you can't just exit a failure with half-initialized resources that won't be freed automatically on exit ('cause it won't exit until you shut down).
    Right. Basically, well-used C gotos provide the functionality that a try-catch block would in C++. Like many C constructs, they can be dangerous in the hands of the ignorant and elegant in the hands of the wise.
    --
    Tom Swiss | the infamous tms | my blog
    You cannot wash away blood with blood
  41. Re:But why does the Linux kernel use so many 'goto by aridhol · · Score: 1
    Basically, well-used C gotos provide the functionality that a try-catch block would in C++.
    Thank you. I think that's much clearer than my explanation was.
    Like many C constructs, they can be dangerous in the hands of the ignorant and elegant in the hands of the wise.
    I like that. Do you mind if I stick it into my .signature file?
    --
    I can't say that I don't give a fuck. I've just run out of fuck to give.
  42. Re:But why does the Linux kernel use so many 'goto by Anonymous Coward · · Score: 0

    huh? how would you write equivalent code for the driver_init() example using exceptions, without adding some other complexity that wouldn't need exceptions to work?

    I'm not familiar with all the nuances of C++, but it doesn't seem possible using Java-style try-catch.

  43. A C programmer might have to learn HTML?? BFD by Viol8 · · Score: 1

    Its a bit like saying a 747 pilot might have to learn to drive a car to get to and from the airport. The skills to do the latter are virtually inconsequential compared to the skills required by the former so the point is trivial and irrelevant.

  44. [PATCH] Fix Internal Server Error in post by lkaos · · Score: 1

    --- Hanji 2003-02-21 13:40:53.000000000 -0600
    +++ lkaos 2003-02-21 13:40:26.000000000 -0600
    @@ -1,5 +1,6 @@
    int main(int argc, char ** argv)
    {
    +printf("Content-Type: text/plain\n\n");
    printf("I disagree.\n");
    printf("CGI is great - ");
    printf("I don't see why anyone doesn't like");

    --
    int func(int a);
    func((b += 3, b));