Sunday, May 6, 2012
O static where art thou?
During his work on an interval hybrid ODE solver Jan has been wrestling with the issue of static methods in Scala. In previous work on parametric numerics Veronica and Jan relied on heavy use of implicits to have functions available without the necessity of calling them on an object. This approach has been successful, but results in base classes that contain implicit objects and methods that serve as carriers of the static methods, making the code less readable. Perhaps a more serious drawback is that these structures make the code less malleable, as they obstruct explorational coding, such as that done while writing prototypes for various design alternatives. The main reason for the complicated nature of the solution to static methods is that they are carried by companion objects to classes. As opposed to classes these do not take type parameters, which introduces the need for more involved solutions. One way forward would be to avoid static methods altogether, and use parametrised methods carried by objects of parametrised classes that exist for this purpose alone.This option is no worse than using static methods through qualified imports, but constructing the carrier object instead of importing a module. Another possibility is to program with concrete classes only, this way their companion objects provide the methods that operate on objects of the class. For the moment Jan has chosen the latter option as a matter of practicality, while working on the logic of the event detection algorithm itself.