A feature that I find signficantly missing in C# is the ability to write
functions in interfaces that can call other functions of the interface.
Given an interface ISomeInteface the only way we can write a general purpose
function to operate on all objects which implement that interface is through
the following style of declaration (in the following code snippets i is an
interface variable of type ISomeInterface) :
SomeStaticClass {
FuBar(ISomeInterface i) { ... }
}
Which when invoked requires the following syntax :
SomeStaticClass.FuBar(i);
What would be more appropriate would be to be able to define interface
functions which allow the more straightforward object-like syntax of :
i.FuBar()
For lack of a better term I refer to these kinds of functions as interface
extensions, in order to distinguish them from interface contract (the set of
functions to be implemented, by an implementor of the interface). One
possible approach for adding this feature is to prefix extension functions
with a keyword modifier, such as in the following notation :
SomeInterface {
extension FuBar() { ... }
}
Another possibility, and my preferred option, is to divide the interface
into two sections :
SomeInterface {
contract
...
extension
FuBar();
}
For more information on extensions as implemented by Heron, there is a first
draft of a paper at : http://www.heron-language.com/extensions.html . I
would like to know what others think of this proposal (both the feature and
the presentation of the feature) and what the proper channels are for
feature proposal to C#. Thanks in advance for your feedback.
--
Christopher Diggins
yet another language designer
http://www.heron-language.com