Pages

Tuesday, February 28, 2012

My Argument Against ColdFusion Sucks & Other Related Putdowns

While I was driving home last week I listening to the "Hearding Code" podcast with Chris Williams (the organizer of jsconf) and I had a small revelation.   Chris brought up how coders will use up one bad experience with a language to completely write it off and publicly denounce the it every chance they get.  Raise your hand if this immediately makes you of think of ColdFusion.   Me too.

Then I started thinking, JavaScript is one of the hottest languages around right now, and for good reason, it has evolved tremendously from where it was in the late 90's.  Does that remind you of anything?  If you are a ColdFusion developer it should seen very familiar to the language you use every day.  Anyone who writes modern ColdFusion code will likely cringe at the code they wrote back in the pre-MX days, just like a lot of the JavaScript developers did in the pre-jQuery/Dojo/Sencha/Prototype/MooTools days.

Next time we hear someone publicly call out ColdFusion for a one bad experience they've had with an app that was written in the late 90's early 2000's lets remind them about JavaScript and the many bad experiences we've all had with it back in its early days.  Lets also remind them how it has evolved into one of the most popular languages in the world.

ColdFusion, in my opinion,  has evolved just as much as JavaScript.  We have a great testing framework in MXUnit, lots of great MVC frameworks to chose from, and a number of other great frameworks that help us be productive such as Validate This, ColdSpring, Hoth, and Hyrule to name a few.  These are all advanced programming frameworks that weren't around in the early days.  In additon ColdFusion itself has also come a really long way as a programming language.  We can how write code in a way that many programmers consider much more elegant and terse with the script updates in ColdFusion9.   We can also use really powerful techniques like onMissingMethod, dynamic typing, and treating functions as first class citizens.  We have ORM capabilities baked right in the framework, how cool is that?!?

While agree it has taken ColdFusion a long time to get this far while languages like Ruby, Python, and even PHP have progressed at a bit faster rate its good that we have gotten where we are.  With the upcoming release of Zeus ColdFusion will take another step further with HTML5 controls built in, RESTful interfaces, closures, and a bunch more exciting features.  These are exciting times to be a ColdFusion developer and I hope that we can advocate the language moving forward by drawing parallels to other languages, like JavaScript,  that have had rough beginnings but are now considered "cool" languages.

Monday, February 20, 2012

Using ColdFusion 10's Function Data Type To Create a Map Function

In functional programming a map function is a way to create an array by passing each element of the array into a function.  Mapping functions are very commonly used in languages like Ruby, Python and JavaScript.  ColdFusion acts more like JavaScript in this respect where a Map is not a native function, however it is easy to implement.

Before I get into the code, lets take a look at how the map function works.   The method signature for map looks like this: public Array function map(Array arr, function fn). The map function takes and array and a function as parameters, and returns an array.  Each element in the array argument is passed into the function and the result is added to the result.

Without further adu, lets take a look a the code:



Running this code would produce this result:









Now this pattern can be applied anywhere you find yourself looping through an array and applying the same logic to each member of the array.

Friday, February 17, 2012

Changing the webroot of the ColdFusion 10 Beta (Zeus) Built In Web Server

If you run the ColdFusion built in web server on your local machine and want to keep your current webroot while playing with the Zeus beta here's how to change the web root:


  • Open coldfusion_install_location/cfusion/runtime/conf/server.xml
  • Scroll down to the end of the document where you see the line:  
<!-- Uncomment the line below to change the default web root or to add virtual directory
Make sure to replace <cf_home> with the absolute path to ColdFusion Home-->

  • Copy the last comment in the group of comments at the end, right before the line.  The line you want toc copy looks like (do not copy the beginning :  
<Context path="/" docBase="<cf_home>\wwwroot" WorkDir="<cf_home>\runtime\conf\Catalina\localhost\tmp" ></Context>

  •  Change the docBase attribute to your the ABSOLUTE path of the directory where you want your web root to be.  In my case it was /Applications/coldfusion9/wwwroot if you are on Windows this will start with a drive letter like c:\... or d:\...
  • Add aliases attributes to both the CFIDE directory AND the WEB-INF directory.  This step is extremely important, without it ColdFusion WILL NOT run.  To do this add a new attribute to the node called aliases.  Inside that attribute add the following text /CFIDE=/absolute_path_to_coldfusion_install_location/cfusion/wwwroot/CFIDE,/WEB-INF=/absolute_path_to_coldfusion_install_location/cfusion/wwwroot/WEB-INF  Again, if you are on Windows this will start with a drive letter like c:\ or d:\.  
  • This is what it looks like on my system (OSX):
<Context path="/" docBase="/Applications/coldfusion9/wwwroot" WorkDir="/Applications/coldfusion10/cfusion/runtime/conf/Catalina/localhost/tmp" aliases="/CFIDE=/Applications/coldfusion10/cfusion/wwwroot/CFIDE,/WEB-INF=/Applications/coldfusion10/cfusion/wwwroot/WEB-INF"></Context>

  • Restart ColdFusion10 and be happy.   

Wednesday, February 15, 2012

You Are Not the Language You Write Code With

Lately I've been thinking a lot about my career and what I'll think about when I reflect on it when I'm retired. Will I look at myself as a ColdFusion programmer?  Will I look at myself as a JavaScript programmer?  I'm pretty sure I'll just look at myself as a programmer.  This got me thinking about how others perceive me as a programmer.  Do others come to my blog and never read past the first two words of  "Ryan's ColdFusion and Web Development Blog"?  Am I automatically dismissed as a programmer because I primarily associate myself with ColdFusion?  I'd like to hope not but I'm sure there are more people that do than I'd like to admit.

This brings me to my point, a developer is not the language they prefer to code with.  A developer is defined by so much more than that.  I'd hire a good Python developer to write ColdFusion applications even if they've never even seen a line of CFML in their life.  A good developer will be a good developer in any language.

So what does define a developer if its not the language they write with?  For me its a few things, first its what they have given back to the programing community through their contributions to open source projects.  I'm not saying Java developers should go out and contribute to Ruby projects.  Its perfectly fine to stay in an area of expertise. The point here is that a developer that gives back by contributing to open source projects shows that they have a passion for writing software that helps others and for writing code in general.  Passion goes a long way to making a good developer.  

Secondly I think a developer can be defined by their thirst for learning new things.  The world of programming is always changing, it can be exhausting to think that the learning never stops.  It can also be exciting and fun.  I wake up each morning looking forward to learning something new, when this feeling stops I'll know its time to get into management.  A developer who doesn't embrase the ever changing landscape will quickly get left behind by others who are actively seeking new things to learn.

Lastly I think a developer can be defined by their willingness to teach and help others.  I'm not talking about speaking at user groups and conferences here.  Yes, those things take tons of time and preparation and do help many others.  However, they are also self-serving engagements.  There's nothing wrong with that, but its the simple truth.  Speaking in public is an ego and career boost for the speaker.  What I'm talking about is spending one on one time with another developer helping them solve a problem or helping them master a new technique.  There's no reward in that other than the self satisfaction of helping someone else.  That't the kind of programmer I want to work with.

Wednesday, February 8, 2012

The Great IDE vs Text Editor Debate: Why I Switched Sides

There are two types of programmers; those who prefer full featured IDE's and those who prefer a lightweight text editor.  I used to be firmly planted in the IDE camp happily opening CFBuilder, CFEclipse, or Aptana every morning to work on my ColdFusion, PHP, and Ruby projects.  Recently however, I have switched camps.  I now have SublimeText 2 and a Terminal open whenever I code and this post will try to explain why I made the switch.

In this corner, the IDE

Sears Mechanics Tool Kit
Let me start by defining what I believe an IDE is. To me an IDE is a prepackaged toolbox with many of the tools you'll need for a job.  Its a lot like the Mechanics Tool Tool Kit from Sears.  In it you get here all the tool necessary to complete the basic tasks a mechanic does.  Two things stand out here, what you don't get, and the fact that you have to lug around all these tools just to get to one single wrench.  Is that socket driver the highest quality tool you can buy at Sears?  Likely not.  Yes, CFBuilder has code insite and intellisence, however it was often a bit too slow and a bit too buggy for me, sometimes it worked, sometimes it didn't.  I never got the feeling that it was actually helping me code faster.  On the other hand knowing the names and types of arguments on my components is awesome and definitely something that I had to be willing to give up when making the switch to a text editor.  Guess what? I don't miss it one bit.

I also use SVN and GIT as my two primary means of source control.  While subclipse or subversive were nice, they rarely worked 100% of the time, especially when I made the switch to a Mac.  I had problems checking projects out where after going through the whole process of setting up the project eclipse would never bring any of the code from the repository so I'd have to start all over.  On my Mac it was a total crap shoot when I'd try to synchronize.  I also tried to use some of the SQL tools inside of Eclipse as well (I think I even blogged about the SQL Editor in CFBuilder once) but I never found them quite as useful as the external SQL tools that I regularly use.  Additionally I used the console view in my IDE quite a bit to write debugging output, this feature is nice, but is easily replaced by tailing a log in the terminal.

Lastly in order to support all of these areas of functionality an IDE needs to use lots of screen space.  When I'm coding I like to see two things: the folder structure of the project I'm working on and the code itself.  When I was using an IDE I found myself constantly readjusting the windows within my workspace.  Maximize the code, minimize the code, show the console, show the server, team synchronization view.  It was distracting to say the least.

Making the Switch


While I was happily coding in my many flavors of Eclipse I'd see many developers talking about Textmate, Notepad++, VIM, and EMACS.  I'd frequently half heart-idly try out E (textmate for windows) but I'd always go back to CFBuilder after a short time.  While I found that I liked the look and feel of these a bit better than Eclipse I failed to see what all the hype was all about.  The first "a-ha" moment I had was when I  was using E and typed in cffunction -> tab, then I pressed tab again.  OK, this is sort of nice, I can fill out a whole tag and cycle through all of its attributes by pressing tab.  This was nice but when I write functions I don't always use all the attributes.  The next step I took towards text editor bliss was to customize the snippits I used the most to match the way I wrote my code.  Shortly after I was writing code faster than I ever was before.  Little by little I started to use E more than CFBuilder and Aptana.

In this corner, SublimeText 2


Snap-On Torque Wrench
This brings us to the point where I installed SublimeText 2 on my machine and started playing with it.  This article on Nettus+ changed things forever.  One of the things I really liked in eclipse was using Ctrl-Click on a component definition in a file to be taken directly to that component in the editor.  I thought Ctrl-P was a lot like the "Open Resource" function in Eclipse, however, what I didn't know is that SublimeText will instantly preview a file in the editor as soon as it gets focus in the search result list.  SublimeText also remembers what files you recently worked on so those files come up first in the file list.  I was finding and opening files faster than ever.  Adding the power of Ctrl-R to quickly find a function in a file I can go to a specific function in a component faster than I can by doing a ctrl-click in eclipse.  SublimeText is the Snap-On Torque Wrench of code editors.  It does one thing and it does it extremely well.  

Additionally now that I wasn't using Eclipse for everything I had to find alternatives for the other things that Eclipse did for me like SVN, GIT, Ftp, and viewing log files.  For the most part the replacements I found have far outperformed what was available in Eclipse. For instance on my Mac Cornerstone has been a great replacement for the SVN integration in Eclipse.  I love the incoming/outgoing file count.  I have less conflicts now because I can see when files are waiting to come in and update more frequently.  There are situations where the eclipse plugin outperforms it, but those are far and few between.

Lastly are the intangibles that make SublimeText a pleasure to work with.  For the first time in my career I have found an editor I am passionate about.  An editor that, for me, makes coding more fun.  Its the little things that make such a big difference.  I love the animations when I close a tab or delete a file. I love the 30,000 foot view of all of my code in a file, I love how the contents of a folder smoothly slides down when I click on it.  I also love how easy it is to pull in a color file and have those colors work on all my code instead of having to import 15 different .col files like I did with eclipse.

Conclusion


In conclusion I'd like to say that no text editor or IDE will make every developer happy.  Each developer should use whatever makes them happy and productive.  In the mean time I'll continue to sing praises of Sublime to whomever will listen.  But who knows, when CFBuilder 3 comes out I'll probably switch to that for a bit simply because I love trying new things.

Tuesday, February 7, 2012

ColdFusion Koans Giveaway: Win a Copy of John Whish's ColdFusion ORM Book

With my work and school commitments I haven't been able to put as much time into the ColdFusion Koans project as I'd like to.  Instead of staying up another hour and working on it late at night I'm turning to you, the ColdFusion community to help me make the project better.  To make it worth your time I'm going to give away a digital copy of John Whish's excellent ColdFusion ORM book (http://www.coldfusionormbook.com/) to one lucky person.  If I get over 20 entries I'll give away TWO copies of the book.

There are three ways to be entered into the contest (if you complete both you'll get three entries).  The first way to enter is to download the Koans project, complete it, and post a link to a screenshot of all the tests passing into the comments of this post, make sure you subscribe to the comments so you know when I announce the winner.  The second way to enter is to add a new test or tests to the project and submit a pull request via github. The third is to write a blog post about the Koans project and post a link to the post in the comments here.

You can download the project here: https://github.com/bittersweetryan/ColdFusion-Koans.  If you'd like a quick intro to the Koans you can view a quick screencast I did here: http://blog.bittersweetryan.com/2011/11/screencast-getting-started-with.html.

I'll be drawing the winner March 1st.

Thursday, February 2, 2012

SublimeText 2 Now Has An Official ColdFusion Package Control Package

This has been making its way around twitter lately but I wanted to share that there is now an official Package Control Package for ColdFusion.  The project is hosted on GitHub https://github.com/SublimeText/ColdFusion so you can either download it from there, or since its an official package now it can be installed directly from PackageControl.   If you use SublimeText and not package control you are really missing out.  Read about it here: http://wbond.net/sublime_packages/package_control.   Installing this version over any of the TextMate bundle ports has a few advantages:

  • The package can now be managed through the "PackageControl" interface.  This means getting an update is as simple as going to Package Control -> Upgrade Package.  
  • Improved tag completion and suggestions.
  • CFScript support
  • The package is written in "Sublime Text" way meaning that some of the syntax and code completion features for ColdFusion are actually compiled into a python file wich should enhance performance. 
  • Brad has been excellent at pushing updates to the project and closing issues that come up.
If you are used to using the TextMate ports its important to note that the snippets are not stored in individual .tmSnippet files in this package.   If you like to customize your snippets you have to go into the ColdFusion.sublime-completions file and update the snippets there.   For instanceI like to remove all of the attributes that I rarely use from the cffunction tag.  If you'd like a quick reference on how the bundles work I have a screencast here: http://blog.bittersweetryan.com/2011/10/screencast-power-coldfusion-editing.html.  This was done using the TextMate port package so I was editing a .tmSnippet file, but the syntax is mostly the same in the .sublime-completions file.

If you like this package please let Brad know, he's on twitter as @atomi.