TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-18-2008, 02:50 AM   #1 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default Using prefixes with variables??

Gareth wrote the following in reply to a post about good programming practices.

===============
I have recently got into the habit of using prefixes to my variables. Such as:

a mysql query = $qQueryName
a result = $rQueryName
a message = $mMessageName
a variable = $vVariableName

They really do help me, at least, structure my code and makes them easy to see what they are.

==================

It is interesting. Does anyone else use prefixes like this? If so, what are they? I'm asking because I'm a new learner and I was doing the same thing, except I was making up my own system, sort of like:

a numeric variable = $nNumber
a char variable = $cName
an array = $aMyarray

Thanks!
Dave is offline  
Reply With Quote
Old 04-18-2008, 03:01 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Karl, Will and I all use them throughout our projects. Will posted a thread on the actual prefixes over in this thread many months ago, which you may find interesting. Our prefixes are not strictly correct because we use sz for strings. In our opinion, $szString looks prettier than $sString, and so we're victims of aesthetics in that instance. Naughty us!

However, considering I use them, I may be somewhat biased, so please excuse me. Nonetheless, the reason I use variable prefixes is so I can immediately identify what a variable should contain. It doesn't just have its readability advantages, but rather you can automatically filter data based on the prefixes. So if I have a variable called $iNumber then I could enforce that data type to be an integer. It often works well in passing the items from POST and GET.

The variable prefixes are actually nothing new. They're officially called Hungarian notation, and Wikipedia has an impartial page all about them. At the end of the day, it all comes down to personal preference. We can argue for and against for years to come.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 04-18-2008, 03:09 AM   #3 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

well actually it depends on what your convenience really was...for me...i also use prefixes in variables..:D

Code:
$tbl_<variable_name> 
eg. $tbl_news
so this means that this is my table variable name for my news..:D
zxt3st is offline  
Reply With Quote
Old 04-18-2008, 03:53 AM   #4 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

Wildhoney --

Thanks for pointing out the previous discussion. It was very good, just the points I was looking for!!

Cheers!
Dave is offline  
Reply With Quote
Old 04-18-2008, 04:16 AM   #5 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Smile

I also read the Wikipedia article you cited. Very interesting! It shows that some very big names in recent comp. sci. history have very different opinions about using this type of notation.

David
Dave is offline  
Reply With Quote
Old 04-18-2008, 04:19 PM   #6 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

Also, I heard that this notation is not anymore recommended because of the problems that appear if you cast varialbes.
But I agree that using some of the prefixes is really helpful
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Old 04-18-2008, 06:18 PM   #7 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

Quote:
Originally Posted by Dave View Post
Gareth wrote the following in reply to a post about good programming practices.

===============
I have recently got into the habit of using prefixes to my variables. Such as:

a mysql query = $qQueryName
a result = $rQueryName
a message = $mMessageName
a variable = $vVariableName

They really do help me, at least, structure my code and makes them easy to see what they are.

==================

It is interesting. Does anyone else use prefixes like this? If so, what are they? I'm asking because I'm a new learner and I was doing the same thing, except I was making up my own system, sort of like:

a numeric variable = $nNumber
a char variable = $cName
an array = $aMyarray

Thanks!
Hey, that Gareth is a genius!

I have found that a prefix system helps. What doesn't matter is what the prefixes are: you could use anything, just as long you can read them quickly and be able to tell what they are.

Gareth.
Gareth is offline  
Reply With Quote
Old 04-18-2008, 07:59 PM   #8 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

Yep, that seems to be the case.

Thanks.
Dave is offline  
Reply With Quote
Old 10-18-2012, 02:05 PM   #9 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Some conservatives have Coach Factory Outlet pushed that critique further, saying that Mr. Obama’s policies are too costly, often assist the wrong people Louis Vuitton Belts and could have the paradoxical effect of driving up college costs. The dispute turns not just on different Coach Factory Outlet assessments of how policies play out, but on differing philosophical views about the role of government. During Gucci Belts his time in office, Mr. Obama has sharply increased aid to low- and middle-income students, notably through the Pell Grant Coach Factory Outlet program, which grew from $14.6 billion given to 6 million students in 2008, to nearly $40 billion for Coach Factory Outlet almost 10 million students this year. His administration also made it easier to request aid, shortening the Coach Factory Online complex federal application and allowing people to transfer their financial information electronically from the Internal Coach Outlet Online Revenue Service database. But while many education experts laud his efforts, analysts of varying political Coach Outlet Online stripes have also questioned how much impact some of the president’s policies will have, noting that the prices Coach Online Outlet charged by colleges, and student borrowing, continue to climb.But behind the headlines about soaring costs, the Coach Factory Outlet Online reality is more complex and wildly uneven, because a growing number of students receive Coach Outlet Online financial aid, and only relatively high-income families pay those fast-rising sticker prices. Adjusted for Coach Factory Online inflation, the College Board calculates, the average net price changed little over the last decade at private Coach Factory Outlet schools, and rose only modestly at public ones.Defending federal spending, Arne Duncan, the secretary of Hermes Belts education, said that for more than 30 years, college prices had risen even when federal aid had not, leading him to believe Coach Factory Online there was zero correlation.
dashixiong is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:31 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design