The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

[web apps] Why use engine over source files?

Hi

I'm learning about how to write web applications, but am a bit in the dark as to why I should use an application engine (whatever the correct term: servlet engine? a server, such as CherryPy for Python that runs the application behind or beside the web server), as opposed to doing what I see in books on PHP (namely, web pages that contain either code or templates using Smarty).

What's the difference? Why should I use one or the other? What application servers are available for PHP?

Thank you.
Fred
Friday, July 28, 2006
 
 
> What application servers are available for PHP? <

PHP does not use an application server, it simply runs under a web server (the most popular being Apache).

You do not *need* templating engines such as Smarty. That is a matter of choice. Personally I use XML and XSL to generate all my HTML, but that is *my* choice and not a requirement.
Tony Marston Send private email
Saturday, July 29, 2006
 
 
The reason why you see application servers behind apache in Python and Ruby is because apache is too slow combined with these languages. PHP runs on apache in a different way that Python and Ruby would, so you don't have that problem and thus not the option of running PHP on an application server.

PHP is going to be fast enough on Apache and the performance of your infrastructure shouldn't be a concern before you begin to consider an IPO due to your wild success :)
Peter Monsson Send private email
Saturday, July 29, 2006
 
 
Tony Marston > Personally I use XML and XSL to generate all my HTML, but that is *my* choice and not a requirement.

Would you happen to have some reading material about using XML/XSL to handle the presentation part vs. using a templating system like Smarty, so I can make an informed choice?

Peter Monsson > The reason why you see application servers behind apache in Python and Ruby is because apache is too slow combined with these languages.

OK, makes sense. But besides performance, I seem to understand that using an application server instead of keeping code in web pages in htdocs is that the former makes programming easier. If you have good experience with PHP, can you comment on this?

I do prefer Python over PHP, but since the latter is available on all hosted sites while Python (and application servers) are pretty rare, I want to make sure going Python is really worth it. All those people still using PHP today can't be wrong, can they? :-)
Fred
Saturday, July 29, 2006
 
 
Fred, a few things:

1. There is absolutely no reason to have all the PHP code and HTML mixed up together in all files. It's easy to separate PHP classes in one set of files and HTML "templates" in other, and then use some presentation code (which can be as simple as include "mytemplate.php") to prepare the output. Tony's approach with XSLT transformations is also valid; it's a difference between Template View and Transform View patterns as described by Martin Fowler.

2. You need to decide what kind of application you're developing. If you aim for an app which is to be installed by the user and you have no control over where and how it will be installed (like a traditional desktop app, or things like WordPress, dotProject or activeCollab when it comes to Web apps), you should go for the lowest common denominator, i.e. a platform that will be easiest to install on the widest array of servers. In that case PHP is an excellent choice (and even PHP4, which is still more in use than the latest version), or perhaps ASP.NET if you are more windows oriented. On the other hand if you write an app that you will have a full control over -- e.g. an internal app for a client that you will continue to support, or a your own service like Basecamp or Google -- then pick the technology you (and your staff) know most about and can be most productive with. Nowadays you can write Web applications (with appropriate application servers, libraries etc) in almost any language you can imagine, from PHP and Python to Java and C++ to Smalltalk and Lisp.

3. Regarding PHP, one caveat. It has somewhat of a "newbie language" reputation, but it is quite a powerful platform when it comes to Web development. You can write complex and sell-designed OOP applications with it (especially with the new features in PHP5, but even version 4 allows for it if you're disciplined). However, it is very easy to also write quick'n'dirty, unmaintainable solutions. PHP is easy to learn but hard to master, although in many cases it makes Web developer's life much easier.
Berislav Lopac Send private email
Sunday, July 30, 2006
 
 
Thx for the feedback.

Berislav Lopac > 1. There is absolutely no reason to have all the PHP code and HTML mixed up together in all files.

Right. I am learning about MVC and checking out different tools to separate data, logic, and view, including Smarty, Savant, and CakePHP. Hopefully, those can be installed even on a shared host, so that I don't have to get my own server at a colo right at the beginning (no problem once the app proves to be successful.)

> 2. You need to decide what kind of application you're developing.

The constraint is web hosting, as I don't want to have to handle my own server(s) at the beginning if I can avoid it. Hence my hesitation between PHP and Python. I prefer the latter combined with an application server, but that would mean installing my own server.

> However, it is very easy to also write quick'n'dirty, unmaintainable solutions.

Yup. What's strange, is that even recent books like "PHP5 Power Programming" show examples that mix code and HTML, like there's nothing wrong with that and there aren't better ways to write apps.
Fred
Sunday, July 30, 2006
 
 
If you're looking for templating libraries, check out my libtemplate, http://www.lazarusid.com/libtemplate.shtml

It doesn't have all of the features of Smarty or some of the others, but that's part of it's strength too.  Templates are bone simple, and you can almost always had the design portion over to a designer who doesn't know PHP.
Clay Dowling Send private email
Sunday, July 30, 2006
 
 
Clay Dowling > If you're looking for templating libraries, check out my libtemplate, http://www.lazarusid.com/libtemplate.shtml

Thanks but... "This tool can be used on nearly any website that allows system executables as CGI programs" : can it be used from PHP on a shared web server?
Fred
Sunday, July 30, 2006
 
 
"The constraint is web hosting, as I don't want to have to handle my own server(s) at the beginning if I can avoid it."

I don't think my point was clear: it's not about how will you use the application initially, it's about whether it will be distributed on servers completely beyond your control. If you have to care only about a single installation of the application, maintained by you and your team, there are still inexpensive dedicated hosting plans where you install whatever you want on a server which is provided by ahosting company (i.e. they care about the infrastructure, you care about the server). In that case you should take such a hosting plan, install Python and whatever you need and go ahead.

If, on the other hand, you will distribute the app (i.e. you client would install it somewhere in the wilds) and want to cover as wide a server base as possible, in that case use PHP with no "exotic" extensions.

"What's strange, is that even recent books like "PHP5 Power Programming" show examples that mix code and HTML, like there's nothing wrong with that and there aren't better ways to write apps."

Well, there *is* nothing wrong with that approach; it's all about what do you want to do. If you're writing a simple Web page with no complex authorization rules, database queries, business logic etc, this approach works just fine. For example, I'm just writing a simple Web site which ca easily be done with plain HTML; but I'm using PHP to simplify inclusion of headers and footers, as well as language selection. This way the site is more maintainable (there is only one file with navigation, instead of one in each HTML site), and easier to set up; I could do absolutely the same with e.g. Dreamweaver templates, but as a server-side guy I find this more comfortable. Of course, this ends up in a lot of PHP throughout my HTML, but proper separation of models, views and controllers would be an overkill in this case.
Berislav Lopac Send private email
Monday, July 31, 2006
 
 
"I don't think my point was clear: it's not about how will you use the application initially, it's about whether it will be distributed on servers completely beyond your control."

A better of way of expressing this is, are you going to sell your application as is, or are you going use your application to exclusively offer a service?

As for the larger engine question, I think the real driving factor is the complexity of the underlying code. Relatively simple data storage and retrieval style applications that perform very little analysis, do just fine without the engine. If you must do a lot analysis before presenting the data, the engine will not only help you organize your code better, it may also...  well, "self-optimize" the code so that it runs better.

Examples: you're writing a program that saves your Little League statistics. After the end of the game, you type in who played, when they hit, whether they get on base, etc etc, and save the info. You don't need an engine for that.

However, if you want to take all that data and perform statistical analysis to the extent that it'll tell you that Bobby Joe does better against left handed pitchers while starting early in the lineup, but terribly if you let him sit on the bench for too long, you'll probably want an engine.

If you plan to offer this tool as a service, you'll want to write it in the language you feel the most comfortable with (Python in this example).  If you want to sell copies of the program so that people have to install their own versions on their own websites, you'll want to write it in the most widely supported language (PHP in this example).
TheDavid
Monday, July 31, 2006
 
 
TheDavid > A better of way of expressing this is, are you going to sell your application as is, or are you going use your application to exclusively offer a service?

As a service. This application won't handle highly sensitive data, so customers won't mind if it's hosted on the web, hence no need to write this as a desktop app. I will however have to investigate HTTPS between client and server, and whether it's possible to encrypt data on the server so that it won't matter if the server is compromised. Since SQLite uses a single file to save its data, this might be a better option than MySQL.

> As for the larger engine question, I think the real driving factor is the complexity of the underlying code.

OK. At first sight, it's not a very complicated app, mostly data entry and then spitting out some reports (stats, graphs).

I'll keep reading and experimenting between PHP and Python, and make a decision. Incidently, hosted virtual servers are much cheaper than dedicated hosted servers, so it looks like using an application server with Python isn't the issue I thought it was. Still, I want to make an informed choice :-)
TheFred
Monday, July 31, 2006
 
 
"Since SQLite uses a single file to save its data, this might be a better option than MySQL."

Make sure you take a look into other options, specifically Firebird and especially PostgreSQL.
Berislav Lopac Send private email
Tuesday, August 01, 2006
 
 
>>Personally I use XML and XSL to generate all my HTML, but that is *my* choice and not a requirement.<<

>Would you happen to have some reading material about using XML/XSL to handle the presentation part vs. using a templating system like Smarty, so I can make an informed choice?<

I do not know of any documentation which compares the various templating engines, just documentation on how I make use of XSL in my framework. The main reason that I chose XSL over Smarty when I began with PHP is that I already knew XSL and knew how powerful it was, so I didn't want to waste my time learning something that was probably less powerful.

I believe I made the right choice as I have been able to construct a set of 10 standard XSL sylesheets from which I can create over 500 different screens in my web application. This meas that I never have to bother witing any HTML code as it is all generated by the framework.

If you want to read about my framework then take a look at http://www.radicore.org
Tony Marston Send private email
Tuesday, August 01, 2006
 
 
Berislav Lopac > Make sure you take a look into other options, specifically Firebird and especially PostgreSQL.

I know those two as well, although PostgreSQL is pretty rare on shared hosts, and FB isn't at all available.

At any rate, I will have to look into encrypting data on the server, because customers will most likely ask questions about security and what happens to their data if... no... when the server is compromised.
TheFred
Tuesday, August 01, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz