Page 1 of 2

On application design

Posted: Thu Aug 22, 2002 8:23 am
by nielsene
This is basically a rambling post, 'cuz I'm bored :)

After being on this site for about a week, I'm starting to see some trends.

People brand new to PHP, tend to ask questions like "I need a page that does foo" or "Can PHP do bar?" where bar is oftened defined in terms of some page display.

The next group of people are often asking the questions like "How do I do X, Y,or Z better" with the tasks being some small snippet of the program.

As some people have said PHP's ease of use leads people to jump right in and not design their application first. However, I think there is an important observation that people miss in that statement. When either writing, or designing, a new web site, do you view it as a collection of pages (a web site) or a collection of data, functions, and display (an application). I would hazard to guess that most people fall into the first camp. If you sit down and design your pages ahead of time, carefully planning which pages lead where, etc, you'll likely feel are warm inside that you've done your good deed and designed before code. Yet, you soon get stuck in the same morass as before and start to think that all this design business is bogus.

I'd argue that in order to "elevate" your coding to the next level its useful, no required, to stop thinking page-centric and starting thinking of your project as an application.

I'm thinking of fleshing this idea out into an article of some kind, does anyone have any opinions

Posted: Thu Aug 22, 2002 8:33 am
by llimllib
I think that the question is *when* to design as an application, and when to design as a collection of pages. My homesite, for example, is a collection of pages. There is absolutely no need for me to make my site otherwise - it's 2 pages large so far! I use PHP to organize my HTML into functions, and some basic database interaction, but I hardly think of it as an application. At work, where I'm developing an application, I have much different design requirements/methods than I do at home, because there are much different goals for the project.

Posted: Thu Aug 22, 2002 8:50 am
by nielsene
So the points I can pull from what you said, I think are:
1. You need to know how to do both
2. You need to be able to decide which method is more appropriate

However, I would also argue that having seen the same code you showed a while back where your page is primarily a series of function calls that this is already at least a strong hybrid.

Most beginning PHP users I've seen stick some common html/php into a header/footer, maybe using a common menu/sidebar. But the content is all generating as a single script in-line with the page. They may have a few functions abstracted out, but not many and a lot of the code is very repetitive. To me this says each page was written individually with little thought to the other pages. Your method, looks to me, like even on simple small sites you still consider the application as a whole..

So maybe the terms I want are avoid page-centric and use either site/application-centric design?

Posted: Thu Aug 22, 2002 9:03 am
by llimllib
Alright, now I see what you're saying. I think that actually would make a really cool tutorial - kind of tricking moderately experienced PHP programmers into learning some real computer science with a language they started to learn for include().

A couple ideas for sections:

a) Definition of application vs. page-centric design
b) Reasons for site/application design
c) seperation of implementation from use
d) functionalization (is that a word?) and objectification

Posted: Thu Aug 22, 2002 9:06 am
by nielsene
Exactly, and thanks for the section ideas.

Posted: Thu Aug 22, 2002 9:47 am
by jason
This seems to almost sound like N-Tier application design. :D Okay, here are my thoughts (as unimpressive as they may be):

Application Design and Information Architecture (which is what some people call web site design) are closely related, and then they aren't. Making a website an Application is almost a like asking to be hung, while designing a website with no Application focus can still get you somewhere.

The problem with a lot of newbies is that yes, they don't think of PHP as a programming language. This problem isn't because they are thinking of PHP as web pages, and not as an application, but because these newbies don't know how to program in the first place. I see a lot of PHP questions that aren't really PHP questions.

"How do I include a page?" is a PHP question.
"How do I include a different page depending on the link a person clicks?" is a programming question.

You can easily tell the difference in the questions: The former asks about syntax, the latter asks about logic.

Unfortunately, this is a problem that is difficult to fight against. You try telling a person who has been PHP scripting for 2 years that they don't know how to program. Programming isn't knowing a language well, it's knowing how to solve problems on your own.

For the most part, you will rarely see programmers asking questions on most boards and mailing lists like the above. Why? No, not because they know the answer. Heck, even experienced programmers from other languages who are just learning PHP follow the same pattern: Research the problem, search for the answer, solve it on your own. As you gain more experience in an area, you learn more and more. Programming is one of those fields where once you have learned how to program, the syntax is easy.

A person who doesn't know Java, but knows how to program, can probably read through the Java code easily enough, and make judgements based on experience. Similarily, a person who doesn't know PHP but wants to include different pages when a link is clicked can solve the problem without knowing PHP (Send a variable to the page, probably via the GET method, retrieve that value, validate it for security reasons, and then include the page). When they post a question (If the found the need to instead of finding the answer on their own), the question might look like this: "I want to include a different page depending on the link clicked. I thought about passing it via the URL and then including it based on the value of the link, any suggestions to this method, or other methods that work better?"

You should now be able to see the difference in the types of questions.

Now, back to the topic at hand: Whether web sites should be programmed as pages or programmed as applications.

The answer, if of course, both and neither. When developing a web site, you need to develop the application as you see fit. When the underlying code is being designed, each area needs to best fit the task.

For example, when I display the news on my front page of the website, I have simply included the code to do this in the page. However, other code, like comment code, is abstracted out into functions and included where I need it.

Tracking information is done as well, along with User information. I have includes all over the place. Certain other pages, like for tutorials, have the code included in just that one page.

So, in the end, knowing how to developing both styles will help you.

Posted: Thu Aug 22, 2002 9:55 am
by llimllib
I agree. I think he's saying that newbies know one side (page method) and not the other (application method), and as such, he wants to write a tutorial to teach them the application method. of designing web pages.

Posted: Thu Aug 22, 2002 10:27 am
by nielsene
Yes, people who arrive at PHP without a CS style background often miss out on these aspects of programming. I know its not possible to really teach it with a tutorial, but its a better place than the forums. In my short one-week on this forum I've already seen at least three high activity users who seem to be seeking this type of information.

This method can be grown to N-Tier, but doesn't have to be if coders aren't ready for it. Simply abstracting some of the commonly used queries/displays will help.

At least to me

Code: Select all

$includeSideMenu=TRUE;
echo beginPage("PageTitleGoes Here",$includeSideMenu);
echo showItem("News",$id);
echo endPage();
is much nicer than in-lining all the code for displaying one item of news and with proper abstraction showItem might be able to also handle articles, posts, etc. The showItem function might not strongly seperate data from display as an N-Tier system would, but its a start to get programmer thinking about using functions for common tasks.

There will likely be some queries/display thats still done directly in-line with the page, somethings are so custom that they just fit there. Especially on very high load sites where wraping some code in functions is too costly. But in most of these cases it important to argue for breaking the functional model as opoosed to breaking it by default.

Posted: Thu Aug 22, 2002 11:06 am
by nielsene
Thinking about this some more, I think Tutorial would be the wrong word for this. "Case Study" is probably a lot closer. The general format would probably be something more like

Present a brief description of the problem, needs to be something that would typically have at least 3-4 main pages with a few small auxillary pages.

Then provide the code done in the "page-centric" method

Now point out the places where functions could be abstracted and work through one or two. This section will give some heuristics/guidelines for how to select these functions, but of course its really a matter of experience.

Then show the new version with the associated libraries created.

As a possible aside/addition show the same thing done using a class approach. The goal is to teach decompositions/abstraction not "The One Right Way". Give people choices, let them think.

As a final exercise a more N-Tier system could be shown spilting either the functional/object version up.

And the article can close with "If you found this interesting and useful you would probably enjoy a 'Software Engineering' class at a nearby college/university".

Posted: Thu Aug 22, 2002 11:12 am
by llimllib
that would be h-o-t-t hot :)

Posted: Thu Aug 22, 2002 11:20 am
by nielsene
Any thoughts on what type of tool would server as a good vehicle for this? My first thoughts are a very minimal threaded discussion board as almost everyone has written one at some point. Or would a "portal" like site be more appropriate (of course with only one functional area implemented in the interests of brevity...) I can't let it get too complicated/large because my thesis is ever calling me (bet you couldn't tell by my posting rate :) ), but it must be complicated enough to show the usefulness of the paradigm.

Posted: Thu Aug 22, 2002 11:53 am
by phpPete
This is right up my alley as for what I'm looking to learn. It's the next logical step in developing as a developer.

I would be totally psyched to see somthing like that!

Posted: Fri Aug 23, 2002 1:13 am
by phpPete
Keeping with the theme of this thread I happened accross these articles:

http://www.phpfreaks.com/tutorials/1/0.php
http://www.phpbuilder.com/columns/tim20001010.php3

Posted: Fri Aug 23, 2002 7:01 am
by jason
nielsene: I originally replied to you to your email, but it wasn't until it bounced back that I realized you sent it via the forum. The answer would be yes, I never turn down a tutorial. :D Greedy webmaster that I am.

Anyways, you might want to focus on creating a news script maybe. I think most newbies would want to learn how to create that, as it's relatively popular.

For fun, I am working on a tutorial on how to create a shoutbox. I don't know why I choose it, but I figured it was simple, and yet, I could teach them something at the same time.

Posted: Fri Aug 23, 2002 7:17 am
by phpPete
:oops: ...ummm....errrr...what's a "shoutbox"...?