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

Calendar

<< July 2010 >>

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 (41) [RSS]
  • ActionScript (1) [RSS]
  • Actuate (1) [RSS]
  • Adobe (16) [RSS]
  • Adobe Community Professionals (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 (16) [RSS]
  • Cleveland (3) [RSS]
  • Cleveland AUG (20) [RSS]
  • Cleveland CFUG (23) [RSS]
  • ColdFusion (78) [RSS]
  • Conferences (33) [RSS]
  • Design (3) [RSS]
  • Dreamweaver (1) [RSS]
  • Eclipse (1) [RSS]
  • Flash (2) [RSS]
  • Flex (10) [RSS]
  • Frameworks (7) [RSS]
  • Fusebox (1) [RSS]
  • J2EE (1) [RSS]
  • JavaScript (1) [RSS]
  • Jobs (2) [RSS]
  • LightFront (6) [RSS]
  • Linux (2) [RSS]
  • Mac (3) [RSS]
  • Mach-ii (9) [RSS]
  • Macromedia (9) [RSS]
  • MAX (34) [RSS]
  • Notes to Self (1) [RSS]
  • Open Source (7) [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 (7) [RSS]
  • Subversion (2) [RSS]
  • Tech News (2) [RSS]
  • Technology (2) [RSS]
  • Tutorials (1) [RSS]
  • User Groups (22) [RSS]
  • Videos (1) [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

      LightFront 0.4.4 has been released, and... my CFObjective talk...
      maertsch said: great presentation. really cool anti-mainstream but with lots of facts. i have learned a lot. thanks... [More]

      LightFront: The incredibly simple & approachable MVC Framework for ColdFusion
      tech said: Thanks for work! Good article. I am a junior developer and wanna to try the LightFront =) [More]

      LightFront - New Video Series - Getting Started with LightFront
      Brian Meloche said: As they say, "it's not you, it's me". :-) I thought everything worked as it should. I'll h... [More]

      LightFront - New Video Series - Getting Started with LightFront
      Derek said: I believe 1600x1200. 24" monitor. Not at home to check, but looks like u gotten taken care of n... [More]

      LightFront - New Video Series - Getting Started with LightFront
      Brian Meloche said: I must have a newer version of the Flash player or something. I was able to replicate the problem. I... [More]

      Podcasts I Listen To...

      Active Podcasts
      CFConversations (My Podcast)
      CFPanel (technically not a podcast, but close enough!)
      RIA Podcast
      CFHour()
      The Flex Show
      Non-active CF/Flex Podcasts (still worth a listen)
      ColdFusion Weekly
      The ColdFusion Podcast
      Helms and Peters Out Loud
      Other Podcasts
      This Week in Tech (TWiT)
      Windows Weekly with Paul Thurotte
      MacBreak Weekly
      Net @ Nite
      Slashdot Review
      Ruby on Rails Podcast (I'm not a Rails developer, but it's always a good idea to stay in touch with the competition!)
      Web Design Podcast from boagworld.com
      Practical Web Design Magazine