HTML5 Canvas
Written by: Simon Sarris
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Web Driver
  3. MVVM
  4. REST
  5. ADO.NET
  1. HTML5
  2. Ajax
  3. jQuery Selectors
  4. CSS Part 1
  5. Git

Link Details

Link 136179 thumbnail
User 225256 avatar

By mswatcher
via davybrion.com
Published: Nov 24 2008 / 14:54

In case you don’t know what is so bad about this, think about this: if you have 5 employees you first send one select statement to the database to get their id values. Then you send another 5 select statements to the database to get the data of each employee. Oh well, 6 queries isn’t that big of a deal right? It sure as hell is if you could’ve just as easily gotten all of the required data with one query (and only one expensive roundtrip)! Imagine you have to calculate the paychecks of 100 employees instead of 5. How about 1000 employees?
  • 16
  • 0
  • 3546
  • 11

Comments

Add your comment
User 209464 avatar

willcode4beer replied ago:

2 votes Vote down Vote up Reply

If the word database wasn't in there, no one would complain about the code itself.

This is what happens when you create an API that rewards the wrong practice. Unfortunately, these types of APIs are all too common.

Instead of criticizing the code, the criticism should be leveled on the design of the API that made that code so easy to write. When designing an API, you should be exceptionally careful. Make the "right" thing easy to do. Document the best ways to do things well. Make the "wrong" thing difficult to do. That's 80% of the battle in preventing this type of behavior.

User 187417 avatar

sproketboy replied ago:

2 votes Vote down Vote up Reply

This is a fundamental problem of ORM. Too much abstraction hides the amount of processing going on here. The author complains about getting each employee one-by-one by id - but also I would say that calling a PayDay method on each one - creating a new Paycheck object - is also bad. Heck, the method is not even returning the modified employee objects.

This could have been wrapped up in 1 SQL statement with little scalability issues.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.