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

Download Download

Related Blog Entries

There are no comments for this entry.

Add Comment Subscribe to Comments