Skip to content

3 things I learned today

Dear Reader,

It’s always wonderful to learn new things. Sometimes it’s not so great if they are things you should have known. Here are 3 things I learned today. Presented here more for my own benefit than anyone else’s.

VFP:
In my day job I work with VFP and MapPoint. If I select a series of GPS lat/long points from a table using SQL into an ARRAY and plot them with MapPoint 2k4, each ADD() takes 2-3 seconds. If I use the exact same select statement but select into a cursor and then use a SCAN loop, the entire map renders in under a second. I’m not exactly sure what is going on. Maybe FoxPro does something goofy with arrays in memory that causes MapPoint to have to brew a pot of coffee between each waypoint. Either way, it seems that in this particular case, cursors are much faster than arrays.

PHP-1:
For 6 years I’ve been working in PHP and occasionally, I have to use the global command. My reading of the manual (all parts concerning the global command and the $GLOBALS array) says that the global command simply exposes a variable defined elsewhere into the current context. Not so and apparently I’m the last PHP developer to know this. global adds the variable to the $GLOBALS array. This probably needs to be mentioned in the manual. Re-reading the appropriate sections, I see how they might be interpreted to say this but a simple statement of fact would be nice. Of course we all know globals are evil anyhow and should be avoided…but still. That one I should have known.

PHP-2:
strpos() and a couple of other PHP commands are weird in that they will either return false, a boolean or 0-n, an integer. In most cases in PHP 0==false but in the case of strpos() the chr you are looking for could be at position 0 so 0 is a valid response. but if it doesn’t find anything it needs to return false. The manual tells you to use === to test for a boolean.


<?PHP
if (strpos(x,y)===false) {
// it's not there...do something
} else {
// it's there, do something
}
?>

I usually end up writing stupid if statements like:


<?PHP
if (strpos(x,y)===false) {
} else {
// it's there, do something
}
?>

Which, while syntactically correct are not elegant. ee99ee pointed out to me that !== is the opposite of ===. (Again, I’ve not seen this in the manual but will admit that I never bothered to look in this case) So I can now use

<?PHP

if (strpos(x,y)!==false) {
// it's there, do something
}
?>

Which is a lot cleaner.

Ok, enough for CS101. :)

Until next time,
(l)(k)(bunny)
=C=