[fpc-devel] for-in-index loop

Graeme Geldenhuys graeme at geldenhuys.co.uk
Mon Jan 28 14:00:09 CET 2013


On 01/25/13 17:17, Alexander Klenin wrote:
>> Using indicies is against all principles of iterators.
> I am not sure what princilpes you are talking about,

The theory. Read any Design Patterns book or technical papers.


> but accessing the key of the current element is required quite often

On the contrary. You should be interested in the current element, not
the index value it represents. ALL my iterators in all my application
code don't use or need the index value. I simply ask for the Next or
Previous object or value.

This also hides the implementation details of the container object, thus
the container can change its internal implementation, and my Iterator
code in my applications will still continue to function without change.


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/




More information about the fpc-devel mailing list