Special

Special Print Closeout!

We're clearing out the remainder of our print issues at fire sale prices -- as much as 75% off! Quantities are extremely limited and only available while supplies last. Hurry to take advantage of this one-time offer.

RBD Magazines

Once these printed back issues are gone, they are gone!

Article Preview


Buy Now

Print:
PDF:

Object-Oriented Thinking

Writing Debuggable Code

It's The Next Best Thing To Bug-Free Code

Issue: 6.1 (November/December 2007)
Author: Charles Yeomans
Article Description: No description available.
Article Length (in bytes): 6,833
Starting Page Number: 39
RBD Number: 6116
Resource File(s): None
Related Link(s): None
Known Limitations: None

Excerpt of article text...

You will not write bug-free code. But perhaps it's enough to write code that is easy to debug. Bugs are usually easy to fix when you can reproduce them and isolate them. In this issue's column, we look at some example code and rewrite it to be debuggable.

Let's consider the example of a window containing two edit fields StartDateField and EndDateField, and a listbox ReportListbox that holds the result of a database query returning all records in the specified date range. Here is some typical code for generating a report from such a query.

Sub BuildReport()

dim startDate as Date

if not ParseDate(StartDateField, startDate) then

return

end if

dim endDate as Date

if not ParseDate(EndDateField, endDate) then

return

end if

dim rs as RecordSet = db.SQLSelect("SELECT fld1, fld2 FROM Table1 WHERE entry_date BETWEEN '" + startDate.SQLDate + "' AND '" + endDate.SQLDate + "'")

if rs is nil then

return

end if

ReportListbox.DeleteAllRows

do until rs.EOF

ReportListbox.AddRow rs.Field("fld1").StringValue

...End of Excerpt. Please purchase the magazine to read the full article.

Article copyrighted by REALbasic Developer magazine. All rights reserved.


 


|

 


Weblog Commenting and Trackback by HaloScan.com