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
view plain print about
1<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
view plain print about
1<cfdump var="#$${Variable}#">
2<cfabort showerror="dumping arguments $${Unique Value}" />
Trigger: fun
Purpose: create a cffunction
view plain print about
1<!---     Date: $${DATE} Usage: $${Hint} --->
2<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}">
3    
4</cffunction>
Trigger: get
Purpose: create a cffunction using a 'getter' pattern
view plain print about
1<!--- Date: $${DATE} --->
2<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}">
3    <cfreturn variables.instance.$${Variable}/>
4</cffunction>
Trigger: set
Purpose: create a cffunction using a 'setter' pattern
view plain print about
1<!--- Date: $${DATE} --->
2<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}">
3    <cfreturn variables.instance.$${Variable}/>
4</cffunction>
Trigger: getset
Purpose: create an argument declaration for a cffunction
view plain print about
1<!--- Usage: Get$${Variable} / Set$${Variable} methods for $${Variable} value --->
2<cffunction name="get$${Variable}" access="public" output="false" returntype="$${Return Type:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid}">
3    <cfreturn variables.instance.$${Variable} />
4</cffunction>
5
6<cffunction name="set$${Variable}" access="public" output="false" returntype="void">
7    <cfargument name="$${Variable}" type="$${Type:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid}" required="true" />
8    <cfset variables.instance.$${Variable} = arguments.$${Variable} />
9</cffunction>
Trigger: qp
Purpose: create a cfqueryparam tag definition
view plain print about
1<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:

view plain print about
1{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

There are no comments for this entry.

Add Comment Subscribe to Comments

7/9/07 11:58 AM # Sez Rob Wilkerson

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}" />


7/9/07 12:04 PM # Sez Ryan Stocker

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?


7/9/07 1:20 PM # Sez Brian Kotek

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!


7/9/07 4:46 PM # Sez Peter Bell

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!


7/10/07 12:06 PM # Sez Aaron Longnion

thanks for sharing! Also, remember to include void as a returnType choice for cffunction


7/19/07 3:51 PM # Sez Larry C. Lyons

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 />


10/28/07 7:56 PM # Sez Jim Priest

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)


Add Comment Subscribe to Comments