Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Programming IT Technology

When a CGI Script is the Most Elegant Solution 256

An anonymous reader writes "Writing local Web applications can be quick, easy, and efficient for solving specific Intranet problems. Learn why a Web browser is sometimes a better interface than a GUI application and why experienced Web developers find themselves struggling to learn a GUI toolkit, and descover that a simple CGI script would serve their needs perfectly well, if not better."
This discussion has been archived. No new comments can be posted.

When a CGI Script is the Most Elegant Solution

Comments Filter:
  • by Gopal.V ( 532678 ) on Sunday March 04, 2007 @01:14PM (#18227394) Homepage Journal

    A lot of people are replacing client-server apps with browser based apps, with zero install hassles - which this particular example doesn't really have. But learning to build html apps in CGI mode is easier than re-learning event loops for GTK land (even in perl).

    Of course, debugging in-browser apps is getting easier with firebug [getfirebug.com] and other developer oriented firefox bits. Now, whether the app is built using perl-CGI, mod_perl, php, ruby on rails, even servlets doesn't matter - the UI can actually work very well. For instance my sudoku [dotgnu.info], in fact looks better in HTML than if I (let me repeat, if *I*) had done it with GTK or MFC.

    And CGI still hasn't lost its edge totally. There are places when you *have* to use CGI to do what you want. I ran into one case when I couldn't use php when I wanted to server pushes [dotgnu.info] on a live connection. Instead of firing multiple requests to the server, I hold the connection and push data when it comes available - sort of stateful connections reinvented for HTTP. Which has definite promise when you're building mashups, which fetch data from elsewhere without cross-user leakage (heh, if he can hijack TCP, I don't know what...) - flockr [dotgnu.info] for instance uses such a script in the backend to feed it data (except I'll be an idiot to post a live CGI script to slashdot).

    CGI ain't quite dead yet ...

  • by dvice_null ( 981029 ) on Sunday March 04, 2007 @01:48PM (#18227712)
    > A web browser is a GUI.

    GUI = Graphical User Interface
    Lynx = Text based web browser

    You were saying... ?
  • Re:perl? (Score:4, Interesting)

    by cxreg ( 44671 ) on Sunday March 04, 2007 @01:58PM (#18227796) Homepage Journal
    "even with mod_perl"? as opposed to what? mod_perl is the most flexible web server technology available on *nix, balancing good performance with a good set of functionality (who can beat CPAN?) it's faster and more scalable than Tomcat, and PHP is simply a joke. about the only true downside is that it's a total memory hog.

    perl CGI, however, is crap as you said
  • by misleb ( 129952 ) on Sunday March 04, 2007 @02:16PM (#18227940)

    Quick web scripts are way easier than developing an application if only for the fact that you don't need to figure out how to use networking in whatever language you'd be working in. Plus, you don't need to "distribute" the application once it's done, and you don't need to provide updates to every user on your network who's using it: update your script, update the application.


    What's funny though is that the example in the article was neither networked nor multiuser. Why not skip the CGI part even and just have commandline scripts to do certain things? I can't say I've ever really consider writing a simple, single-user one-off GUI application. Nor can I think of a time where I'd want a personal web server listening on a local IP/port.

    Plus, developers think in program logic, not in program design. A web script let's the developer write their output in HTML, then go back in later and add some CSS for presentation once they've got the program actually working. I say, it's a good way to do things.


    No, developers think in program design. *Programmers* things in program logic. :-)

    Not to mention that a lot of web scripting languages are easier to use than full-blown application languages, and there are many packages that let you attach native GUIs to web scripts. There isn't a compelling argument not to go that route if your application a) uses networking, and b) is distributed over an intranet.


    But if it doesn't do a or b (as in the article), Perl/Tk is probably simpler than even bothering with a web server. That is assuming that a GUI is even important at all.

    -matthew

     
  • by Bozzio ( 183974 ) on Sunday March 04, 2007 @02:24PM (#18228004)
    I think major compatibility issues always have to do with the very basic ways the different browsers handle javascript and event. A GREAT example is if you ever have to write somecode for when a page unloads. It'll work fine in IE, Safari, and Firefox, but good luck getting it to work on Opera. I spent hours trying to figure out why onunload didn't work on Opera... apparently it's a "feature!"

    Anyway, whenever I've had problems with script compatibility it's ALWAYS been with event hooks, and with very basic interpretation differences in javascript between browsers. And let me tell you, getting these scripts to work is a LOT more than 5 minutes per browsers. Sometimes you'll need to write an extra 200 lines of script just to get the same feature in all browsers.

    It's not as simple as you made it seem.
  • by misleb ( 129952 ) on Sunday March 04, 2007 @02:37PM (#18228106)

    Yes, I often do use a web browser as a script GUI. A web browser changes a few HTML text strings into a pretty display.


    If it is only a few lines, it probably isn't 'pretty.' It is probably just a plain, small form centered in an oversized browser window. Personally I find things like PerlTk to be much "prettier" if only because the window is taylored to the app. And also the box model of Tk is MUCH easier to work with than HTML/CSS. I find reliably placing elements on the screen with HTML/CSS to be a huge pain in the ass.... and I'm primarily a web developer! ;-P

    -matthew
  • by PatPending ( 953482 ) on Sunday March 04, 2007 @03:00PM (#18228322)
    I use Perl/CGI/Apache2/MySQL for proof-of-concept/fast-prototyping--which usually takes one to two days (or weeks). Once the functionality, testing, and etc. is done, I send the specifications and the URL to another department. Then I wait for one to two months for them to come back with a Windows .NET program (usually written in C# or VB) using MS SQL Server. During that time my co-workers continue to use my web-based stuff. (BTW, this is in a corporate environment with annual revenues of about four billion dollars and 5,000 employees.)
  • What about PHP? (Score:1, Interesting)

    by praseodym ( 813457 ) on Sunday March 04, 2007 @04:22PM (#18229010) Homepage
    PHP is a very simple language as well and not overkill for simple tasks. How can it be compared to CGI? Does it have any real disadvantages? Advantages are clear: many developers are better at writing PHP than at writing Perl and PHP is nowadays more widespread on servers than CGI.
  • by Anonymous Coward on Sunday March 04, 2007 @08:18PM (#18231662)

    So we have slow, bloated, IE6-only web apps. Hey, its easy to deploy. Has the users cursing non-stop and wanting us dead. But its easy to deploy!

    So you're expressing a preference for non-web apps based on the fact that the people who wrote your company's web app are incompetent? What the hell makes you think they'd have done a better job with whatever other toolkit they used, especially keeping in mind that both of those you mentioned would simply give them vastly more opportunity to seriously screw things up?

    If you've never used a properly designed and written web app (and from the tone of your comment, I'd guess not) you have no idea just how well they can work. Not everybody loves using them, but my experience with replacing non-web internal apps with web-based ones has been that the majority of people much prefer the web-based app. And if the developers of the software are clueless... well, no toolkit in the world is going to save them.

  • by totally bogus dude ( 1040246 ) on Sunday March 04, 2007 @08:59PM (#18232060)

    If you're going C++ for performance reasons, take a look at tntnet [tntnet.org]. It's a web application framework in C++, and provides sessions, thread-safe operations, and things like database connection pooling. You can even create web pages with C++ embedded right in, similar to e.g. PHP or ASP. And it's fast.

  • Re:Preach it, brutha (Score:4, Interesting)

    by Blakey Rat ( 99501 ) on Monday March 05, 2007 @01:06AM (#18233964)
    The problem isn't one of marketing (well, ok, that's part of it), but of ease of use.

    Remember, if you have a feature that people can't figure out how to use, for all practical purposes that feature does not exist.

    If you want to make X popular, first of all give it a decent name. Secondly, write an extension to Firefox so that a specially-tagged HTML page can call an X application over the Internet to run it. Add in all the bells and whistles I described in the grandparent post, and bam, you have a winner... assuming you can make it work without requiring gobs of Linux knowledge like it does now. Now when I visit Gmail, Google can put up a highly interactive email client which lets me drag&drop a file into the email window to add an attachment, and I'm happier and Google's happier and Firefox has a huge selling point.

    From what I understand, though, X isn't suited for this for a couple reasons:
    1) It's designed to run an entire desktop over the network link, not just one single application. i.e. you define a rectangle as "the desktop" and all windows/etc that X opened would have to be contained in it... that's not ideal.
    2) It's bandwidth-heavy. Maybe not when competing with Citrix, but if Google started using it they would see their bandwidth bill skyrocket.
    3) X doesn't solve the problem of native widgets. X applications run in OS X look like crap because the widgets are simple greyscale things that look like they were rejected from Windows 95, and not the nice-looking OS X buttons and widgets. Additionally, X applications in OS X still can't accept drag&drop, or use the OS X spell checker, or communicate with other apps, etc etc.

    If it's going to happen, I think a new protocol needs to come forth. Perhaps something that transmits VB-like "forms" to the client on demand, and the "forms" can contain scripting in Python to accomplish the task, with a network protocol to stream-in new "forms" as needed and to interface with a remote ODBC connection through this psuedo-app. You could design the "forms" to take up minimal bandwidth and use native widgets by giving instructions like "draw a pushbutton with a label 'hello' at this coords" instead of sending bitmaps (like X does.) You'd also be able to script a form to modify itself to some extent, so you wouldn't need to make a round-trip to the server every time you hit a disclosure triangle.

    If anybody builds this, put my name in the credits. ;)

The key elements in human thinking are not numbers but labels of fuzzy sets. -- L. Zadeh

Working...