Iterators: signs of weakness in object-oriented languages

  • Authors:
  • Henry G. Baker

  • Affiliations:
  • -

  • Venue:
  • ACM SIGPLAN OOPS Messenger
  • Year:
  • 1993

Quantified Score

Hi-index 0.01

Visualization

Abstract

The appearance of iterators in an object-oriented language appears to be inversely related to the power of the language's intrinsic control structures. Iterator classes are used for the sole purpose of enumerating the elements of an abstract collection class without revealing its implementation. We find that the availability of higher-order functions and function closures eliminates the need for these ad hoc iterator classes, in addition to providing the other benefits of "mostly functional programming". We examine a purely functional iteration protocol for the difficult task of comparing the collections of leaves on two non-isomorphic trees---the so-called "samefringe" problem---and find that its type signature requires recursive (cyclic) functional types. Although higher-order "member functions" and recursive (cyclic) functional types are unusual in object-oriented languages, they arise quite naturally and provide a satisfying programming style.