New object declaration with cfscript 9

I have recently started using cfscript for models in my applications.
I have been using the new cfscript 9 in my models to grab a query of
users, blog entries, etc, and I have model objects for each.
(Blog.cfc, Entry.cfc).
* An entry object
* @accessors true
* @extends EntryService
component {
  property numeric blogsId;
  property string title;
  property string authorName;
  property date dateCreated;
  property string tags;
  property string metaKeywords;
  property string metaDescription;
  property string contents;

  Entry function init(){

    return this;


I have then been using a service layer to grab these objects like so:

component singleton="true"{

  EntryService function init(){

    return this;

  // Get Latest Entries
  Array function getLatestEntries(numeric lim="3")
    var strSql = "SELECT * FROM blogs";
    var query = new Query();
    var oResults = query.execute();
    var numRes = oResults.getPrefix().recordcount;
    var qResults = oResults.getResult();
    var entries = arrayNew(1);

    for(var i = 1; i <= numRes; i++)
      var entry = new Entry();


    return entries;

Thereby creating an array of entries and returning this array back to
a handler.

My questions is, Am I doing the right thing by creating an array of
objects? Is this more or less efficient than simply passing queries

Your code should be much more maintainable by passing arrays of objects. CF9’s object creation is FAST. Yes, there is overhead, but, it is very, very, very small.

Keep it up.

Also, if you name your columns in your DB the same as your object’s properties you can reduce your code you posted quite a bit!

You can then use the BeanFactory.populateBean() or populateModel() methods of coldbox.

In general, if you are doing something new especially, I'd suggest
passing objects around instead of queries. Queries have some really
nice features about them built in, but if you use objects you'll
hopefully be inclined to add more behavior to those objects that you
just can't get with a query. Examples might include validation,
composition of properties (like adding a Name field to a User that
composes the First Name and Last Name fields in your db), basic
metadata (having standardized properties common to all objects like
CreatedAt, CreatedBy, LastModifiedAt, LastModifiedBy), etc.

I'm still getting there myself, but I'm looking forward to the day
where I can really put together a project that I design the model
first and then let the model largely determine the database schema for
me. Its a bit weird and scary for a guy that has been writing gnarly
SQL for so many years, but I'm seeing the benefits of really
concentrating on the business objects more and letting storage
(including No-SQL databases like Couch and Mongo) handle itself more
and more.

And I second everything Aaron said, object instantiation has gotten a
lot faster in CF9 and Railo is just blazing in comparison to old
versions of CF and the helper Populate* methods in CB are really
pretty sweet. Let your model determine your db schema if you can.
Hibernate does a pretty good job creating and setting things up for
you. They don't always use the same naming scheme I would but if you
let Hibernate do it for you you have a lot of work taken off your


* An entry object
* @accessors true
* @extends EntryService
component {

Just a point of style: whilst ACF9 allows you to specify code
semantics (meaning) in comments, I really don't think it's a good
idea. Comments should *never* affect the meaning of code. I'd keep
comments for hint and documentation but use real attributes for things
that affect the meaning of the code, such as accessors="true" and

           var strSql = &quot;SELECT \* FROM blogs&quot;;
           var query = new Query\(\);
           var oResults = query\.execute\(\);

You can simplify this by writing:

var oResults = new Query( sql = 'SELECT * FROM blogs', datasource =
'mps' ).execute();

(otherwise the new CFCs-for-tags are really verbose!)

My questions is, Am I doing the right thing by creating an array of
objects? Is this more or less efficient than simply passing queries

Another thing you might want to consider is using the built-in ORM (in
ACF9 / Railo 3.2) so that you can map your blogs table and columns
directly to your Entry CFC and then fetching all the records as an
array of objects is as simple as:

entityLoad( 'Entry' ); // return an array of Entry objects built from
all rows in the blogs table...

You might also take a look at iterating business objects, which
iterates using a single instantiated cfc, custom object behavior and
query performance both.