The StaDyn Project (Computational Reflection Research Group)

StaDyn

An efficient hybrid static and dynamic typing programming language

Dynamic languages are used for developing different kinds of applications such as adaptable and adaptive software, Web development, application frameworks, game engines, interactive programming, rapid prototyping, and dynamic aspect-oriented programming. These languages build on the idea of supporting reasoning about (and customizing) program structure, behavior and environment at runtime.

Dynamic languages do not perform type checking at compile time like statically typed languages (Java, C# or C++), performing most type-checking at runtime. This postponement causes two main drawbacks:

  1. Runtime performance. The exact knowledge of object structure at compile time gives more opportunities for compiler optimizations. The runtime type inspection and type checking performed by dynamically typed languages commonly involve a runtime performance improvement.

  2. Early detection of type errors. Type errors are not detected at compile time. This does not allow programmers to fix programming errors immediately rather than discovering them at runtime; when the programmer's efforts might be aimed at some other task, or even after the program has been deployed.

Project Aim

The main objective of this project is to combine the benefits of both dynamically and statically typed languages in the very same programming language: StaDyn. StaDyn permits the straightforward development of adaptable software and rapid prototyping, with high robustness and runtime performance.

Static typing is centered on making sure that programs behave correctly at runtime. Therefore, static typing languages have a kind of pessimistic policy regarding programs correctness. This pessimism may cause compiler errors of programs that would be correctly executed by dynamically typed languages. The following Java code shows this limitation:

        Object[] v=new Object[10]; 
        for (int i = 0; i < 10; i++) { 
            v[i] = "String " + i; 
            int length = v[i].length();  // Compiler error
        } 
                    

Dynamic languages follow the opposite point of view. They do not perform any type checking at compile time. Thus, dynamic languages are very optimistic, compiling programs that might be identified as erroneous statically. The following code is a Python example of such a scenario:

        myObject = object()
        length = myObject.length()  # No compiler error                    
                    

Language Benefits

  1. Early type error detection. The StaDyn compiler performs type checking of dynamically typed code. Thus, the previous Python example, written with the StaDyn syntax, would be detected as erroneous by the StaDyn compiler.

  2. Runtime performance. The type information gathered by the StaDyn compiler is used to optimize the dynamically typed code. Many runtime type-checking operations are avoided, causing a significant runtime performance improvement.

  3. Improving runtime adaptability statically typed languages. Statically typed flow-sensitive variables could be used, providing a static duck typing system.

  4. Separation of the dynamism concern. To make dynamic and static type systems converge, we follow the Separation of Concerns principle applied to our programming language. The programmer may specify those parts of the code that need higher adaptability (dynamic) and those that may guarantee a correct behavior at runtime (static). This separation permits to turn rapidly developed prototypes into final robust and efficient applications.

  5. Direct interoperation between static and dynamic typing languages. The type system of StaDyn allows the interoperation between both typing approaches in the same language.

  6. High level of legibility and simplicity. The absence of mandatory type annotations is sometimes used to increase the legibility of the source code (e.g., var keyword in C#). A constraint-based type system is able to gather the requirements to be met by a variable without specifying them in its type declaration. For example, in Java, the min method of the java.util.Collections class (returns the minimum value in a collection) is declared this way:

        public static  <T extends Object & Comparable<? super T>> T min(
            Collection<? extends T> coll)	
                                

    In StaDyn, it could be written as:

        public static var min(var coll )	
                                

    The type system infers the constraints that the parameter must satisfy, by analyzing the source code of the method body. These constraints are used by the compiler the type of the min function and its coll parameter.

To see source code examples in a brief tutorial, please check out the Getting Started page.