Why? Because the code checks for the *existence* of application.foo, not whether application.foo is initialized. By doing create-and-initialization in one expression, you avoid getting into the state where you have a created-but-not-initialized object.

Think this doesn't happen in real code? This was one of the thread-safety fixes that had to be made to Mach II between 1.0.8 and 1.0.9: in 1.0.8 the AppLoader init() method did not return "this" and the initialization code in mach-ii.cfm was not thread-safe because it couldn't chain the methods - 1.0.9 fixed that with a three-line change (change init()'s returntype=, add <cfreturn this /> and chain the init() call onto the createObject() call).

So you are suggesting that we should create best practices for every example of where an application was poorly coded? No, then why this particular example? Isn't this a situation where the lack of constructors is causing problems and you are creating a best practice as one particular workaround? Wouldn't it be better to advocate in this case thread safety as a best practice? Does that achieve the same goal without polluting the practice with a stylistic concern.

In the end, we are talking about doing to thing with one expression as opposed to two. Whatever problem a practice is trying to solve, the practice will be equally correct whether the expression is in one line or two.

-Matt

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to