<!---
some validation on formats:
- should be at least 3 characters
- should be at least two alphabetic
- optionally followed by - and two or three alphabetic
- optionally followed by _ and at least 3 alphabetic
--->
<cfif len(outputSalesOrg) gte 3 and
REFind("^[A-Z]{2,}(-[A-Z]{2,3})?(_[A-Z]{3,})?$",outputSalesOrg) eq 1>
<!--- it's probably valid --->
<cfelse>
<cfset raiseException("INVALID","Unknown sales organization (#arguments.inputSalesOrg#) encountered",arguments.filename) />
</cfif>
The comment adds value because the code is compact and non-obvious (but this is a classic use of regex). I wrote the comment first and then wrote the code. However, since the code in this case is non-obvious, I left the comment in place.
Feel free to comment here or over on Kay's blog (to keep the thread in one place, if you want).some validation on formats:
- should be at least 3 characters
- should be at least two alphabetic
- optionally followed by - and two or three alphabetic
- optionally followed by _ and at least 3 alphabetic
--->
<cfif len(outputSalesOrg) gte 3 and
REFind("^[A-Z]{2,}(-[A-Z]{2,3})?(_[A-Z]{3,})?$",outputSalesOrg) eq 1>
<!--- it's probably valid --->
<cfelse>
<cfset raiseException("INVALID","Unknown sales organization (#arguments.inputSalesOrg#) encountered",arguments.filename) />
</cfif>

5 responses so far ↓
1 Brandon Harper // Feb 28, 2006 at 11:23 AM
I usually just do quick inline comments with my initials to explain anything which is tricky, especially if it's some sort of very proceedural process, or anywhere that a bunch of things happen on one line of code.
I am kind of bad about writing lines of code like this as a method sometimes just to save some typing, but I do usually comment each one of them (snipped from a cffunction):
<!--- BH: Transforms a report struct from the ReportBean into WDDX and sets it within the ReportBean itself --->
<cfreturn getReportBean().setReportWDDX(Struct2WDDX(getReportBean().getReportStruct())) />
(I wonder if that code will show up in a comment or not)
2 Lola Lee Beno // Feb 28, 2006 at 11:35 AM
That said, I try to make my comments useful and not too excessive. Where I put in pseudocode, I go back later and revise these into comments that explain what is occured, or remove the text after writing a summary at the top.
3 Sean Corfield // Feb 28, 2006 at 2:38 PM
[!--- BH: Transforms a report struct from the ReportBean into WDDX and sets it within the ReportBean itself ---]
[cfreturn getReportBean().setReportWDDX(Struct2WDDX(getReportBean().getReportStruct())) /]
As for the trim(), I omitted the code (elsewhere in the app) that trims the values I'm getting from an XML message. The code is part of Macromedia's order management system that receives sales orders as XML via file or JMS. As the XML is picked apart, every field is trim()'d so that the rest of the app doesn't have to deal with that.
FWIW, the function begins with:
[cfset outputSalesOrg = arguments.inputSalesOrg /]
Then it does a bunch of validation and transformation of the sales org code to canonical form before returning it. The function is called getCanonicalSalesOrg().
4 Sean Corfield // Feb 28, 2006 at 2:39 PM
5 Chris Stoner // Mar 1, 2006 at 5:21 AM
Leave a Comment