Quick question from C++

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

Weirdan wrote:
Mordred wrote: 2. I find intval() to be the more readable variant of the two, but IIRC someone here said that internally casting and calling the function do the same.
Through testing I found the intval to be about 10 times slower compared to (int). Maybe it is because intval understands hexadecimal strings.
Oh. In that case I'll have to reconsider my casting strategy. Thanks!

As for Hungarian, I too come from (actually still am, in my day job) C++. I find it easier to track the intent behind my variables. This doesn't mean that the occasional $sResult doesn't end being "false" on error and so on, I'm not forcing strinct typing into my coding, just "hinting" at it.

For OOP I go even further, I use $this->m_nIntMember and $pObject->m_sStringMember, etc. This makes it easy (for me) to track the following two possible mistakes:

Code: Select all

//in a class method
$m_nIntMember = 0; //huh, m_ prefix without a -> in front of it? ALERT ALERT ALERT

Code: Select all

$sResult = '';
//...
$this->sResult .= '<hr>'; //-> without a m_ prefix? ALERT ALERT
(I hate that PHP doesn't have proper variable locality, and in my beginning PHP/OOP days I often forgot about the $this-> nonsense.)

I also do $g_pGlobalObject and $s_sStaticString when the need arises.

And yep, I do CamelCasing, but not of the Java semiCamelCased variety, all functions start with a capital. But well, it's my religious upbringing I guess, the church of C++ ;)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

I picked up Hungarian notation from my first language.. VB (I feel dirty..)

I dropped it the moment I dropped VB, however.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Mordred wrote:And yep, I do CamelCasing, but not of the Java semiCamelCased variety, all functions start with a capital. But well, it's my religious upbringing I guess, the church of C++
You know, I didn't realize until today that I'd been doing the semi casing in JS... It always seemed strange but I could quite put my finger on it.

I do spread out my function declarations just like I did in C++ though.

Code: Select all

/* Object getElemStyle()
 * Parameters: 
 *     String strId
 *
 * Cross-browser element styles, returns object or null
 */
function getElemStyle(strId			// element id
				)
{
	// DOM or IE
	if(DOM || IE)
	{
		return getElem(strId).style;
	}
	//Netscape
	else if(NS)
	{
		return getElem(strId);
	}
	
	return null;						// error
}
feyd | Syntax highlighting is case sensitive: JavaScript is not javascript. ;)
Post Reply