• DocumentCode
    1994351
  • Title

    Equality and hashing for (almost) free: Generating implementations from abstraction functions

  • Author

    Rayside, Derek ; Benjamin, Zev ; Singh, Rishabh ; Near, Joseph P. ; Milicevic, Aleksandar ; Jackson, Daniel

  • Author_Institution
    Comput. Sci. & Artificial Intell. Lab., Massachusetts Inst. of Technol., Cambridge, MA
  • fYear
    2009
  • fDate
    16-24 May 2009
  • Firstpage
    342
  • Lastpage
    352
  • Abstract
    In an object-oriented language such as Java, every class requires implementations of two special methods, one for determining equality and one for computing hash codes. Although the specification of these methods is usually straightforward, they can be hard to code (due to subclassing, delegation, cyclic references, and other factors) and often harbor subtle faults. A technique is presented that simplifies this task. Instead of writing code for the methods, the programmer gives, as a brief annotation, an abstraction function that defines an abstract view of an object´s representation, and sometimes an additional observer in the form of an iterator method. Equality and hash codes are then computed in library code that uses reflection to read the annotations. Experiments on a variety of programs suggest that, in comparison to writing the methods by hand, our technique requires less text from the programmer and results in methods that are more often correct.
  • Keywords
    object-oriented programming; Java; abstraction function; cyclic references; library code; object representation; object-oriented language; subclassing; Artificial intelligence; Computer science; Contracts; Cost function; Java; Libraries; Programming profession; Reflection; Testing; Writing;
  • fLanguage
    English
  • Publisher
    ieee
  • Conference_Titel
    Software Engineering, 2009. ICSE 2009. IEEE 31st International Conference on
  • Conference_Location
    Vancouver, BC
  • ISSN
    0270-5257
  • Print_ISBN
    978-1-4244-3453-4
  • Type

    conf

  • DOI
    10.1109/ICSE.2009.5070534
  • Filename
    5070534