IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Language Basics   Print This     
  From the October 2008 Issue of Prestwood eMag
 
Delphi Language Basics:
Simple Habits Save Lots of Pain
 
Posted 14 years ago on 5/29/2007
Take Away: We developers sometimes get "on a roll." We know exactly what we need to do, and the code just flies off our fingertips. Later, though, we find ourselves in trouble...

KB100556

They say experience is what you get - right after you needed it.

So, from years of painful experience, here are a couple coding habits I've eventually forced myself to follow.

Endless Loops: When I know I'll be iterating over all the rows in a result set, here's the first few lines I write:

While not MyTable.EOF do
  begin
    // work goes here
    MyTable.Next;
  end;

In other words, before I write a single line of the "working code," I write the "Next" statement.   I can't tell you how many times I've focused on the working code - and omitted the Next statement.  Ouch!

I use a similar, defensive mechanism when creating objects:  Immediately after creating the object, I write the code that will destroy it.  Only then do I go back and write the code that uses the object.  Again, in the heat of battle, it's easy to forget to free allocated resources.

A simple way to express these principles is this: "Do the housekeeping first.  Attend to the details later."


Comments

1 Comments.
Share a thought or comment...
Comment 1 of 1

May disagree, krunker looking forward to more sharing

Posted 19 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1274A1
Enter key:
KB Post Contributed By Wes Peterson:

Wes Peterson is a Senior Programmer Analyst with Prestwood IT Solutions where he develops custom Windows software and custom websites using .Net and Delphi. When Wes is not coding for clients, he participates in this online community. Prior to his 10-year love-affair with Delphi, he worked with several other tools and databases. Currently he specializes in VS.Net using C# and VB.Net. To Wes, the .NET revolution is as exciting as the birth of Delphi.

Visit Profile

 KB Article #100556 Counter
6245
Since 4/2/2008
Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2021 Prestwood IT Solutions.   [Security & Privacy]