An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

cfmljure - using Clojure from CFML

September 3, 2010 ·

If you follow me on Twitter, you'll have seen me posting about Clojure quite a bit recently. I really like the simplicity and elegance of Clojure. I like the function programming style. I like that it's a dynamic scripting language. I like that it can also be compiled to JVM bytecode and used in any mixed-language project on the JVM.

About a month ago I helped someone get some Clojure code compiled and integrated into CFML, like any other Java-based project, but that set me thinking about being able to just use raw Clojure scripts from CFML without needing to go thru the compilation and deployment process. I asked on the Clojure mailing list how to load and run scripts from Java and that gave me what I needed to create a simple CFC wrapper that lets you write Clojure scripts and dynamically load and execute them from inside CFML.

That's how cfmljure was born on github! It's very early days for the project - I consider this an 'experimental' version - but I've created a Google mailing list for cfmljure and it's also listed on RIAForge). I don't expect it to be crazy popular (like FW/1 for example) but I expect to use it on production projects and thought it would be good to put out there for others to experiment with and provide feedback on.

Things on the roadmap include making it more Leiningen friendly (Leiningen is the de facto standard build tool for Clojure and it definitely makes life simpler) as well as figuring out how to access Clojure variables from CFML. I may even try to figure out how to pass CFCs into Clojure and have them be callable (Clojure can call Java but I'll probably go the route of a Clojure proxy function initially).

Have fun with it! Join the Google Group if you have questions / problems / suggestions!

Tags: cfmljure · clojure · coldfusion · oss

5 responses

  • 1 TJ Downes // Sep 3, 2010 at 8:39 AM

    Hey Sean, this is very cool. Thanks for building tools like this for the community. It's an excellent way for CFML developers to break into new languages more easily, which is critical these days.
  • 2 Dan Vega // Sep 3, 2010 at 9:57 AM

    Forgive the ignorant question here Sean but I am interested so I figured its worth asking. While the idea of combining the 2 technologies is really cool, do you have any examples of why you would use this? A couple examples to show how this could benefit developers would be really cool. Thanks and keep up the innovation!
  • 3 Sean Corfield // Sep 3, 2010 at 12:47 PM

    @Dan, mostly I'd encourage CFML developers to dig into new languages that 'think differently' so they get a new / improved perspective on solving problems. I've recommended things like Haskell and Prolog as being 'out there' and really helping developers think differently. Clojure is a JVM-based language so we have the option to use it easily from within CFML so we can dip our toes into the functional programming world that I would have previously suggested something like Haskell for (which didn't interop with CFML).

    Functional languages are really good at working with collections of data, composing and applying small pieces of logic to implement complex processes on homogenous data sets. With the inherent immutability and potential for parallelism, this offers a safer and, on multi-core systems, potentially much faster way to process data.
  • 4 Dan Vega // Sep 3, 2010 at 1:18 PM

    Awesome, thanks Sean. I just didn't know if you originally wrote this to solve a specific problem. I couldn't agree more though, learning how to attack problems in other languages is crucial for growth as a programmer!
  • 5 Sean Corfield // Sep 3, 2010 at 4:36 PM

    @Dan, well, I do plan to use Clojure with CFML must as I already use Groovy and Scala: to address specific performance and / or complexity issues that crop up in large systems.

    For example, I'm using Scala with CFML right now to implement some heavy lifting with XML where CFML just can't match the performance needed. Scala's "actors" let me do safe concurrency and XML is a native data type - I get somewhere between 10x and 20x improvement with Scala over CFML for this problem. But I wouldn't want to write all my backend in Scala.

    Same with Clojure: I can see using it for specific data manipulation tasks where the equivalent CFML might be too complex or too slow (or both).