|
| Web News |
Profit at India's HCL Technologies doubles on strong... Indian software company HCL Technologies Ltd. said Monday its profit in the most recent quarter doubled from a year ago, thanks to a slew of new outsourcing orders that more than offset the impact of a stronger rupee.
Wipro's CEO Sees India's Global Future Entering the fortified, tree-lined grounds of software giant Wipro Technologies' sprawling headquarters campus here is a sharp reminder of how India's first global success story is still flourishing. The chaos and noise on...
Indian, Chinese firms 'most aggressive' about IT Indian and Chinese companies see themselves as the "most aggressive" in the Asia-Pacific region in adopting information technology (IT), said a research house survey released Monday. Indian companies were found...
Gameshastra short-listed for tech award Gameshastra, India's largest game services provider, Monday announced that it had been short-listed as one of the top 200 contenders for the Red Herring 100 Asia 2007 awards. 'It is an honour to achieve this...
Airtel Broadband Users Get Google Bharti Airtel Broadband and Telephone Services (B&TS), and Google have teamed up to bring Web-based services to Airtel Broadband Internet customers. As per the agreement, Airtel will offer it's Broadband customers a portal that includes Google search; Gmail with...
|
| Recent WebProNews Articles |
Cringely Details Why Your Broadband Stinks The $200 billion boondoggle that was meant to deliver high speed digital services to the home by the year 2000 instead left America running to stand still in the world of broadband delivery. Tech pundit Robert X. Cringely took a deeper look at something we've noted previously.
Viacom, Google A Father-Son Fight? Once new Google employee Philippe Dauman Jr wraps up his summer vacation and takes up his new post, Googlers may want to keep any negative opinions of Viacom CEO Philippe Dauman Sr to themselves.
Google Starts Shared Storage Service Google users can boost their available storage for Gmail and Picasa Web Albums to as much as 250GB for an annual fee. Hours after Microsoft opened its Windows Live SkyDrive online storage product beta to all comers, Google followed up with the announcement of...
Scholars Push For Search Engine Regulation Here's an idea sure to start some fires: Is it necessary to consider government regulation of search engines? Please hold your throwing-stones until the end of the presentation. A technologically advanced century...
Don't Try Crawling Google News Comments The newest feature on Google News - comments solicited from participants in a news story - won't be part of anyone else's news. When AOL broke down its subscriber walls, it looked like the end of walled garden...
|
|
08.13.07 Coldfusion: Structure As An Argument By Raymond Camden
Joel asks:
This is just a quick "best practices" question about CFC's, specifically regarding arguments.
Let's say that I am creating a book entry in my database. My form has 3 simple fields--title, author, number of pages. Easy enough.
My question is what a "best practice" for dealing with this scenario would be. Although I am still pretty new to CFC's, I have learned that bundling information as structs to be used in the CFC can be extremely useful, especially when the contents of said struct are dynamic.
But what of known values? Obviously, when invoking the component I could bundle title, author and number of pages into a struct and look for that in the CFC. However, in doing this, it would seem that the various specifications for individual arguments (i.e., 'required', 'type', etc.) would be lost as these could only be applied to the expected struct. Also, it seems that the whole idea of encapsulation is compromised to an extent as the specificity of the arguments being expected is reduced and made more generic (e.g., the struct).
On the other hand, when dealing with ridiculously long forms full of known values, loading them all into a struct would potentially save some coding on the CFC side.
So just in case folks don't quite get what Joel is saying - he is talking about two options to pass data to a CFC. You can either use a set of arguments or have one argument that is a struct. Consider the following two examples:
So as you can see - Joel is right. In the second example, you no longer have any real clues as to what the UDF is using, outside of one structure. You also lose the validation that helpfully double checked name and age. So in my simple example, I definitely think Joel is right - using "real" arguments does make sense. But as he points out - what about a method that takes many more attributes? It would be simpler, for example, to be able to pass the FORM scope as a structure and not use a lot of...
form.name,form.age,form.foo,form.goo,form.rustillreading
Luckily there are a few things we can to make this easier.
First off - don't forget that you can use CFINVOKE and CFINVOKEARGUMENT syntax. While this results in more typing (potentially), it does make things readable. And you can use these tags without typing until the cows come home. Consider this example:
This example is equivalent to the previous form - just more inline and less typing, but again if you did want to skip certain form fields you would not be able to.
So all in all - I agree with Joel here and hopefully the examples above will show ways to mitigate cases where you have to deal with a large number of attributes.
Comments
About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com
Raymond Camden is Vice President of Technology for roundpeg, Inc. A long
time ColdFusion user, Raymond has worked on numerous ColdFusion books
and is the creator of many of the most popular ColdFusion community web
sites. He is an Adobe Community Expert, user group manager, and the
proud father of three little bundles of joy.
|
|