Re: about DoublyLinkedList

"Hugo Santos" <[email protected]> Sun, 1 Apr 2007 22:43:42 +0100
Newsgroups gmane.os.openbeos.kernel.devel
Message-ID <[email protected]>
Hi Ingo, all,

> You can already use:
>
>         for (Iterator i = list.GetIterator(); i.Next();) {
>         }

  for (Iterator i = list.GetIterator(); i.HasNext();) {
    item *foo = i.Next();

  yes :-) But this isn't very readable IMO since the increment is done
in the beginning of the loop instead of the end as is usual. I find
that considering the current interface

  Iterator it = list.GetIterator();
  while (it.HasNext()) {
   item *foo = it.Next();

  is more readable than the for() version due to the prevalence of the
conditional and the lack of increment step.

  This iterator approach allows easily for items to be removed since
it always keeps an extra pointer for the next item; but i find this
use case to be a particular case and not the general case. I'll gladly
follow the current convention though.

  Personally, my point for a different approach is that the STL-like
interface better maps concepts such as "First" versus the Java
approach where Iterators are mostly Visitor objects. I think concepts
result in more understandable code, but i guess that's a personal
opinion.  Also, the STL isn't going anywhere and having an interface
which is similar to it helps new developers. :-)

>> ... operator* and operator-> ...
> Also STL like, though I wouldn't object, if those were added.

  Again, the concept of iterator vs. the iterator object. :-)

> The main reason for RemoveHead()'s existence is not code size or
> efficiency, but simplicity. Functionality like this is needed often enough,
> particularly when emptying lists or implementing queue-like behavior, so it
> has got a shorthand.

  Sure.

> >   As the amount of code that uses DoublyLinkedList is still small it
> > would be easy to convert all of it to the new interface (if you agree
> > of course).
>
> Please don't. :-)

  I would never commit such a big change without discussing it first.
:-) I mostly did some experiments in a local git branch.

> Definitely. If it was up to me, I would root out the evil pure C code and C
> interfaces in the kernel completely. :-P

  I'm very much for type-safe approaches thus my approach to DoublyLinkedList.

  Hugo

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV