Loading ...
Sorry, an error occurred while loading the content.

35Re: [extremeperl] Perl, OOP, and Unit Testing

Expand Messages
  • Rob Nagler
    Jul 22, 2002
    • 0 Attachment
      asimjalis writes:
      > The test instead of defining the OO interface
      > should define the data structure.

      For practical reasons, we manage all data through classes. This
      simplifies the calling convention (we always use -> when calling an
      API). Classes can return rich data structures a la XML::Parser, which
      are not objects. This feels "right" to me in Perl. The test still
      tests the OO API. The result check may have to validate a rich data
      structure, which is easy in Perl thanks to ref() and defined().

      I (and others [1]) agree with your conclusions about OO and data.
      Fine grained objects are a big problem in Java, which is why int,
      boolean, etc. are not objects (and therefore can't be NULL, which is
      another problem :-). This is why Java sucks in many ways. Arrays and
      hashes are very cumbersome to use, but they are necessary to solve
      most problems in software.

      A good example of "unnecessary OO" is XML Data Binding[2]. In Java,
      you need some way to access XML data efficiently. XPath-like
      interfaces aren't it. Data Binding allows you to instantiate an XML
      file as a set of classes generated from the DTD. You don't need this
      in Perl, because you have everything you need with hashes and arrays.
      This makes Perl's XML handling more efficient and easier to use.

      My #1 goal in testing is to have a test case per line. I find
      declarative testing is the easiest way to do this. It also gives more
      control to the test framework. To me, it's completely natural and
      easy to write declarative tests in Perl. In Java it's cumbersome,
      because it lacks simple data structures like lists. Can't say for


      [1] http://www.paulgraham.com/noop.html
      [2] See http://www.rpbourret.com/xml/XMLDataBinding.htm and
      http://java.sun.com/xml/jaxb/ and
    • Show all 4 messages in this topic