Showing posts with label ColdFusion. Show all posts
Showing posts with label ColdFusion. Show all posts

Monday, February 28, 2011

ColdFusion musings on variable scope

Well I've come across the use of using local to reference all local variables in a function and some phobia to use var for declaring local function variables. I must admit I find this weird. I'm an avid fan of using var but that probably comes from my development in ActionScript and other languages I've developed in such as Java, C/C++. To me the phobia comes directly from the dreaded "memory leak" where you have the variable scope referenced instead of the scope relative to the function (local). This seems like a flaw in ColdFusion that a variable which is not scoped can appear to be causing the developer to have memory headaches. But to me I think developers should be more wary of what they are coding. The use of the local structure just seems like a lame hack which bloats the amount of code you write. ColdFusion is on it's own when comes having such a verbose way of referencing local scope variables. So really this is an issue of scope and a better solution would be to make it that you have to reference variables not in the local scope explicitly instead of the of reverse... well that being said people also just go and ahead an explicitly reference all variables which means a lot of typing. I don't care if you have intelli sense it means more typing no matter what.

So I do hope in the next version of ColdFusion they solve this problem because it makes code look ugly and longer to write... two things which ColdFusion is suppose to be working against. And yes I love my but you need a hand.

My feelings towards cfscript are similar to Ben Forta's. Read his post on I Am Not A Fan Of CFSCRIPT

Tuesday, November 3, 2009

Earlest time to call a RemoteObject?

I was doing some investigation on how best to retain your session. A lot of Flex applications don't utilize session management especially in the case when the app is restarted by a refresh or a new window. Which then the users are faced by a annoying login window even though the server has retain the session information which negates this need to re-login. But before I really go into that I got sided tracked looking into when is it best or the earliest time you can send off a request to get session information. This is an interesting question with an obvious answer as well. But I wanted to really understand why.

To do the call I'm using RemoteObjects with ColdFusion as the destination. The ColdFusion CFC is fairly basic just returning an array with the JSessionID. All of this will complete quickly to negate any long server processes. Ideally in a production environment I would use a session structure to return to speed things up.

So I wrote some basic ActionScript code to connect and call the CFC. I first tried calling it from preinitialize call. The call worked but it took ~100ms to complete which was troubling which it was just calling a server on my machine. I then did a quick speed test of calling the RemoteObject and was able to call it and get a responds in < 1ms so something else was at play here. I then thought about maybe I should push the call further up the process since preinitilization was happening at ~200ms since application start but I wanted it to start earlier.

Preloader here I come! The preloader was being called at ~100ms and I was really happy but then I hit a road block...
[FaultEvent fault=[RPC Fault faultString="[MessagingError]" faultCode="InvokeFailed" faultDetail="null"] messageId="33578681-51C7-A64A-7C04-B829D52F7A4C" type="fault" bubbles=false cancelable=true eventPhase=2]
This is a puzzling error message since it doesn't give me any reasons why the InvokedFailed? If I called the call the RemoteObject later in the Flex life cycle it worked so seemed strange that it would fail at this point. So bring on Flex Debugger! I got it down to one call which was causing an exception and it was the mx.messaging.config.SeriviceConfig.xml getter. It was being called before it had been set with the complied flex-services.xml which seems strange that it didn't have this embed. Then I started to look into when it got set so and found that it hadn't been called by SystemManager to initialize this value. So even though the complier embeds the value of the flex-services.xml it needs to be set at initialization by the SystemManager.

So what does this boil down to? You can't call RemoteObjects prior to the start of Application preinitialization process since the SystemManager has not completed its own initialization process. Remember that the Application is a child of the SystemManager so following the Flex startup rules you shouldn't do anything with it until initialization of the SystemManager is complete. So using the Application preinitialization/preinitialize event is the best/earliest time to do a call to the server to get data using RemoteObjects.

Oh and the other point about the call taking so long ~100 ms... well I put that down to the additional things that occur at start up. A lot happens when a component/Application is created ;-)

Thursday, December 18, 2008

Centaur language features welcome

Well as new ColdFusion Centaur is in the forge being crafted by Adobe developers with all sorts of goodies I rub my hands with glee. I'm really happy to finally see you will be able to define components in cfscript! Also getters and setters making the fold which are well overdue! Will be interseting to see how much closer they make cfml and cfscript since for a long time cfscript has been left out in the cold.

Bolt out of the ColdFuion blue comes a new IDE which I hope will kick ass when developing apps. Adobe did a great job with the Flex IDE and I'm expecting the same developer benefits to come availialbe to ColdFusion. Yeah we've had CFEclipse which really leveraged Eclipse developer features but never cut the mustard for me. For too long Dreamweaver was really the best CF editor and it wasn't a good editor for developing applications. So I'm wishing and hoping that Bolt will be amazing!

These are great features but they are so overdue it is not funny. I'm almost certain if we had an IDE and the language features in this release in 6.1 ColdFusion developers would be developing very differently today. Perfect example is the poor cfinterface tag which seems to constantly underfire. Though it's not that the concept of interfaces is bad and I really like them. Just that there is not enough development tools to support it in current shape of CF but if we had some more language features and tools to hook into them I doubt there would the debate there is. Though as the saying goes "Better late than never..."

Sunday, September 28, 2008

ColdFusion Daylight saving bug (feature?)

Well just got back from the weekend to find a nice bug with a date time created in a query.

Date value passed to date function CreateDateTime is unspecified or invalid.

This was pretty strange since this function had been called for the last 3 months each day so obviously was a daylight savings issue. I pinned it down to on CreateDateTime function:

CreateDateTime(2008, 9, 28, 2, 0, 0);

What the issue is that this is an invalid date time since this time does not exist but honestly throwing an invalid date error is pointless. This is noted in the ColdFusion LiveDocs in the comments. But in hindsight I should check for this date time to make the query more robust. Though checking the datatime is valid every time I create a date time is a waste of processing power in my mind.

So the only solution available is a try{...} catch(){...} solution which I think is poor.

try {
dateTime = CreateDateTime(2008, 9, 28, 2, 0, 0);
} catch(Any exception) {
// Blank the result - Daylight saving issue
dateTime = CreateDateTime(2008, 9, 28, 0, 0, 0);
}

Sunday, September 7, 2008

Installing ColdFusion on OSX -

Well must admit I installing ColdFusion has always been pretty simple but this time when I was installing it on my MacBook Pro I found I could not set up the web connectors. It just wouldn't let me choose the directory which Apache was in and this was simply strange and annoying. It worked fine when I installed it using ColdFusion's own web server. I then tried hopelessly to configure from that point but again no luck. By this point I gave up and went back to my virtual machine of Vista running IIS/ColdFusion. I must admit VMware Fusion is really sweet product though I wanted to run Apache/ColdFusion in OSX not on a VM which is really a pain in the neck to use since you have start it etc. I'll blog later on VMware's Fusion and how much I like it :-)

So I ended up around at a mates place trying to learn more about Apache and tried again installing ColdFusion. What I found in this attempt is that I'm running a 64bit Intel Duo 2 processor and the Apache installation was also 64bit. I was like... Yeah!! ...but also thinking who forgot to tell me my MacBook Pro has a 64bit processor? I had previously tried to figure out if my processor was 32/64bit but OSX doesn't give any details away so I had assumed it was 32bit.

After this moment of bliss between my MacBook Pro and I, I downloaded the 64bit installer of ColdFusion and all went well! This is a long story for a simple installation issue. Saying this there are no obvious messages from the ColdFusion installer (or others I might add) to say you're using a 32bit installer when you should or consider the 64bit installer.

Saturday, June 7, 2008

ColdFusion 8 Ajax

Just watch Raymond Camden's presentation on ColdFusion 8's new Ajax features. I must admit I was blown away with how easy it to create Ajax features with a few lines of code. I can't say I'm a fan of Ajax since I'd prefer to do it Flex but I do understand Ajax does have it's place. It is really great to have the power to create a datagrid with ease with ColdFusion. So you don't need to learn an Ajax lib and just use this new ColdFusion feature like any other ColdFusion tag.

Friday, May 25, 2007

Web services

Been working hard at project at work and one annoy thing I found with ColdFusion (CF) is that it doesn't refresh the web service stubs automatically. So what this means that if you change the web service CF still thinks its the same and you get an exception. This is a real pain when your developing but fine for production since you don't expect the web service to change. I found a way to refresh webservices thanks to Brandon Purcell (http://www.bpurcell.org/index.cfm).

Key aspects to refresh from the caller is can be found here http://www.bpurcell.org/blog/index.cfm?mode=entry&entry=965