Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 152369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:36:41+00:00 2026-05-11T09:36:41+00:00

I am reorganizing my ColdFusion directory structures and am curious about how experienced CF

  • 0

I am reorganizing my ColdFusion directory structures and am curious about how experienced CF developers are organizing libraries of smaller cffunctions.

I am not as curious about elaborate components (objects) as I am about the dozens of little utility functions we all build up over time.

  • Do you use a large single file with cffunctions and cfinclude it?
  • Do you use a large single file as a cfcomponent and call creatobject/cfinvoke?
  • Do you put each utility cffunction in its own cfc and call createobject/cfinvoke?
  • Do you use the cfimport taglib syntax?
  • Do you use the CustomTags or cfmodule?
  • Do you have a better way?

Since I don’t like verbose syntax I have been just cfincluding a lib.cfm that has a bunch of common cffunctions in it. I may refactor them to grouped cfcs I can createobject on just to have better isolation on variable scopes.

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:36:42+00:00Added an answer on May 11, 2026 at 9:36 am

    This is a reprint of a blog post I did back on June 13, 2007. I’ve been using this method for quite sometime and it works great! YMMV.

    Who doesn’t like user-defined functions (UDFs)? If you have done any programming, chances are that you have used them extensively. The biggest problem that people have with them is how to include and organize them in your application.

    What I’ve found that most people do is create a Utils.cfc or UDFs.cfc and cut and paste their UDFs that they want to use into the component as demonstrated below:

    <!--- UDFs.cfc ---> <cfcomponent output='false'>  <cffunction name='init' access='public” returntype='Any' output='false'>   <cfreturn this> </cffunction>  <cffunction name='myUDF1' access='public' returntype='Any' output='false'> </cffunction>  <cffunction name='myUDF2' access='public' returntype='Any' output='false'> </cffunction>  </cfcomponent> 

    Once you have all the UDFs that your application will be using pasted into your component, you will need to make the UDFs available to your application. Almost everyone I’ve seen does this loading by the component into the application scope. The following line is placed into the onApplicationStart() if you’re using Application.cfc or by just adding it into the Application.cfm if you’re using that:

    <cfset application.functions = CreateObject('component', 'udfs').init()> 

    Whichever one you’re using, Application.cfc or Application.cfm, the results are the same; all your UDFs are available to your application and you can use them freely throughout. The only difference is what variable name you use. I use application.functions, some use application.utils or application.udfs; doesn’t matter, again, the results are the same.

    There is one problem that I have with this approach though, it’s cumbersome and the UDFs component will get huge. The problem with having such a huge component file is editing it becomes a nightmare since scrolling through thousand of lines of code isn’t very fun and also I’ve noticed that CFEclipse bogs down on huge files. Sure code collapse does provide some relief but there has to be a better way.

    What I wanted was to just have one file for each UDF I was using and a way for my application to load them automatically. The reason behind this was so that if I needed to edit myUDF1, I could just open the file myUDF1.cfm and edit what I needed. I also wanted to be able to grab UDFs from CFLib.org and just drop them into my application without having to edit anything. If I ever needed to remove a UDF from my application, it would be as easy as deleting the UDF file and reinitializing my application.

    To accomplish what I wanted, I modified my UDFs.cfc to 11 lines of code:

    <!--- UDFs.cfc ---> <cfcomponent output='false'>    <cfset variables.udfdir = GetDirectoryFromPath(GetCurrentTemplatePath()) & 'udfs'>   <cfset variables.q = ''>    <cffunction name='init' access='public' returntype='Any' output='false'>     <cfreturn this>   </cffunction>    <cfdirectory action='list' directory='#variables.udfdir#' filter='*.cfm' name='variables.q'>    <cfoutput query='variables.q'>     <cfinclude template='udfs\#name#'>   </cfoutput>  </cfcomponent> 

    So what exactly is going on?

    In a nutshell, here’s what’s happening: I have a directory called udfs in the same directory that I have my UDFs.cfc. This is the directory that I put all of my UDF CFM files. What the UDFs.cfc does is scan this directory when it is called and automatically includes each CFM file it finds. Thus it automatically loads any UDFs in the UDFs folder into itself (commonly called a ‘mixin’).

    So my goal is reached! I have each UDF in its own file so I don’t have to scroll through a huge component file to find it. I can now open and edit it easily. By just looking at the directory, I know what UDFs my application is using. I can automatically add a UDF from CFLib.org by just saving the text from browser into a file in the directory. Plus if I no longer need to use the UDF in my application, I simply delete the file from the directory and it’s removed from my application during the next re-init. All this is done without having to touch the main UDFs.cfc file.

    Below is an example of what one of the UDF CFM files looks like. The file is called fullLeft.cfm and resides in the UDFs directory.

    <!--- fullLeft ---> <cffunction name='fullLeft' access='public' displayname='fullLeft' returntype='string' output='false'>   <cfargument name='str' type='string' required='true'>   <cfargument name='count' type='numeric' required='true'>   <cfif not refind('[[:space:]]', arguments.str) or (arguments.count gte len(arguments.str))>     <cfreturn Left(arguments.str, arguments.count)>   <cfelseif reFind('[[:space:]]',mid(arguments.str,arguments.count+1,1))>     <cfreturn left(arguments.str,arguments.count)>   <cfelse>     <cfif count-refind('[[:space:]]', reverse(mid(arguments.str,1,arguments.count)))>       <cfreturn Left(arguments.str, (arguments.count-refind('[[:space:]]', reverse(mid(str,1,arguments.count)))))>     <cfelse>       <cfreturn left(arguments.str,1)>     </cfif>   </cfif> </cffunction> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 72k
  • Answers 72k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer No, because it's not SSH using your config files, but… May 11, 2026 at 1:43 pm
  • added an answer Why are you getting 500 Syntax errors? Remember that unlike… May 11, 2026 at 1:43 pm
  • added an answer I am not aware of any protocol which does this… May 11, 2026 at 1:43 pm

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.