Difference between revisions of "Andromeda"

From HIVE
Jump to navigation Jump to search
(→‎New Syntactical Features: added stuff that is not changing in Andromeda 0.2.0)
Line 51: Line 51:
 
===Polymorphism===
 
===Polymorphism===
 
===Generics===
 
===Generics===
 +
Andromeda supports generic programming with the implementation of generic types. Any class may be declared to be generic by postfixing angled brackets (<tt><></tt>) containing an arbitrary number of type parameters to the class's name in its declaration. Only classes may be generic; unlike in C++, functions cannot be made generic. Two examples of generic class declarations are:
  
 +
public class LinkedList<T> {
 +
    //...
 +
}
 +
 +
public class TreeMap<K,V> {
 +
    //...
 +
}
 +
 +
<tt>LinkedList</tt> is a generic type with one type parameter <tt>T</tt> and <tt>TreeMap</tt> is a generic type with two type parameters <tt>K</tt> and <tt>V</tt>. Generic classes must be ''parameterized'' upon instantiation. That is, each parameter must be specified with a type. This can be either a concrete type, another generic type, or even another type parameter (the last two are only valid if the instantiation itself occurs in a generic class). Unlike Java, Andromeda does not allow the instantiation of ''raw'' generic objects - objects of generic types that have not been parameterized. Currently, Andromeda allows classes as well as native types that can be interchanged with <tt>int</tt> to parameterize generics. Wrapper classes must be used to parameterize generics with other native types (such as <tt>unit</tt>).
 +
 +
Aside from the restrictions described above, generic types are treated as if they were any other type. Generic classes may be extended by concrete or generic classes and vice versa. The Andromeda type system regards the same generic type with different parameterizations (<tt>LinkedList<Integer></tt> vs. <tt>LinkedList<Fixed></tt>) as different types, so they cannot be used interchangeably. While Andromeda allows inheritance polymorphism with respect to the generic types themselves, it does not allow it respect to the parameters. In other words, assigning a <tt>Derived<A></tt> to a variable of type <tt>Base<A></tt> is allowed, but assigning a <tt>A<Derived></tt> to a variable of type <tt>A<Base></tt> is not.
 +
 +
When working with type parameters, no information about the type that eventually will be used in place of the parameter can be determined from the parameter itself. This is because Andromeda uses a strictly nominative type system wherein information about types is contained within the their names. Since parameters are not actual type names but instead only placeholders, they impart no information. A consequence of this is that one may not call any methods on objects whose type is only described by a type parameter or use them where a non-parameter type is expected (e.g. method arguments or return values) without explicit casts. This also renders illegal the invocation of the <tt>new</tt> or <tt>delete</tt> operators on objects of a parameter type.
  
 
== Links ==
 
== Links ==

Revision as of 21:33, 2 December 2010

Andromeda is an object-oriented, imperative scripting language that extends Blizzard's Galaxy language. It was designed to be an extension to Galaxy in the manner that vJASS was an extension to Warcraft III's JASS scripting language. Andromeda is implemented as a superset of Galaxy, meaning that all syntactically valid Galaxy code is also syntactically valid Andromeda code (the only exceptions are cases where the Galaxy code uses one of Andromeda's keywords). Moreover, Andromeda is compiled directly to Galaxy, allowing custom maps that use Andromeda to be played on Battle.net without the use of third-party mods.


Goals

Andromeda's main goals are to:

  • Maintain compatibility with native Galaxy code
  • Support object-oriented programming (OOP)
  • Support comprehensive and useful reporting of compile-time errors
  • Introduce common programming features absent from Galaxy
  • Reduce the need for unnecessary and boilerplate code
  • Produce optimized code in the target language when compiled
  • Provide simple and effective methods for code debugging

Design Paradigms

Andromeda is an object-oriented, procedural, and imperative scripting language with additional support for generic and (limited) reflexive programming. First and foremost, Andromeda adheres strictly to the tenets of Object-Oriented Programming (OOP). Procedural programming, while still supported, is included mainly for compatibility purposes with Galaxy. In Andromeda programming, an emphasis is placed on viewing the program as a collection of objects, each with its own state. Code is built around querying objects to determine their states and manipulating objects to change their states. This allows for the adoption or expansion of programming strategies such as:

  • Encapsulation
  • Modular Design (also known as Reusability)
  • Extensibility
  • Orthogonality

Language Features

Andromeda retains all of Galaxy's syntax features while adding new ones. Most of the new syntax is inspired by or directly borrowed from the Java programming language.

Source Code Structure

New Syntactical Features

Andromeda supports certain syntax found in C/C++ and Java that is missing in Galaxy, including:

  • Block commenting
  • Function/Method overloading
  • Multiple variable declaration on one line
  • Expanded implicit cast support
    • string to text
    • bool, int, fixed, char, byte to string or text when using the concatenate (+) operator
  • Local variable declaration freedom
  • {} Blocks
  • Postfix/Prefix increment/decrement operators (++ and --)
  • Using assignments as expressions: x = 5 + (y = 5); results in x being assigned the value of 10
  • for and for-each loops
  • Initializer (static) blocks

It also redefines some Galaxy constructs to make them more compatible with Andromeda style:

  • Forward declarations are no longer necessary (and discouraged)
  • The private keyword replaces the static keyword as a visibility modifier (use of the latter is possible, but discouraged)
  • Structs declarations no longer have to end with a semicolon
  • Reflexive programming using string literals to reference functions is discouraged. The .name field should be used instead to access a function/method's name.

Encapsulation

Classes

Polymorphism

Generics

Andromeda supports generic programming with the implementation of generic types. Any class may be declared to be generic by postfixing angled brackets (<>) containing an arbitrary number of type parameters to the class's name in its declaration. Only classes may be generic; unlike in C++, functions cannot be made generic. Two examples of generic class declarations are:

public class LinkedList<T> {
    //...
}

public class TreeMap<K,V> {
    //...
}

LinkedList is a generic type with one type parameter T and TreeMap is a generic type with two type parameters K and V. Generic classes must be parameterized upon instantiation. That is, each parameter must be specified with a type. This can be either a concrete type, another generic type, or even another type parameter (the last two are only valid if the instantiation itself occurs in a generic class). Unlike Java, Andromeda does not allow the instantiation of raw generic objects - objects of generic types that have not been parameterized. Currently, Andromeda allows classes as well as native types that can be interchanged with int to parameterize generics. Wrapper classes must be used to parameterize generics with other native types (such as unit).

Aside from the restrictions described above, generic types are treated as if they were any other type. Generic classes may be extended by concrete or generic classes and vice versa. The Andromeda type system regards the same generic type with different parameterizations (LinkedList<Integer> vs. LinkedList<Fixed>) as different types, so they cannot be used interchangeably. While Andromeda allows inheritance polymorphism with respect to the generic types themselves, it does not allow it respect to the parameters. In other words, assigning a Derived<A> to a variable of type Base<A> is allowed, but assigning a A<Derived> to a variable of type A<Base> is not.

When working with type parameters, no information about the type that eventually will be used in place of the parameter can be determined from the parameter itself. This is because Andromeda uses a strictly nominative type system wherein information about types is contained within the their names. Since parameters are not actual type names but instead only placeholders, they impart no information. A consequence of this is that one may not call any methods on objects whose type is only described by a type parameter or use them where a non-parameter type is expected (e.g. method arguments or return values) without explicit casts. This also renders illegal the invocation of the new or delete operators on objects of a parameter type.

Links

Libraries