Seven snippets for highly effective developers

I like to think a lot about Rapid Development. Programming I find to be very enjoyable. I enjoy thinking around problems and designing proper solutions. I also enjoy adding processes and techniques that allow me to write better code faster. Today, we will focus on using snippets in CFEclipse to develop in a rapid fashion.

Snippets, put simply, are code segments that can be customized and inserted into your source code with a minimal of effort. Often we need to write a block of code following a particular pattern, such as get/set methods. We then locate a similar block of code, copy it, paste it into the new code then change the variable names and other bits to fit the idiom. Rather than this somewhat error prone technique, we can use a snippet.

Below are my top 7 snippets that I use on a regular basis. Feel free to modify each to represent your stylistic needs.

Trigger: arg
Purpose: create an argument declaration for a cffunction
<cfargument name="" type="$${Type:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid}" required="$${Required:true|false}"/>
Trigger: da
Purpose: Dump a variable and halt processing. Also puts the Unique Value into the show error attribute of cfabort
<cfdump var="#$${Variable}#">
<cfabort showerror="dumping arguments $${Unique Value}" />
Trigger: fun
Purpose: create a cffunction
<!---    Date: $${DATE} Usage: $${Hint} --->
<cffunction name="$${Function Name}" output="false" access="$${Access:public|private|package|remote}" returntype="$${Return Type:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid}" hint="$${Hint}">
   
</cffunction>
Trigger: get
Purpose: create a cffunction using a 'getter' pattern
<!--- Date: $${DATE} --->
<cffunction name="get$${Variable}" access="$${Access:package|public|private|remote}" output="false" returntype="$${Return Type:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid}">
   <cfreturn variables.instance.$${Variable}/>
</cffunction>
Trigger: set
Purpose: create a cffunction using a 'setter' pattern
<!--- Date: $${DATE} --->
<cffunction name="set$${Variable}" access="$${Access:package|public|private|remote}" output="false" returntype="$${Return Type:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid}">
   <cfreturn variables.instance.$${Variable}/>
</cffunction>
Trigger: getset
Purpose: create an argument declaration for a cffunction
<!--- Usage: Get$${Variable} / Set$${Variable} methods for $${Variable} value --->
<cffunction name="get$${Variable}" access="public" output="false" returntype="$${Return Type:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid}">
   <cfreturn variables.instance.$${Variable} />
</cffunction>

<cffunction name="set$${Variable}" access="public" output="false" returntype="void">
   <cfargument name="$${Variable}" type="$${Type:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid}" required="true" />
   <cfset variables.instance.$${Variable} = arguments.$${Variable} />
</cffunction>
Trigger: qp
Purpose: create a cfqueryparam tag definition
<cfqueryparam value="##" cfsqltype="cf_sql_$${CF SQL Type:bigint|bit|blob|char|clob|date|decimal|double|float|idstamp|integer|longvarchar|money|money4|numeric|real|refcursor|smallint|time|timestamp|tinyint|varchar}">

These seven snippets are included in a zip file. You may download it by clicking the 'download' link at the bottom of this post. If you already have snippets, then DO NOT Copy over keyCombos.properties. The other 7 files can be added in to the directory with little chance of conflict. You will have to manually edit each snippet to put in the trigger text and the name/description. (You *COULD* try to merge the keycombos.properties files, but I assume no liability)

To install, open up your workspace directory and unzip the files in the following directory:

{WORKSPACEROOT}.metadata/.plugins/com.rohanclan.cfml/snippets

For more information on tweaks, configurations, snippets and other CFEclipse information, please have a look at the CFEclipse Trac Wiki

Also, a pragmatic tutorial on how to use snippets

Related Blog Entries

Comments
I've never seen anyone else include an abort call in their dump snippet. I rarely dump information without it. I also found that I dump variables so much that I need a label to keep it all straight so I have the following modifications:

<cfdump var="#$${Variable}#" label="$${Variable}" expand="$${Expand:Yes|No" />
<cfabort showerror="dumping arguments $${Unique Value}" />
# Posted By Rob Wilkerson | 7/9/07 11:58 AM
Thanks for the snippets!

BTW, I had to copy mine into org.cfeclipse.cfml (instead of com.rohanclan.cfml) - do different versions of CFEclipse use different directories?
# Posted By Ryan Stocker | 7/9/07 12:04 PM
Great post Dan! I have used very similar snippets myself for a long time. I can't believe I never thought about posting them in a blog entry like this!
# Posted By Brian Kotek | 7/9/07 1:20 PM
Very cool Dan - thanks. I also had similar arg and method snippets, but I couldn't be bothered to create the enums, so thanks for that!
# Posted By Peter Bell | 7/9/07 4:46 PM
thanks for sharing! Also, remember to include void as a returnType choice for cffunction
# Posted By Aaron Longnion | 7/10/07 12:06 PM
just an addenda to your cfdump snippet. I found if I don't include a <cfset request.cfdumpinited = false> I lose most of the formatting for the table that the cfdump uses. So I use the following for my cfdump snippet:

<!--- reset dump variable in request scope --->
<cfset request.cfdumpinited = false />
<cfdump expand="true" label="$${dumpLabel}" var="#$${variable}#" />
<cfabort />
# Posted By Larry C. Lyons | 7/19/07 3:51 PM
And remember if you are using CFEclipse - you can share snippets with SnipEx...

http://cfsnippets.org/

Or you can setup a local SnipEx server (see the CFEclipse wiki)
# Posted By Jim Priest | 10/28/07 7:56 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001. Contact Blog Owner