Page 2 of 2

Posted: Wed Feb 14, 2007 3:23 am
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++ ;)

Posted: Wed Feb 14, 2007 9:44 am
by Jenk
I picked up Hungarian notation from my first language.. VB (I feel dirty..)

I dropped it the moment I dropped VB, however.

Posted: Wed Feb 14, 2007 10:17 am
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. ;)