Combining Static and Dynamic Typing to Achieve Multiple Dispatch

Abstract

Some programming languages such as CLOS, Xtend and Dylan provide multiple dispatch through multi-methods. Multiple dispatch is a language feature for dynamically determining the actual method to be executed, depending on the dynamic types of its arguments. However, many widespread languages such as Java, C# and C++ only support single dispatch by means of dynamic binding. For this reason, different implementation techniques are commonly used to obtain multiple dispatch in these single-dispatch programming languages. This paper proposes a new way to achieve multiple dispatch in hybrid static and dynamic typing languages, comparing it with the typical techniques used to simulate it. A qualitative comparison is presented, considering factors such as software maintainability and readability, code size, parameter generalization, and compile-time type checking. We have also performed a quantitative evaluation of runtime performance and memory consumption. The proposed approach provides parameter generalization, and high maintainability and readability. Its code size depends on neither the number of multi-method parameters nor the number of derived types. Runtime performance is, on average, analogous to runtime type inspection, 3.9 times slower than static typing, and 36.6 times faster than reflection. The proposed approach consumes 31% more memory resources than the rest of approaches.

Publication
In Information –An Iternational Iterdisciplinary Journal