Saturday, May 12, 2012

ColdFusion From an Outsider's Perspective

After changing my primary development language to PHP over a year ago, I've been able to get a new perspective on ColdFusion. One thing I've noticed is that people in the community spend less time focusing on new language enhancements and instead spend more time trying to make the language easier to work with. While this is a good thing, there are two pain-points that seem to come up over and over again that simply aren't issues in most other languages:
  • Case sensitivity
  • Struct key order
Would it really be so bad if ColdFusion was case sensitive? It would make converting ColdFusion objects to JSON or XML a lot more straightforward. "But Tony, I want to be able to define a function named getName but then be able to call it using gEtNaMe()". There should be no place for inconsistency in code. I honestly don't see any benefits to it not being case sensitive. Besides, with the addition of Hibernate, parts of the language are starting to become case sensitive already.

Would it really be so bad if structs maintained their correct key order? I see people building relatively complex solutions trying to solve this problem, often times having to dip into Java to accomplish the task. Wouldn't it be better if the native data type just worked the way you wanted it to? "But Tony, that's not how a HashMap works." Says who? Object keys stay ordered in JavaScript and associative array keys stay ordered in PHP. ColdFusion should work the same way.

In my opinion, making these changes adds a lot more value to the language than some of the other recent enhancements, such as WebSockets or REST.

Wednesday, September 21, 2011

Encode HTML Characters in JavaScript using jQuery

Here's a quick post on how to encode and decode HTML characters in JavaScript using jQuery. I didn't come up with the solution, but I thought it was pretty clever.
function htmlEncode(value){
    return $('<div/>').text(value).html();
}

function htmlDecode(value){
    return $('<div/>').html(value).text();
}
Courtesy of http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding

Wednesday, August 10, 2011

jQuery Naming Conventions: Don't Prefix Variables With $

When working with jQuery, I hate it when developers prefix their variables with dollar signs. For example, var $buttons = $('.button');. In my opinion the dollar sign really hurts the readability of the code.

Some developers claim that adding the dollar sign is a good naming convention because it shows that the value represents a jQuery object. If that's the case, then everybody should start using Hungarian notation all of the time. Gross.

The one exception I might make is for var $this = $(this);, although even then I would rather prefer something like var me = $(this);.

Long story short, don't prefix your variables with a dollar sign. Besides, it's not like you're working with PHP or anything.

Monday, June 6, 2011

ColdMVC Updates 1.3.7

Here's a quick post describing some small but relatively cool updates to ColdMVC in version 1.3.7: http://bit.ly/ColdMVC-Updates-1_3_7

Monday, May 30, 2011

ColdMVC Documentation Updates

I recently added some more documentation for ColdMVC:

* An overview of models in ColdMVC: http://www.coldmvc.com/guide/models

* Query operators in ColdMVC: http://www.coldmvc.com/guide/operators

* Building complex queries in ColdMVC: http://www.coldmvc.com/guide/queries

* Getters and setters in ColdMVC: http://www.coldmvc.com/guide/getters-and-setters

* Specify required params for an action: http://www.coldmvc.com/annotations/params

* Specify allowed request methods for an action: http://www.coldmvc.com/annotations/methods