In Part II, we'll address the challenges of server-side programming.
In Part
I of this two-part series, we looked at essential skills for client-side Web
development. In this installment, we'll look at server-side programming.
Server-side programming involves writing business logic, database access
logic, validations, and interfaces to the client (usually a browser of some
sort, although with Web services applications, it could be another Web server).
Server-side programming can be done using a variety of development environments
and languages, depending on a number of factors, such as the choice of Web
server middleware, hardware, operating system, and development language. For
example, on the System i, some of the choices are CGI programs that run in the
Apache Web server, PHP running in the Apache Web server with the PHP module
installed, Java servlets, or JavaServer Pages (JSPs) running in WebSphere WAS.
Note that CGI is a protocol, not a language or development tool. Several
tools use CGI as the basis for delivering Web apps, with varying approaches to
implementation of the protocol. These include open-source tools such as CGIDEV2,
commercial "kits" (suites of APIs to make programming in the CGI protocol
easier), and commercial development environments. Most of these exploit RPG as
the primary development/generation language, but it is possible to write
CGI-protocol-based code in most any ILE language, such as Cobol, C, or C++. On
platforms other than the System i, besides PHP and Java-based solutions, you may
encounter CGI scripts, usually written in Perl or early versions of PHP or ASP
.NET, Microsoft's equivalent to JavaServer Pages (JSP), running on IIS,
Microsoft's proprietary Web server.
Another popular server-side Web
technology is Adobe's ColdFusion, originally produced by Allaire. ColdFusion
consists of both a development tool and a deployment environment. It uses its
own server, which sits on top of other Web servers. ColdFusion had a strong
presence in the early days of database-driven Web programming (circa
1999–2000), but its popularity is declining due to the success of PHP,
Microsoft's inroads into the marketplace, and the adoption of Java-based
solutions.
A Comparison
Let's look at the advantages and disadvantages of
some of these approaches.
CGI on System i
Advantages
- CGI is a widely used protocol (on
other platforms besides System i).
- CGI programs written in native ILE languages run extremely efficiently.
- CGI is very easy to deploy.
- CGI programs can be written using familiar languages, such as RPG.
- Many operating system APIs allow extension of RPG capabilities for rich Web
applications.
- Applications can be tightly integrated with operating system functionality
(such as user ID authentication, object-level authority, etc.).
- Free open-source code libraries are available for writing CGI programs (such
as CGIDEV2).
- Several good commercial development tools are available for writing CGI
applications.
Disadvantages
- CGI is not easily ported to
other platforms.
- CGIDEV2 and other free libraries are limited in functionality.
- RPG is not a native Web-development language, so it has limited native Web
functionality.
- RPG is proprietary (not used on any other platform than System i), C is not
ANSI-standard, and CL is proprietary (these are probably the most common
languages used to construct System i–centric Web applications).
PHP
Advantages
- It's easy to install, configure, and
deploy.
- There are no license fees to run open-source versions.
- PHP is easy to start coding in (procedurally written or
object-oriented).
- PHP runs efficiently, even though it's interpreted rather than compiled
(some pseudo-compilation can be done, also).
- It's a widely used language, with lots of Web resources available for
learning it.
- Lots of open-source applications written in PHP are available.
- Many editors are available for writing PHP.
- PHP has cross-platform capability; if you write PHP using MySQL as your
database, for example, it is easy to run it on other servers with no or minimal
code changes.
Disadvantages
- PHP is relatively new on System
i.
- It's interpreted, not compiled. This may mean it doesn't scale as well as
compiled ILE code on the System i.
- Because it's a loosely typed language, it's easy to learn, but that also
makes it more prone to buggy code than strongly typed languages such as Java or
C++.
- It's open source, so there's loose control over the quality of the product,
with many volunteer contributors, compared to commercial software.
JavaServer Pages (JSP)
Advantages
- JSP has a well-designed, formal language specification.
- It offers cross-platform capabilities.
- Several development tools are available for developing Java-centric Web
apps, including the open-source project Eclipse and IBM's WDSc.
- JSP is similar in concept to PHP and ASP.NET, so it's relatively simple
conceptually to work with.
Disadvantages
- Java does not run
well or scale well on System i. Although advocates will tell you otherwise,
there are countless stories of companies having to upgrade their hardware to run
Web applications in WebSphere.
- Some developers maintain that WebSphere is difficult to install, configure,
and tune.
- Java often presents a big learning curve for RPG programmers.
- Java does not fulfill the promise of "write once, run anywhere." It's more
like "write once, test everywhere," which reduces the benefit of being able to
deploy cross-platform.
If you are interested in learning about
J2EE, which is the umbrella technology for Java servlets and JSP (and a lot of
other Java-based technologies), Sun Microsystems has a great Web site for
that.
ASP.NET
Advantages
- ASP.NET has a rich set of controls for
creating Web applications.
- The robust development workbench from Microsoft (Visual Studio) helps to
create ASP.NET applications.
- It's a comprehensive language.
- It's highly scaleable.
- ASP.NET runs on IIS, Microsoft's popular Web server.
- It uses the .NET framework, which supports other languages such as VB, C#,
and J# (Microsoft's answer to Java). You can compare the .NET framework to ILE
on the System i or to the Java Virtual Machine (JVM); each supported .NET
language creates compiled code that runs in the .NET framework and can interact
with programs built in other .NET languages.
- It offers a rich set of tools for tight integration with other Microsoft
products, such as Outlook for emails, calendaring, etc.
Disadvantages
- It requires the Microsoft IIS Web server,
which runs only on Microsoft operating systems.
- The .NET framework has a learning curve associated with
it.
Because ASP.NET runs on a Microsoft platform, why would you
consider it for System i Web development? Well, there are ODBC drivers for
connecting to the System i database, so you can write ASP.NET applications that
access System i data. Organizations that are nervous about exposing their System
i to the Internet sometimes take this approach, although I think this is an
unnecessary concern, given System i's robust security features.
What IBM Could Learn from Microsoft
One area that Microsoft really excels in is its
development tools. There is really no comparison between IBM's tools and
Microsoft's Visual Studio and similar tools. For example, Microsoft's tools are
easy to find on the Microsoft Web site, are easy to install, and are not PC
resource hogs (compared to WDSc, which requires much more memory). And some
developers consider IBM's developer tools to be less intuitive than Microsoft's
tools.
Figure 1: Edit an HTML file with Microsoft's Visual Web Developer 2005
Express Edition. (Click image to enlarge.)
Compared to IBM, Microsoft also does a great job of
promoting its tools. For example, on the
developer's Web site, you can easily download free Express versions of
Microsoft software; just click the Downloads tab. From there, you can download
Visual Web Developer 2005 Express in just three clicks—no forms to fill
in, no email addresses required. Just click and install. Contrast this with
IBM's WDSc page.
IBM would do well to make it easier for developers to figure out how to get a
free trial download.
In addition, Microsoft does a superb job of selling
programming as a fun and exciting pursuit. For example, on that same developer's site, there's a
"Facebook developers kit." Microsoft makes its products relevant and interesting
to the younger crowd. The site is covered with great images, screenshots, video
demos, and more. In contrast, IBM's is... well, dull. No pictures. No videos.
Just the IBM logo and lots of text and links.
What These Approaches All Have in Common
All the solutions I've described use a common Web
programming concept, to one degree or another. The idea of interleaving HTML
with server-side code is quite different from traditional green-screen
programming, where you clearly separate UI design (display file DDS) from
programming logic (RPG code, for example).
This can present a problem in
terms of coding; it makes it difficult to design your screens separately from
your programming logic. Each technology addresses this problem with different
degrees of sophistication. For example, CGIDEV2 uses "sections," which let you
write large chunks of HTML with server-side variables embedded. JSP supports the
use of JavaBeans, which are self-contained objects consisting of both
presentation layout and server-side code. For example, you can easily hook in an
HTML calendar that is created as a bean. The bean draws the calendar on a
designated place on the page. The programmer might set properties for the bean
that control whether or not the current day is highlighted, for example.
Microsoft's ASP.NET supports the same concept. Visual Studio .NET comes with a
suite of pre-built server-side controls that you can easily plug in to your
pages. One of the most powerful is the datagrid. This is like a subfile on
steroids. It produces a scrollable table of values from any SQL select
statement, with resizeable and sortable columns, plus many more features. As a
programmer, you do not need to know the innards of the control—how the
requisite HTML is produced, for example. You simply place the control on your
page using Microsoft's design tool and then set properties for it. Zend also has
something similar, called Zend Frameworks, which includes an object-oriented
library of components written in PHP 5.
Which Approach Should You Choose to Learn Server-Side Technology?
With the advent of strong PHP support on the System
i, it really makes sense to start with PHP:
- It's easy to learn.
- You can use any editing tool: Zend's, NuSphere, Notepad, TextEdit, HTML-Kit
or one of the latest System i–centric rapid development tools from the
System i ISV community.
- You can find tons of code samples on the Web.
- Zend has done a great job of providing functionality that makes it work with
the System i database, using either record-level access or SQL statements.
- The rich set of functions for writing PHP applications are simply not
available in RPG toolsets such as CGIDEV2.
- It's cross-platform capable.
PHP's Object-Oriented Capabilities
Although PHP is typically coded using procedural
coding styles that employ function calls, etc., PHP 5, released in July 2004,
also supports a robust object-oriented coding model. Zend Frameworks is a set of
object-oriented components written in PHP 5 that provide a high degree of Web
functionality that's easy to plug in to your own applications. Having the
ability to write PHP in an object-oriented architecture gives you room to grow
with the language. You can start out learning to code PHP procedurally, using
concepts that are familiar to you, and then eventually move to using an
object-oriented methodology to write more robust and reliable code.
Learning PHP
Literally hundreds of Web sites teach PHP. As I
mentioned in my previous article, W3
Schools is one of my favorite sites, especially for basic introductions to
Web technology. Other sites include PHP.net. A
Google search for "PHP tutorials" returned 808,000 hits! Also, there are many
good books on PHP. One Web site I have found particularly helpful is O'Reilly's
Safari Books Online. This is a
subscription-based site that gives you access to O'Reilly's library of
publications, as well as technology books from other publishers. You get to read
complete online versions of the books. You can also download sections, or buy
hardcopy versions directly from the site. Compared to the comparable cost of the
print versions, the subscription fees are very inexpensive.
Perhaps one
of the major reasons to use PHP is that you can be comfortable knowing that PHP
is a major technology that is here to stay. Investing in PHP training for
yourself or your staff is a long-term value proposition. It's an investment that
you will leverage for years. In addition, PHP is widely taught in colleges and
universities, so finding new talent who can code in PHP is relatively easy
compared to other languages, especially RPG.
Putting It All Together
You will need the skills from both of the articles
in this series in order to write commercial-quality Web applications:
- HTML
for content and layout
- CSS for advanced layout
- JavaScript for client-side scripting
- PHP (or other server-side language) for server-side database access,
business rules, and presentation logic
While this sounds
daunting, it doesn't have to be. Read a couple of books, grab some sample code,
and get going! Web programming is tons of fun, and once you get started on it,
you'll never want to see another green-screen again!
Duncan
Kenzie is President and CTO of BCD Technical Support,
the development and support group for WebSmart,
a popular iSeries Web development tool, and Nexus
Portal, a portal product specifically designed for System
i, iSeries, and AS/400 servers. Duncan has 30 years of experience on the
midrange systems platform creating software for both green-screen and native Web
environments.
|