Viewing by month: August 2005

Aug 30 2005

CFC Tips: Of course there are caveats!

Yesterday I posted a quick list of ten tips for dealing with CFCs. Folks have been quick to point out, publically and privately, that the tips aren't always 100% applicable.

Ben Rogers, Barney B, etc:

Thanks for your constructive comments.

Whoever e-mailed me anonymously:

Of course I know these aren't set in stone rules, and I didn't present them as such.

Conclusion:

The tips I posted are guidelines. Barney said it very well:

"every one of these tips is the WRONG thing to do in one case or another. 99% of the time, however, they're right"

There are times to go against almost every one of these tips. However, keeping them in mind will help you make sure that you're only going against them at the appropriate times.

So that some unnamed soul can feel a little more vindicated and assured that my head is not where they suggested, I'll now contradict most of what I said yesterday:

1. Don't use the "this" scope - except in the case that you need a more strongly typed transfer object.

2. Don't talk to application, session, client, etc. - unless, of course, you're building a facade for one of those scopes.

4. Don't get too caught up with OOP and Design Patterns - unless you understand the motivation and consequences, and are willing to do some learning during the implementation.

5. Just do it - but not on your client's dime in a way that is unethical and will get you fired.

6. Create constructors and name them "Init" - unless you're creating a stateless object, in which case the constructor can be fairly useless.

7. Use the variables scope! - see #6

10. Keep them small! - sure, they can get big in terms of numbers of lines, but this was a simple introduction to cohesion.

9 comments - Posted by Joe Rinehart at 9:01 AM - Categories: ColdFusion MX

Aug 30 2005

The AM Agg: Jared, Raymond, and the Electric Hamsters

Jared leads the way with Mappings

Jared shows us how to use ColdFusion mappings to switch between multiple versions of [Model-Glue/Mach-II/etc.]. A lot of CFers don't know about mappings, and he provides a good intro to the practical side of why they're a good thing!

Jared (Again!) on ColdFusion's place

He just keeps saying smart thing. Jared recalls a conversation with Mike Nimer (of Macromedia) about ColdFusion's place in the scheme of things, and how it makes a nice bridge between the abstract OO world, and the more procedural world of html, devices, and other things you actually interact with.

New Version*s* of Galleon Released

Yesterday, Raymond Camden released a new version (1.4) of his free message board platform, removing the need for a mapping, making it play better with existing database, and adding sticky threads and user ranking. Later in the day, a minor update was released that's primarily a bug fix and compatibility (BlueDragon) release. Is waiting for CFOpenBB worth it, or should we just use Galleon?

Fun Keyword Workaround in Flash Forms

Apparantly CF Flash Forms block key words (e.g., "new"), even in string literals like "New York," leading to things like foo = "Ne" + "w York". I wonder just how far people will go, and how much time will be spent in trying to push CF Flash Forms further than I think they were meant to go, and if that cost may equal the price of a license of Flex.

Kid charges cell phone with hamster. Thankfully, no response from PETA.

A 16-year-old in the UK turned a hamster wheel into a generator that charges his cell phone. 2 minutes on the wheel = 30 minutes of talk time. That's pretty impressive, but it's no jet powered beer cooler.

3 comments - Posted by Joe Rinehart at 7:31 AM - Categories: See Also

Aug 29 2005

CFCs - Ten Spontaneous Tips

A quick, unordered, outburst of ten tips for folks (new to) using CFCs. Feel free to add more, or tell me I'm a moron and that I forgot something.

1. Don't use the "this" scope.

Unless you know when and why something should be "public," err on the side of caution and avoid the "this" scope like the plague. Instead, write a function that returns the data you're after.

2. Don't talk to application, session, client, etc.

This reduces the reusability of your CFC: instead, pass it either the scope or the specific data it needs.

3. Use those "hint" attributes.

Your boss will be muy impressed by the slick-looking automagically generated documentation you can create via the CFC explorer, especially if you use CF7 to create a PDF out of it!

3. Understand ColdFusion mappings

It's easy to get confused when you don't understand mappings and ColdFusion is just sitting there telling you that "my.wonderful.earth.shattering" CFC can't be found.

The nickel tour on Windows + IIS + default CF/IIS install (glossing over Custom Tag caveats):

ColdFusion starts looking for CFCs by name at the ColdFusion root (by default, probably the same as your web root, e.g., "c:inetpubwwwroot"). If you try to load the "my.wonderful.earth.shattering" CFC, it'd look for c:inetpubwwwrootmywonderfulearthshattering.cfc. However, if you create a ColdFusion mapping of "/my" pointing to c:mystuff, it'd look for c:mystuffwonderfulearthshattering.cfc.

4. Don't get too caught up with OOP and Design Patterns

They're a lot easier to learn if you do stuff on your own and screw up. Otherwise, it's hard to "see" why they're good things.

5. Just do it

Going back to #4, CFCs in general are easier to learn if you screw up and then think about how you did things.

6. Create constructors and name them "Init."

Always create a in your CFCs named "Init" where the returntype is the name of the CFC (e.g., "my.wonderful.earth.shattering") and the last line is <cfreturn this />. It'll make you look like one of the cool kids, and you'll thank yourself later.

Example: It's a lot easier to pass the Init() method a datasource name and store it in the variables scope than it is to pass it to all of the cffunctions that need the datasource name.

7. Use the variables scope!

CFCs aren't just function libraries! They can hold data *in between* calls to their functions. If you have a CFC that mainly serves to query a database, you can "tell" it its datasource name, and it'll remember it when you call selectMyStuff() and updateMyStuff(), instead of having to pass it along each time.

8. Remember thread-safety.

Just because a CFC you're writing now isn't going to be placed someplace dangerous (like the application scope), it doesn't mean it never will. Luckily, thread safety in CFCs is usually as simple as declaring every variable, every time, with the "var" construct. Variable declarations always come after the list, and before any more code, or CF will throw an error. Example:

<cffunction name="doSomething">
<cfargument name="foo" />
<cfset var result = "" />
<cfreturn result />
</cffunction>

9. Don't let them output anything

Your CFCs should be used for logic purposes, not to print things to the browser. If you want to create HTML in them, create it and pass it back.

In other words, don't do this:

<cffunction name="sayHello">
<blink>Hello!</blink>
</cffunction>
Instead, do this:

<cffunction name="sayHello">
<cfreturn "<blink>Hello!</blink>" />
</cffunction>

This tip brought to you by the Campaign to Save the Marquee Tag

10. Keep them small!

If your CFC seems like it's doing a lot, and has functions that aren't really related to one another (say, addNewColdFusionDatasource() and orderAMushroomPizza()), it may be time to split it into two (DatasourceManager and PizzaOrderer).

10 comments - Posted by Joe Rinehart at 2:59 PM - Categories: ColdFusion MX

Aug 29 2005

The AM Agg: Google building its own Internet?

Google building second internet?

Google is rapidly purchasing dark (unused, not evil) fiber across the US. Is a massive ISP around the corner? Or, are they just tired of paying hosting and IP transit fees?

Google + CF + Flash

Judith Dinowitz over at the Fusion Authority has a nice collection of links to those using ColdFusion and Flash to build client software for Google services such as GTalk. Fun stuff!

Including Javascript within Javascript

Rob Rohan shows a quick little technique to include files via javascript by dynamically writing the script tag. Why didn't I think of that?

OpenOffice vs. MS Office

Real Tech News has a great review of real-world use of the open-source alternative to MS Office. I've used it for a few years, and for the price, it can't be beat!

GP de Plouay: Go George

OT, Cycling: George Hincapie, Armstrong's most faithful teammate, won the 23rd race of the ProTour. I have to like him because he proves that us tall guys can race, too.

3 comments - Posted by Joe Rinehart at 8:04 AM - Categories: See Also

Aug 25 2005

The AM Agg: gTalk, Ruby, And Robertson's a Nut

Villains: Is Google the new Microsoft?

Now, I don't think so: they seem to be a company that actually provides software that works most of the time. I think it's just jealousy, but some others don't.

GTalk + Event Gateways

Scott Stroz and Jared Rypka-Hauer have gotton gTalk working via a ColdFusion MX7 Event Gateway. Also worth checking out are the Flash and AJAX implementations.

I Google'd a bit, and can't find any .NET or PHP implementations yet. Are we just cooler? :)

Daemonite reviews CFMX vs. Ruby on Rails articles

There's a good distinction made here: the ColdFusion vs. Ruby on Rails articles compare a framework+language (RoR) to a language (CF). Read on for more insight.

Very nice Flash 8 Slideshow

While I've been impressed by the eyecandy examples for Flash 8, this is the one of the first Flash 8 examples I've seen that I think is unobtrusive and experience enhancing - a simple blur transition in slideshow.

One step closer to Macroflobiedobiemedia

Shareholders "overwhelmingly" approved the $3.4 billion dollar deal. "Overwhelming" doesn't quite state it: 99% approved.

Introduction to Flash Remoting

For CFers who've never really used Flash until Flash Forms came out, ASFusion has posted a great answer to the "What the @#$#@ is Flash Remoting?" question, covering everything from implementation to mechanics to some alternative implementations (AMFPHP).

RSS 0.9 -> CF Structure + Query function

Handy new CFLib entry from Joe Nicora that converts a RSS 0.9+ feed into a ColdFusion structure containing metadata and a query of items. Nice, eh?

Robertson: "Incredibly stupid."

OT, but I just can't get enough of watching Robertson get a smidging of what I feel he deserves. Sen. Coleman (R-Minnesota) called Robertson's call for the assasination of Hugo Chavez "Incredibly stupid" yesterday. I like this guy Ruiz's style, click the link, get a laugh.

1 comments - Posted by Joe Rinehart at 7:53 AM - Categories: See Also

Aug 24 2005

No Rumor: Google does IM

Yes, Google is going the IM route, providing IM and voice chat in a simple, clutter-free interface.

Heck yeah.

http://www.google.com/talk/index.html

1 comments - Posted by Joe Rinehart at 6:32 AM - Categories: Off Topic

Aug 23 2005

Robertson: Kill Chavez...God: Thou shalt not...what again?

Normally I avoid the political, but Apache Ant is chugging along, and a news story at Bloomberg infuriated me.

Pat Robertson, head of the Christian Broadcast Network, has stated that the US should kill Hugo Chavez (preseident of Venezuela).

While there may some legitimate reasons for a regime change down there, I think it's worth pointing out a few flaws:

1. Robertson leads a fundamentalist (Bible = Word of God) movement in the U.S. So which part of "Thou Shalt Not Kill" is open to interpretation?

2. "We don't need another $200 billion war to get rid of one strong-arm dictator," Robertson said. Does that mean that you can put a price tag on violating one of the ten rules you base your faith on? Just to really tweak you, Pat, the Catholic church tried this one (see: indulgences, Enchiridion).

3. Robertson said that Chavez is going to make Venezuela a "launching pad for communist infiltration and Muslim extremism all over the continent." I think Robertson should spend some time meditating on his own actions: serving as a launching pad for capitalistic opportunism (see: using CBN funds to help his diamond mining operations) and Christian extremism (really, if Chavez was Christian, do you think Robertson would have said this?).

14 comments - Posted by Joe Rinehart at 8:04 AM - Categories: Off Topic