Var Scoping In a For Loop - Watch Your Var Names

Posted By : todd sharp Posted At : August 4, 2010 3:47 PM Posted In: ColdFusion

3

I was doing some work with Dan Vega's Hyrule project yesterday and noticed some odd behavior where the validation routine would basically stop if I used an 'isMatch' validator. I checked the normal logs, etc and made sure there wasn't an errant abort or try/catch in the code and then I finally spotted the issue.

Basically it boils down to the fact that Dan had an outer and nested loop that were both var scoping the loop iterator of 'i'. This led to the unfortunate circumstance of prematurely ending the outer loop from completing. Consider the following code:

public void function foo(){
    for(var i=1; i<=3; i++){
        writeOutput('outer loop - i=' & i & '<br />');
        for(var i=1; i<=2; i++){
            writeOutput('inner loop - i=' & i & '<br />');
        }
    }
}

You might expect the following output from that code:

for loop good

But you'd actually get this:

for loop bad

That's because the inner loop overrides the assignment of 'i'. When the inner loop completes and the outer loop proceeds it realizes that 'i' is no longer less then or equal to 3 and it stops processing.

The lesson here is to be careful with your var scoping. You'll no longer get the luxury of ColdFusion telling you that a local variable can not be declared more then once. Also, remember the importance of variable naming. You won't get an error but you could end up with some seriously unexpected results.

Real Life RIA Powered By The Adobe Stack - CFUnited 2010

Posted By : todd sharp Posted At : July 30, 2010 4:23 PM Posted In: AIR, CFUnited, Flex, ColdFusion, CFUnited 2010, SlideSix

0

I created an online focused version of my slides from my Real Life RIA session at CFUnited. To check it out head past the jump.

CFUnited Is Almost Here!

Posted By : todd sharp Posted At : July 21, 2010 9:49 AM Posted In: AIR, CFUnited, Flex, ColdFusion, CFUnited 2010, SlideSix

0

Wow, it's been six months since I wrote a post on the old blog here (I know you've all missed me)! The awesome news is that CFUnited is right around the corner - just a week away in fact! So, on to the important news...

Facial Recognition in 14 Lines Of ColdFusion

Posted By : todd sharp Posted At : January 21, 2010 2:05 PM Posted In: Java, ColdFusion

60

I was doing a bit of research on a potential project when I stumbled across faint, a Java facial recognition library and decided to give it a quick try.

The bad news is that the documentation is literally non-existent. So I did a bit of poking around the Jar and quickly found an 'OpenCVDetection' class. I dropped the faint Jar in my class path, restarted CF and about 5 minutes and 14 lines of code later I got the following result:

Now Running ColdFusion 9

Posted By : todd sharp Posted At : November 12, 2009 8:51 AM Posted In: ColdFusion, SlideSix

10

If you follow me on Twitter you probably already know, but I wanted to put the word out that I'm now running ColdFusion 9 Enterprise. From a performance standpoint, the difference on SlideSix is pretty noticeable. I'm also loving how quick the Flex Management Console is now thanks to the complete Flash Remoting overhaul that came with CF9.

Want to know the coolest thing of all about this upgrade? It didn't cost me a dime. That's right, I was lucky enough to get a completely free license to CF9 Enterprise from ColdFusion Product Manager Adam Lehman. Do you have a brilliant idea for a startup that takes advantages of the power of ColdFusion? Pitch your idea to Adrock and you may just get your hands on a free license too!

I can't wait to take advantage of some of the UI enhancments and I know that the PDF upgrades will lead to an immediate improvement in the conversion quality of some presentations. There's also a handful of other ideas I have in mind to play with. More on those later.

As a footnote, I should mention that for the most part the upgrade went fine but there was one minor annoyance. The process to get CF working on IIS7+ is widely documented, but I ran into a different issue. After CF installed I kept getting Handler Mapping errors thrown by IIS. I'm not exactly sure this is the right thing to do, but the fix was to check 'Configure 32 bit webserver' in the web server connector tool. See screenshot:

Update: I ran into this issue because the App Pool was configured to run 32 bit. When upgrading from 32 bit CF to 64 bit make sure to set 'Enable 32 bit applications' to false in the App Pool's advanced settings.

Quick Puzzler - Get Last Friday

Posted By : todd sharp Posted At : October 27, 2009 1:49 PM Posted In: ColdFusion

14

Here's a quick puzzler to get your brain working. I just helped out a friend with the following issue but I'm interested in seeing how others go about solving it. I'll borrow Ray's Friday Puzzler rules - don't spend more then 5 minutes on it and the best solution is granted 1,794 bonus points.

Write a UDF that solves the following puzzle: If it is any day or time after noon on Friday (server time) then set 'reportDate' equal to the current date. If it's any day or time before noon on Friday then set 'reportDate' to last Friday. Sounds easy, but it can get a little tricky.

Post your entry in the comments below.

Building A Better Search For SlideSix - Part 1

Posted By : todd sharp Posted At : October 22, 2009 8:47 AM Posted In: Java, ColdFusion, SlideSix

2

After finishing up a few outstanding fixes and enhancements for SlideSix the other day I decided to give search a bit of love. Well, I didn't quite decide it; it was more of the gentle reminder from Sean Corfield about the existing search not really working all that well that prompted me to action. Regardless, I learned a few things about search that I'm going to share over a few blog posts that will use this alliteration littered title.

ColdFusion 9 Released!!

Posted By : todd sharp Posted At : October 5, 2009 12:11 AM Posted In: ColdFusion

2

I hate to write simple posts like this without bringing my own unique take on an announcement, but this one is too good to pass up. I'm extremely excited that ColdFusion 9 is finally publicly available. Congrats to all my friends at Adobe who've worked so hard on this release. It really is a game changing release for the CF world. I wish I was in LA to raise a glass with you right now. Thanks again and congrats.

I'll be blogging much more in the coming few weeks on some of the new features of CF 9. Stay tuned.

Flash Remoting Broken On CF9? Here's The Fix

Posted By : todd sharp Posted At : September 23, 2009 8:39 AM Posted In: Flex, ColdFusion

2

I'm finally getting around to really digging into ColdFusion 9 and stumbled on a very strange error with Flash Remoting (specifically the Flex Messaging Gateway) in one of my applications. The app worked just fine on CF 8 but I started getting a 'foo is undefined in event.data.body' when I tried it in 9. So I started doing my standard troubleshooting. Step one was to dump out the struct in question. Oddly enough, my key was there and it had a value. Next I tried structKeyExists() and sure enough CF told me that the key did in fact exist. However, when I tried to access the value I'd get the exception. I even tried associative array notation and accessing the keys as uppercase in case there was some weirdness going on. That didn't work either.

Want To Win A Customized CF Dude Flip Camera?

Posted By : todd sharp Posted At : September 8, 2009 9:02 AM Posted In: ColdFusion

5

This is super cool. Simon Free has put together a contest to help bring awareness to the three newest ColdFusion conferences and will be giving away 3 customized 'CF Dude' Flip cameras - one at each event. So what do you have to do to win? It couldn't be easier. Just register for one of the events and then tell him, in 100 words or less, why you love ColdFusion or are excited to learn ColdFusion. That's it. He'll pick a winner at each event and will award the Flip camera. See the site for the rest of the details.

Awesome idea Simon, and nice work on the site design by Andy Matthews.