Sometimes, a query should just be a query

Posted By: Brian Meloche; Posted At : January 17, 2008 4:18 PM

Related Categories: ColdFusion

During a conversation today with another developer, I was reminded of a recent collection of blog posts by San Diego ADUG Manager, Robert Munn, that talks about this from a technical perspective, but I wanted to talk about it from more of a "best practices" slant.

I don't think this is quite as bad in 2008 as it was a couple of years ago, but there has been a propensity for CF developers who are trying to use MVC and create OO CF applications to lose sight of the KISS method of development - Keep it Simple, Stupid!

ColdFusion's beauty is in its simplicity, but there are many CF developers that seem to have a love/hate relationship with this simplicity. It's either they intentionally add a lot more complexity to their applications, or that they actually wish it were harder! We see CF developers that seem to trash ColdFusion every chance they get, and I can't understand why for the life of me.

I used to be a procedural developer, but I am definitely an OO developer and have been for a while now. I use Mach-ii and ColdSpring every day, and am pretty darn good at it! So, I don't want to sound like I am bashing OO. I am just saying that there is good, responsible OO, and then there's pseudo-OO, where there are getters and setters everywhere that really do nothing. Your objects need to DO something, and not just exist because they look like OO.

OO is great, but there's a time and a place for it. To be clear, I am talking pragmatism and using what the language is best at over theory. Not everything should have getters and setters and return an array of objects. I've known for some time now, anecdotally, that, most times, a query should just stay a query. There are no reasons to convert them into objects if they can be represented as a query. Unless they represent a single object that needs to be manipulated, you don't need them. Often, if you need a more complex structure, returning an array of structures, versus an array of objects, will give you MUCH better performance.

There is best practice, and maintaining good applications with no more code than you need. But, in Rob's blog, there's also legitimate technical reasons why you should use no more objects than you have to. Rob has a series of posts called "Object instantiation and heap size in ColdFusion".

Part I
Part II
Part III
Part IV

Rob is highlighting where objects are persisting in memory until the end of the request and how memory spikes up, where a procedural solution resulted in much faster processing and lower memory.

That's not to say that you shouldn't create arrays of objects, but Rob's was a great test to demonstrate that objects, a lot of them, are problematic in ColdFusion. Interestingly, keeping the object in memory actually HURT performance. As this demonstrates, it's not the instantiation of objects that causes the problems, but the bean persistence. Objects holding data tend to be memory hogs, even in CF8.

Here is probably the most significant statement made in the series of posts:

"It would seem that the use of components as beans to hold data creates a serious potential performance problem for CF-based apps in cases where those beans are persisted (e.g. in the application or session scope) or where many beans are instantiated in a single, long-running request. I don't see any problem using beans in other scenarios, e.g. using beans to store a small number of records returned from the database, or using a bean to model a form in an HTML or Flex front end. I would be cautious, though, of using a large number of beans in a request or persisting beans in the session scope where they may not be garbage collected."

In today's conversation, both of us agreed on this principle, but we haven't been working together all that long, so it was good to bring it up, and I thought I'd bring attention to the subject. Rob's blog posts on it hit home.

If you haven't found Rob's blog yet, I suggest you add it to your rotation.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

Hosting provided by...

Hosting provided by hostmysite.com

Speaking and/or Podcasting at...


cf.Objective() 2009

CFUnited 2009

Calendar

<< July 2009 >>

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Archives By Subject

  • About Me (39) [RSS]
  • ActionScript (1) [RSS]
  • Actuate (1) [RSS]
  • Adobe (15) [RSS]
  • Adobe Community Experts (2) [RSS]
  • AIR (1) [RSS]
  • AJAX (1) [RSS]
  • Animals (11) [RSS]
  • Articles (2) [RSS]
  • ASP (1) [RSS]
  • Blogging (14) [RSS]
  • BlueDragon (2) [RSS]
  • Canadian-American (1) [RSS]
  • CFConversations (15) [RSS]
  • Cleveland (3) [RSS]
  • Cleveland AUG (20) [RSS]
  • Cleveland CFUG (23) [RSS]
  • ColdFusion (69) [RSS]
  • Conferences (29) [RSS]
  • Design (3) [RSS]
  • Dreamweaver (1) [RSS]
  • Flash (2) [RSS]
  • Flex (10) [RSS]
  • Frameworks (4) [RSS]
  • Fusebox (1) [RSS]
  • JavaScript (1) [RSS]
  • Jobs (2) [RSS]
  • Linux (2) [RSS]
  • Mac (3) [RSS]
  • Mach-ii (8) [RSS]
  • Macromedia (9) [RSS]
  • MAX (34) [RSS]
  • Open Source (6) [RSS]
  • Personal (16) [RSS]
  • Podcasts (23) [RSS]
  • Politics (1) [RSS]
  • Railo (0) [RSS]
  • Random Musings (10) [RSS]
  • Reality TV (1) [RSS]
  • Social Networking (1) [RSS]
  • Speaking (6) [RSS]
  • Tech News (2) [RSS]
  • Technology (2) [RSS]
  • User Groups (21) [RSS]
  • Weight Loss (4) [RSS]
  • Windows (0) [RSS]
  • Work (8) [RSS]
  • Search

    Twitter Updates
    Follow me!

      RSS

      Subscribe

      Enter your email address to subscribe to this blog.

      Tags

      about me adobe animals blogging cfconversations cleveland aug cleveland cfug coldfusion conferences flex max personal podcasts random musings user groups

      Recent Comments

      The new me at cf.Objective()
      todd sharp said: Wow man - I see you more then most people in the community and you even surprised me with this pic. ... [More]

      The new me at cf.Objective()
      Tony said: Great Job Brian! It's always great to see good things happen to great people! [More]

      The new me at cf.Objective()
      Raymond Camden said: Congrats Brian. Awesome job. [More]

      At cf.Objective(), and I'm no longer CF_Heavy...
      Brian Meloche said: New pics have been posted: http://www.brianmeloche.c...... [More]

      So how AM I doing?
      Adam Tuttle said: Congratulations again, Brian. My hat goes off to you. [More]