Questions: I want to warn myself of potential errors in my own code. Have I 
missed a feature in the Delphi IDE? If not, is there a better of way of 
flagging 
up possible problems?
------------------------------------------------------------------------------

Detail:

Obviously I have collected over time a bunch of home-made methods that solve an 
immediate problem and will likely be useful again in the future; I put all 
these 
in a set of units which I cite in the uses clause of a unit as needed.

However, from time to time these methods are not as complete or rigorous as I 
would like - but hell, you know, the wolves are at the door, the clients are 
getting uppity.  But I do worry that a couple of years down the line I'm going 
to forget the limitations and trip myself up by using the code inapproriately.

This has come to the fore again as I start to migrate projects to D2009 and 
notice possibilities, e.g. in the change from 1 byte to 2byte chars, ASCII to 
Unicode and all that: I've got a lot of useful string handling routines that 
may 
not work if the full range of Unicode strings was used. Right now I think that 
I'll not need to use the full range - but who knows what I'll need in a few 
years? I don't have the time or inclination at the moment to thoroughly test 
all 
the possibilities - and in fact I'm not sure I know what all the possibilities 
may be. To paraphrase Rumsfeld: "I don't know if there are things I know or 
don't know".

So, I want to build-in to some of these methods a warning to myself to be 
careful how I use them. I have started adding unneccesary string parameters to 
the method definitions, something like this:

function MyStrTest(TextIn: string; Hey_ASCII_Chars_Only: string = ''): boolean;

This is ugly and inefficient but it has three advantages:

- the declaration and implementation both carry a visible warning;
- the warning shows up when the code completion hint displays, so I am reminded 
every time I use the method;
- the unneccessary parameter is optional and so doesn't need to show up in the 
main body of code, as in:

    if MyStrTest(SomeString) then ...

although I can use it if I want to, as in:

    if MyStrTest(SomeString, '!!% Hey - be careful with this method') then ...

and if I am disciplined about using key sub-strings such as 'Hey_' or '!!%' I 
can quickly search my projects for the warnings.

The To-do-list could partly solve the problem, but it doesn't show up when I am 
actually using the methods.

Does anyone have a better solution, or do you all write perfect code all the 
time?  :-)

Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to