Let me say I'm sort of a convert to CGI done with Pascal, largely on the strength of Wanderlan's ExtPascal project (
http://code.google.com/p/extpascal/).
The only advantages I can see in working with a scripting language like PHP is that it's generally easier to deploy. Many ISP's, employers and "free" Web hosting services don't permit access to the cgi-bin folder on their servers. While this doesn't affect your development locally on your own computer, it might be a nuisance later to discover that your existing Web site won't do, meaning a change in URL and a small expense for a paid service could be necessary.
The other advantage to PHP, etc. is that when deploying you don't have to worry about what OS the server is running, whereas with CGI you'll have to compile for a specific OS target, typically Linux.
It might be useful if forum readers could post URL's of inexpensive Web hosting services that permit CGI apps which could be used for demo purpose and testing the deployment of CGI apps.
With ExtPascal, I think we have a CGI approach that represents one of those watershed or breakthrough moments. At its heart is the commercial, dual licensed Ext JS, which is one of the most popular and most attractive looking JavaScript Web widgetsets available. What do I mean by a "JavaScript Web widgetset"? Generally this means a set of visual classes written in JavaScript that are sent as source code to your browser by the Web server. These classes implement the buttons and other controls that you program and that the user interacts with in the browser. Since JavaScript is sent as source code, the .js files are usually pretty unreadable since all white space has been stripped out to shrink the files. However, Ext JS includes "debug" versions that, while not documented, at least include whitespace and line breaks and can be read as normal source files.
I'm glad Ext JS is commerical. This means it's not going to just disappear or fade into uselessness like to so many open source efforts.
I also like the way that there isn't really much code supplied with ExtPascal. All the Pascal wrapper classes for the Ext JS widgets (TExtWindow, TExtButton, etc.) are auto-generated. This is really a great idea because it means that there's so much less source that has to be maintained. Wanderlan's code generator (that you run just once to create the wrapper class source files) is only a few thousand lines of code.
The ExtPascal wrapper classes also emit almost all of the JavaScript, so you don't have to write much JavaScript yourself, although you can if you want. For example, when you instantiate a TExtButton class and set some of its properties, at runtime this results in a big JavaScript "new" constructor that actually creates the JS object. In addition to the base widgetset .js files that are sent when the page is first loaded, the browser will also receive this JavaScript that's created on the fly.
Probably the only thing missing from ExtPascal is a visual designer. Right now, that's probably an advantage of a product like Delphi for PHP. Not only does it have a VCL for PHP class library (PHP classes that wrap the underlying qooxdoo JavaScript widgetset similar to the way ExtPascal wraps Ext JS), it also has a visual form designer that will be familiar to any Delphi or Lazarus user. However, that's where the similarities to Delphi and Lazarus end. Once you start coding in Delphi for PHP you realize quickly that you're in a different world. Not only are you writing both PHP and JavaScript code, but you're putting the code in the same file. The PHP code you write is only executed on the server and the JavaScript code you write is only executed in the browser, yet they're in the same file. And the order in which they're executed isn't obvious. Looking at the postings on the Delphi for PHP forum shows that this absolutely stumps most developers at first.
Other issues with PHP, etc. that you only run into later include the fact that you can't use your normal debugger with these languages since they're scripting languages. With ExtPascal and Lazarus you just use your normal gdb.
What I've been working on is a set of LCL/VCL-based "design" controls that can be used with Lazarus and Delphi to visually design ExtPascal forms. One of my goals is to write as little code as possible, so the design controls are just wrappers of TCustomForm, TCustomButton, etc. and the source for them is all auto-generated. One of the problems with so many open source projects is the sheer volume of code involved. Many developers seem to be as happy as pigs wallowing in all that code, but at some point, almost by definition, if the project doesn't magically attract other developers and grow and stabilize, it _will_ reach a crisis point when the original author is no longer able to maintain and advance the project. By writing less code, the seriousness of this crisis when it comes can be reduced.
If you haven't tried out ExtPascal, you really should. If you have a Mac, Apache is already pre-installed and all you have to do is turn it on, so there shouldn't be any reason for not at least exploring CGI development with ExtPascal. And if you want to go the next step and install the Lazarus project package and design control package that I threw together, I think you'll be pleasantly surprised at what this adds to ExtPascal:
- Once the project and design control packages have been installed in Lazarus, just choose File | New | ExtPascal Application to create a new ExtPascal project. This immediately gives a structure to your project that should be familiar - that is, it's almost exactly the same as an LCL application. If you look at Wanderlan's ExtPascalSamples.dpr you might be dismayed by its jumbled structure, but this file is really intended as a way to demo and exercise many of the Ext JS widgets, not as an example of how you should structure your projects.
- Designing the ExtPascal forms visually and setting properties means you don't have to know very much about Ext JS. Although Ext JS is well documented (
http://extjs.com/deploy/dev/docs/), this _is_ JavaScript documentation, not Pascal documentation. For example, to set a combo box's items, you'll find in the JS docs that you do this by setting the combo box's "store" array. In Pascal, this would be something like this (from Wanderlan's example):
StoreArray := JSArray('"Shade", "Mostly Shady", "Sun or Shade", "Mostly Sunny", "Sunny"');
However, if you use the TExtFormCombo in Lazarus, you set the StoreArray property in Object Inspector using the familiar strings editor dialog just like you use with TComboBox.
Thanks.
-Phil