Slashdot Mirror


When a CGI Script is the Most Elegant Solution

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

17 of 256 comments (clear)

  1. When is a CGI script the most elegant solution? by Anonymous Coward · · Score: 5, Insightful

    When everything else is not.

  2. Easier than Networking! by MattPat · · Score: 5, Insightful

    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.

    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.

    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.

    1. Re:Easier than Networking! by MattPat · · Score: 5, Insightful

      You start out saying, oh, we will only support browser X...but it never sticks...and your regression testing grows geometrically with each browser and version of browser you support.

      Honestly, as a web developer, I've never quite understood this. Whenever I design a website, it'll often look different in multiple browsers (read: it'll be effed up in Internet Explorer), but unless I use a particularly fancy bit of JavaScript, they almost always functionally work the same in multiple browsers. I just don't get it... are the people who are writing the web apps really that bad with their concept of standards? Are they relying on browser bugs to do a job? Or are they just getting way too cutesy with their JavaScript? Should someone give them a dictionary open to the word "testing"? It just seems to me to be silly not to spend five extra minutes per browser to open your app up in IE, Firefox, Safari (if Macs will be using the app), and Opera (which is pretty guaranteed to work if Firefox and/or Safari does).

      Other than that, though, I agree with what you're saying, in many cases it looks like a full-blown app would be the best solution. I was thinking along the lines of quick fixes that were easily expandable, though, which in my mind is best for web app.

      But hey, in computers there's no wrong way to do anything, right? You just need to gauge which method will make your users swear the least. ;)

    2. Re:Easier than Networking! by skoaldipper · · Score: 4, Insightful

      You are exactly right. When other business competitors (to us) were developing elaborate GUI based alternatives to our browser portal, our clients (and theirs) migrated to our platform instead. Which Industry? The Insurance companies - Progressive, Infinity, State Farm, etc. It was a perfect match for all their agents distributed across the nation (and who weren't even located on those companies premises). For heavy form processing, the browser already provided the interface - the backend delivery system we developed was a snap. And this was over a decade ago, long before distribution across the internet - just using their intranets. The biggest bonus from this GUI switch to browser? Maintenance - by far. Feature changes (like menu arrangements or additions) a close second.

      --
      I hope, when they die, cartoon characters have to answer for their sins.
    3. Re:Easier than Networking! by AmazingRuss · · Score: 4, Insightful

      "unless I use a particularly fancy bit of JavaScript, they almost always functionally work the same in multiple browsers. "

      But which bits of java script are fancy and which are not? And how often is almost always? It comes back to pushing stuff out on the server and crossing your fingers...and there is plenty of that inherent in development without your two qualifications. I guess I'm kind of anal, but, dammit, when I write a line of code I want it to do the same thing for everybody that runs it. That way I can focus my attention my own boneheaded mistakes.

      " I was thinking along the lines of quick fixes that were easily expandable, though, which in my mind is best for web app."

      Quick fixes that are easy expanded tend to grow into gigantic morasses of tacked on code with no toplevel design. In 20 years, the poor churl that has to deal with that monster will be damning you to the fiery depths of hell!

    4. Re:Easier than Networking! by plams · · Score: 4, Informative

      "But which bits of java script are fancy and which are not?"

      This is actually quite easy. Stuff that relates to the DOM often differ from browser to browser while the core language does not. This is somewhat similar to the fact that you can compile and link ANSI-compliant C on virtually any platform as long as you don't do anything platform specific.

      At work I recently developed a JavaScript framework for calculating text length that had to take variable character widths and hyphenation into account. The idea is that the user can type away in a standard TEXTAREA field and know when some predefined text area in a PDF document is full. I think the code ended up as 500+ lines of JavaScript code, but the ONLY browser specific problem I ran into was a subtle difference in the parsing of arrays; Firefox would treat the statement [1,2,3,4,] as an array with the length of 4, while Internet Explorer would say the length was instead 5 (and the last value was "undefined", if I recall). I gather that the reason why browser independence came so painlessly was that 95% of the code was just text processing and number crunching anyway. I doubt I'd have the same luck if I tried to do a WYSIWYG editor since it would have a great more interaction with the DOM.

  3. When the web apps are taking over ... by Gopal.V · · Score: 4, Interesting

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

  4. Another issue by fyngyrz · · Score: 4, Insightful

    One of the issues that concerns me is what essentially amounts to hijacking of my processing resources. One example is animated ads. It takes CPU power to continually flip a large ad's frames; that's *my* CPU power. So I don't let flash or animated GIFs run unless I make an exception. Same thing applies, for instance, to the difference between slashdot and digg. Slashdot provides a static page. I can load it, and the fact that it is loaded costs me nothing in particular. If I flip away from the browser, it doesn't chew CPU time. But if I load a digg page, my CPU is pegged for a while, especially with large pages, because digg is bloated, slow-as-hell pigware that uses *my* CPU to display and organize its content. Guess how much time I spend there. :)

    As I generally have other things going in the background, I don't take kindly to profligate use of my resources; animations, pigware, etc. I keep my eyes open, and I tend to spend time on places that more resemble slashdot than digg in this regard. I *will* bite if the site offers something that overcomes my urge to keep my cycles for myself, but that is a conscious value judgement, not an accident.

    Generally speaking, there's another advantage for sites that produce HTML and CGI forms, and do not depend upon the user's computing environment, and that is broad compatibility. If you stick to the basics, then the broadest set of browsers will function with your "stuff." No Java, no PDF, no flash... just the basics. You can make beautiful, functional websites (assuming you've the art skills) with the basics. I see no need for more; the value is in the content, and it isn't like you can't make a good presentation. The first thing I think when I run into a morass of Java, etc., is "incompetent."

    But that's just me. :)

    --
    I've fallen off your lawn, and I can't get up.
  5. Re:Ugh by beavis88 · · Score: 4, Insightful

    None of those are problems with web apps, they're problems with the decisions the companies made in developing said web apps.

  6. Re:You web developers... by mabu · · Score: 4, Insightful

    Real programming basically died in the mid 1990s.

  7. I don't understand! Help me? by Anonymous Coward · · Score: 5, Insightful

    I don't understand either the problem space, or the solution. I've read the article twice -- though it is apparent by most of the comments that people have not read the article.

    It sounds like the author is recommending a single instance web server application running on a local machine that uses a file store instead of a database and CGI as the programming interface. (In other words, this is NOT an intranet application for multiple users!) Doesn't sound that simple at all. In order to do this, you must:

    - Know at least one programming language for CGI.
    - Know HTML including forms, postback and session.
    - Understand the limitations of web browser UI elements. (There are many.)
    - Install and maintain a webserver on your local machine.
    - Build a robust file store interface. (Even loading / saving / parsing XML files with backups takes time...)
    - Install and maintain permissions for the file store.
    - And more...

    Sounds like all of the disadvantages of the web with none of the advantages.

    Why would you not use PERL and CSV IN/OUT files for simple (or complex) command line processing -- and if you needed a really simple UI, then Excel with Visual Basic. (This isn't easy, but it's a lot less technology to learn and maintain.) Anything more complex: Java, the free version of Microsoft VS or xcode. Anything worth doing is worth doing well.

  8. Re:perl? by cxreg · · Score: 4, Interesting

    "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

  9. Re:You web developers... by skrolle2 · · Score: 5, Funny

    You're just jealous because our stuff actually is used by a lot of people, whereas your toaster-controller, written in C, with a user-interface noone understands only got five downloads from Tucows. And one of them was your cat jumping up on your keyboard.

  10. Those who fail to understand GUI apps.. by Junta · · Score: 4, Insightful

    Are doomed to reinvent them, poorly, in a web browser.

    The premise of the article is that a local application written to target a local server with web browser client is better, but then goes on to say essentially 'ok, here are all the pain in the ass things to overcome when trying to scale it down to a single user compared to typical web server environments'. In his article, he is trading one perceived pain in the ass set of things for another. The unstated stuff is you are requiring the unmentioned user to first have a webserver and CGI environment set up correctly before even beginning to run your app (since the aim is to be standalone on a box, the user's system is the server). He mentions some shortcuts you can take by assuming some network security things and no DB, but in the end the shortcuts are still more work than simple GUI apps for the equivalent task.

    As to his fear of GUI toolkits, it's actually mostly silly. He sums it up by saying web browsers don't make you deal with 'resize events, window expose events, or menu events', but the truth is for a GUI application of the complexity he speaks of, GUI toolkits largely don't *make* you, they *let* you. If your application is as simple as what he prescribes, you can ignore that whole functionality of the toolkit. Sure you have to connect events to widgets of interest (i.e. buttons), but you have to do the exact same thing on webapps, but with different wording. If your application has some reason to start messing with the sort of stuff he fears dealing with and is implemented in a browser, a whole lot of pain is in store for you with obscure, platform specific javascript aplenty. Similarly, he mentions file opening/saving, and font management, but again, the toolkit usually has user-wide settings you can ignore the existence of just like a browser for font and style, and evoking the Toolkit standard filebrowser is usually exceedingly simple (along the lines of filename=Chooser() (not a specific language/toolkit)).

    I have dealt with quite a few 'webapp-for-everything' people, generally they make web apps with an exceptionally clunky interface that responds poorly (I actually dislike Gmail's interface, but Zimbra was impressive, but still sluggish). If I find myself using it frequently and I can find out what it is frontending (usually a database for general apps, imap for mail, etc), then I write a quick GUI application or use a standard standalone app to do the same thing. I end up with a smoother interface that lets me be more productive, and often things run faster (webapp deployments are frequently the bottleneck, the backend could service far more than the webapp can push through for whatever reason). Whenever I do that and someone glances me interfacing with a system notoriously annoying in interface, they always want my application. Again, good Webapps can be on par with GUI apps, but for all the reasons the guy mentions, webapp developers mostly think implementing everything as simple forms is the way to go and that sucks for a lot of usage. GUI apps of course can be written piss-poor as well, but the typical GUI toolkit primitives are richer than simple HTML forms.

    The only potential thing depending on how the app manages data and how it could be useful is the issue of scaling out/up. With a standalone GUI app, the barrier to running it remotely and having all your data in one place is higher than webapps (if running it remotely, must have X/RDP/VNC client installed on your random client which is less likely than a browser, if just having the data remote, still have to get the data accessible via some means and your client must have your software). This is a hard thing to define concretely, but the implementor should be able to make this determination fairly easily.

    --
    XML is like violence. If it doesn't solve the problem, use more.
  11. Re:descover? by 1u3hr · · Score: 4, Funny

    Their main function is to think of the "from the ... dept." line. Doing a spellcheck or other mundane editing tasks would distract them from that.

  12. Re:Here's what happens a month later... by Anonymous Coward · · Score: 5, Funny

    ...and then you would be right to say,

    if (you == inHouseProgrammer)

    "Well you cocksuckers should have told me all this shit up front so I didn't waste my weekend writing a useless web app. If you want it fixed, do it yourself"

    else if (you == consultant && you == chargingTimeAndMaterials)

    "I'll be happy to add those new requirements for you, but I'm afraid that's going to impact the schedule."

    else if (you == consultant && you == chargingFixedFee)

    "Thanks for the feedback, bit I'm afraid we will have to address those new requirements in a follow-on contract."

  13. Re:Ugh by pjt33 · · Score: 4, Informative

    The only solution is to write a new internet protocol (not HTTP) designed specifically to run apps from a server...
    You mean like X?