Jump to content


Photo
- - - - -

Variable Names


  • Please log in to reply
3 replies to this topic

#1 lazijunkie

lazijunkie

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 19 July 2006 - 12:00 PM

Variable Naming

The Variable Naming standard you choose, can be anything you want, bearing in mind that different languages have restrictions on what can be used to name variables, and some keywords are banned from being included in variable names. Some languages are also case sensitive, or insensitive, and that also has as effect on variable names.

Variables in Php
The variable name is case-sensitive and starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

Variable Naming Tips

1) Choose a standard, that comes naturally to you, and one that will adequate describe the variable and the use of the variable. Also insure that the naming standard you choose, if you are having multiple members on your team, that everyone sticks to the same standard.
$website_name = "Php Tutorial Site";

2) Iteration and other loops, you can use the "known" variables that are associated with iterations
$ index;
$indx;
$ndx;
$n;
$i;
$count;
$counter;

While these variables do not appear descriptive, when it comes to loops, they describe the functionality very well, and that usage is commonly known in the programming world.

3) Using Upper and Lower Case
This helps in making the name of the variable easy to read, as it provided a break to the eyes, and help the programmer to understand that variable and it purpose. This helps to show the normal speak break that is associated when joining 2 or more words.

$fullname;
$FullName;
$myfirstbook;
$MyFirstBook;
$phptutorialsite;
$PhpTutorialSite;

4) Using the underscore is another way to join word, and provide the natural breaks, just as we did with the Upper and Lower Case, we can also use the _ underscore, in conjunction with the Upper and Lower Case to get full effect and making the variable names easy to use.

$mywebsitename="Php Tutorial Site"
$my_website_name = "Php Tutorial Site";
$MyWebsiteName = "Php Tutorial Site"
$My_Website_Name= "Php Tutorial Site"

Alogn with writing comments in your PHP program, having descriptive variable names is an effective technique in reducing the number of hours spent programming and debugging.

#2 Indigo

Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 19 July 2006 - 05:40 PM

Alogn with writing comments in your PHP program, having descriptive variable names is an effective technique in reducing the number of hours spent programming and debugging.


Well, I agree, but anyone with a brain should understand this without reading a tutorial. :)

Edited by Indigo, 19 July 2006 - 05:42 PM.


#3 lazijunkie

lazijunkie

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 20 July 2006 - 05:53 AM

Never assume, leave nothing to chance, you be surprised what you take as being common knowledge, that people either dont know or dont pay any attention to. Everyone reading the tutorials might not be an expert programmer or never been exposed to programming.

I have programmed on projects with bunches of people, and i was really surprised when we finally came together to make it work.

#4 joe

joe

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Location:stuck in the middle of cyber space

Posted 21 July 2006 - 03:01 AM

Never assume, leave nothing to chance, you be surprised what you take as being common knowledge, that people either dont know or dont pay any attention to. Everyone reading the tutorials might not be an expert programmer or never been exposed to programming.

I have programmed on projects with bunches of people, and i was really surprised when we finally came together to make it work.


it's ok !! Good tutorial... :o ^_^




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users