Case Study: applying generics to the Buffer library
(Last updated on 20 Feb,2004. we shall post a full paper describing this experiment soon)
¡¡
In our
earlier case study, we analyzed
redundancies in the Buffer library. We designed a meta-level solution in XVCL in
which we eliminated 68% of code. An interesting question is how
much of the redundant code can be eliminated by applying generics? In this case
study we answer this question but also ¨C we look deeper into the analysis of
strengths and limits of generics. The conclusion of our study is that while
generics provide an elegant solution to unifying certain groups of classes,
there are many other situations that also call for generic solutions, which
cannot be tackled with generics. Then, it is beneficial to apply less
restrictive but more powerful meta-programming techniques.
¡¡
Upon careful observation of the Buffer library, we found that only three buffer groups fall neatly into the generics-friendly layout and could be replaced by 3 generic classes. They represent 21 classes (3 groups of 7 classes each). In each of these groups, classes corresponding to byte and char types were not generics-friendly with their peers. That left us with only 15 generic-friendly classes (3 groups of 5 classes) that could be replaced by generic classes Buffer<T>, HeapBuffer<T> and HeapBufferR<T>. According to this result, generics can eliminate only 27% of code from the Buffer library. This solution still relies on wrapper classes for primitive types.