On Mon, 21 Mar 2016, David Jenkins wrote:

I understand the need for the list to be sorted and agree that calling find on an unsorted list is an error condition.

I am not convinced that current change deals with that well.

For one, the Sorted flag and actual state of the list are not directly linked. I can manually sort the list so that Find binary search will work just fine. But Find will exit before the binary search can occur - without any indication why.

But you agree that if Find is called on an unsorted list, bogus data will
be returned ? Or, worse, an never-ending loop may occur ?
In short, as you say, an "error condition" can ensue without you knowing it.

That is a bug. So, in my opinion (and of some others), Find is implemented buggy in Delphi.

Consider the buggyness a given in what follows.

If we consider something a bug in Delphi, we do not copy the bug.

You happen to rely on this buggy behaviour. This is of course unfortunate.

I attempted to fix this bug using a not too invasive method.
Originally I simply wanted to raise an exception, but that was deemed too
invasive.

There are now several options:
1. I change the code to raise an exception instead (as was my original plan)
2. I change the code to resort to a linear search if sorted is false.
3. I introduce a boolean property that determines whether Find does any check.
   By default the check will be done, to warn people they're doing
   something stupid. If they override the check, we can assume they know what
   they are doing.
4. Combine 1 and 3.

Or,

5. You override sort so it does nothing. It is virtual.
   You can then set sorted to True, no sort will occur, and find will do it's 
job.

6. You use another TStringList where you change find to suit your needs.
   All it takes for you is to copy the implementation, you can keep the same
   name, and insert the unit after the classes unit in places where you need it.

It's your call which of the 5 methods is used.

But one thing is sure: we're not reverting the behaviour back to the buggy 
behaviour.

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to