home support FAQ resources services partners contact us contact us
 Web Application Previous  Next  
 Tutorial

Chapter 1 Development Concepts

As this example shows, global variable names tend to be longer than local variable
names.This is due not only to the module prefix but also to clarification practices.
When the definition and initialization point of a variable are unknown because
they’re hidden in a module to which you don’t have access, it’s very important to
reflect the variable’s meaning and contents in its name.There’s a practical limit to this,
of course—nobody would want to remember names of 40+ characters—but this is
more a limit of common sense.

Basically, you should name global variables just as you would describe them to
someone. For example, how would you describe the variable $phpPolls_lastIP? You
might not know what phpPolls does, but the name suggests that it has something to
do with polls. lastIP says that it’s the last IP… Which IP? You don’t know. Obviously,
the name for this global isn’t very well chosen, because it doesn’t describe its contents
exactly. Now suppose that you ask the purpose for this variable, and get the answer, “It
contains the IP of the last user who submitted a vote.”Think about a name for it now.
How does $phpPolls_last_voters_IP sound? Better, isn’t it? But although the name
itself might be good, it’s still not suitable because you’ve also seen two other globals
from phpPolls, both prefixed with phpPolls_ and then written in one word. For consistency,
you decide to separate different words within the name only by capitals:
$phpPolls_lastVotersIP.

Function names should be treated in the same elaborate style as global variables, but
with a few differences. Function names should describe their functionality and fit into
the flow of the language. Fitting names into the language flow is achieved by determining
the actions that a function performs and choosing a name that will be the
most suitable in the majority of all occurrences of that name.
If a function determines whether a user is currently online, for example, it might
have one of the following names:

function get_online_status($user_name);
function check_online_status($user_name);
function user_status($user_name);
function user_online($user_name);
function is_user_online($user_name);
Depending on the return type, only the first and the last name in this list are suitable.
Assuming that the function would return a Boolean value, it would usually be used in
conjunction with an if() clause, where it would look like this:
n Choice 1:
if(user_status($user_name))
{
// do something
}
Previous  Next  
Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist