Sorry to yell (well, we don't have to assume all exclamation marks are equivalent to yelling) but this email came in to me this morning and it is very troubling for me:
I have a question for you about varScoper and CF9. As I understand it, in CF9 all unscoped variables in a function are placed into a protected local scope, thereby killing the need to use the var x = "" line to scope them.If that understanding is correct, does this make varScoper obsolete in CF9? Our team in upgrading to CF9 in the near future, and trying to identify if running code through varScoper needs to continue to be a part of our code review processes or not.
The answer is an unequivocal no. You must still continue to var scope your variables in UDFs and CFC methods. There is no change in this respect. ColdFusion 9 only makes two related changes:
- The var scope previous was an "unnamed" scope. ColdFusion 9 fixes this by creating a scope called local. Like other ColdFusion scopes you can treat this as a structure.
- Because there is an implicit local scope, you can now skip the var keyword and use "local." instead. So given the line used in the quote above, you could var scope X by rewriting it as local.x="". To me, this is still "var scoping", it just gets there via a different path.
So long story short - yes - you still need to var scope in CF9. The varScoper tool is still an important and necessary part of your testing/deployment strategy.
As I (slowly) try to recover from yesterday, I thought I'd send out a quick reminder to folks that the latest betas of both AIR 2.0 and Flash 10.1 are available.
AIR 2.0 should be an amazing release. I highly recommend catching up on Christian Cantrell's blog as he has quite a few entries on the new release.
Flash 10.1 is also now at beta 2. I've not followed the news much on this but from what I can see this will be an important update for mobile devices.
I hate to sound like a broken record, but, I'll say it again. For my readers who only know ColdFusion, now is the time to expand your skills and pick up AIR. Even if you don't want to learn Flex (which I recommend as well), you can simply build upon your existing HTML and JavaScript knowledge by adding the power of AIR.
There are some really good blog entries out there on ColdFusion 9 and optimization (I suggest reading everything at Rupesh's blog). As a developer, you have multiple options for how your entities are configured, and how related data is loaded. I'm still coming to grips with those options and learning how to best use them. But here is my question. Are there tools out there that can monitor your ORM usage and report back suggestions for optimization? As an example, consider a Department object that has many Employees. You may decide to make that relationship lazy="extra" since you figure you will almost never need to get employees from a department. But imagine now it's three years down the road - your front end code has changed - and now you are almost always requesting that data. It would make sense to change that relationship (and maybe change fetch to select as well) - but how would you know that? Is there some tool out there that can notice how you are using your entities and then provide some guidance? Certainly you can log the SQL, but it may not be simple to go from that logged SQL to your business logic.
Are there any tools/suggestions/etc in this area?
Google's Static Map API
Feb 4
I discovered something cool today - Google has a "Static" Maps API. What is that exactly? While Google Maps is very powerful, it requires the use of JavaScript. For simple maps, or for embedding maps into PDFs, you can't use regular Google Maps. This gets around it. The API is a simple URL based service that returns the image in binary form. So for example, to create a map for my area, I'd use this URL:
This week a user sent in what I thought was a rather simple request. He needed to find the center of an image. That's pretty trivial math, so I fired back with the following:
1) Read the numbers from left to right.
2) Each number is added to the next...
3) Except when the next number is larger than the current number. Then you take the pair and do a subtraction.
So with this logic in mind, I came up with the following UDF. It assumes valid Roman numerals for input. But it seems to work ok.
2 var romans = {};
3 var result = 0;
4 var pos = 1;
5 var char = "";
6 var thisSum = "";
7 var nextchar = "";
8
9 romans["I"] = 1;
10 romans["V"] = 5;
11 romans["X"] = 10;
12 romans["L"] = 50;
13 romans["C"] = 100;
14 romans["D"] = 500;
15 romans["M"] = 1000;
16
17 while(pos lte len(input)) {
18 char = mid(input, pos, 1);
19 //are we NOT at the end?
20 if(pos != len(input)) {
21 //check my next character - if bigger, replace with a sub
22 nextchar = mid(input, pos+1, 1);
23 if(romans[char] < romans[nextchar]) {
24 thisSum = romans[nextchar] - romans[char];
25 result += thisSum;
26 pos+=2;
27 } else {
28 result += romans[char];
29 pos++;
30 }
31 } else {
32 result += romans[char];
33 pos++;
34 }
35 }
36
37 return result;
38 }
You can see how it follows the basic, 'left to right, add the numbers together' process, and how it notices when the current character has a higher number to the right of it. I wrote up a quick test script for it like so:
2 <cfloop index="input" list="#inputs#">
3 <cfoutput>
4 #input#=#romantodec(input)#<br/>
5 </cfoutput>
6 </cfloop>
Which produced:
XX=20
XI=11
IV=4
VIII=8
MC=1100
DL=550
XL=40
You can download this UDF at CFLib now: romanToDecimal
p.s. Sorry for those still waiting for UDF approval at CFLib. It is a volunteer process (myself, Scott Pinkston, Todd Sharp) so be patient!
That title really isn't very clear, so let me explain a bit more about what this blog entry is about. A reader asked if it was possible to do pagination via Ajax (ie, each page of content is loaded via Ajax), but have the controls (the previous and next buttons) exist outside of the Ajax-loaded content. This is an interesting question. It is incredibly trivial to load content via Ajax with jQuery. My seven year old could do it in his sleep. But we need to find a way to handle showing, and hiding, the navigation controls. We also need to ensure those controls can correctly "drive" the content to handle paging. Like ColdFusion, jQuery provides many ways to solve a problem. This is just one example.
So only 4-5 weeks after I said I would wrap things up, it is finally time to announce the winners of the "Best of ColdFusion 9" contest. Before I do so, I have a few things I want to say.
First - I know that showing other people your code can be a nerve-wracking experience. It takes a bit of bravery to put your code out there for the world to see (and pick apart), and I, and my readers (if I may be so bold to speak for them), appreciate it. I love talking about code, and I think sharing code for review is one of the more fun ways to learn. So no matter what, I'm appreciative and I thank you all for your submissions. This year I had submissions from:
Dale Severin
Sam Farmer
Budd Wright
Russ Spivey
Dan Vega
Andrew Duval
Adam Tuttle
Simon Romanski
Marko Simic
Guust Nieuwenhuis
Ben Nadel (I don't know this guy, but something tells me he is an up and comer in the CF world...)
Corey Butler
Chris Martinez
Ben Riordan
Nathan Struz
We had 15 entries in total. There is no way in heck I would have been able to judge all of these. Luckily I had a great group of guest judges who helped out. Big thanks to
Brian Rinaldi
Paul Hasting (Paul, I promise my code will be globalized... one day)
Todd Sharp
Francisco Pualino
Daniel Short
Brian Kotek
Charlie Arehart
And finally, huge thanks to Adobe - specifically Adam Lehman and Allison Hueslid for supporting me and the contest with some killer prizes and Liz Frederick for creating the logo.
So I'm sure you're tired of all this blather and just want me to get to the winners. The judging process worked like this:
Every judge gave me a numeric ranking (from 1-10) on how well they thought the entry they reviewed best met the goals of showcasing ColdFusion 9. I looked over these reviews, and the ones I reviewed, and made a judgement call. This was, by necessity, somewhat arbitrary. I expect people to disagree with this decision. To me though the prizes are the least important part. Looking at all the entries and the stellar examples of ColdFusion 9, I think the job is done. But there has to be a winner... and that winner is...
Ben Riordan and MuralBuilder This entry blew me away for something I normally care little about - practicality. Folks know I like to write a lot of CFML, and not much of it is actually useful, so to see an entry that was both cool and useful - well - it just felt like the right choice to make.
As for the three runner ups, they are:
Marko Simic and Collya
Sam Farmer and spreadEdit
Budd Wright and - my personal favorite - CFDungeon
All in all - I was pretty happy with all the entries (and thanks to Adobe, everyone is getting a little something something), so everyone please give yourself a big pat on the back.
The first (I think?) ColdFusion 9 Security bulletin has been released: Solution available for potential ColdFusion information disclosure issue This relates to Solr and it's built in web service.