Future Features¶
This section covers future features of the OneScript language.
Type Inference¶
Instead of using a specific declaration type for a variable it will be possible to use the var keyword if the type of the variable can be inferred by its use.
var a = "This is a string";
var b;
var c = 1;
b = c + 23;
The example above show a direct inference for the variable a and a deferred inference for the variable b. As long as the inference can be made the compilation will be successful.
Collection Improvements¶
Iterators¶
All arrays will support the foreach statement block.
Dictionaries¶
Dictionaries support an indexed array for fast searching.
Class Improvements¶
Properties¶
Support for properties like many other languages.
class Animal {
private string name;
public string Name {
get { return name; }
set { name = value; }
}
}
In the above example there are a number of new keywords to denote the getter and setter of a property. For a setter the value keyword is automatically given the inbound value.
Abstract Classes¶
The ability to create a template class that can be inherited by other classes to support the idea of refactoring code.
abstract class Animal {
public string Name;
public void SayName();
}
In the above example it is possible to define methods with no block. These have to be fulfilled in the classes that inherit it.
Inheritance¶
Class Inheritance supported in many other languages improves refactoring of code.
class Horse : Animal {
public void SayName() {
Console.Write(base.Name);
}
}
the above example introduces the new keyword base. This refers to the base class that is inherited.
Interfaces¶
It is possible to define an interface listing the public properties and methods. This can be inherited by a class and then used as the template for that class. It's real benefit is the adoption of an interface by multiple classes so they can all be handled in a common way.
Asynchronous Programming¶
Whilst libraries used with OneScript support asynchronous programming the language itself does not. Methods can be made asynchronous with the asynckeyword and asynchronous methods can be called asynchronously with the awaitkeyword.