New language features

Below is a list of some of the most visible new language features in the Core language of X# , compared to Visual Objects and Vulcan.

As you can see many new keywords were introduced, but these are positional: they will also be recognized as Identifiers on other places, so there is very little chance that you will have to make changes to avoid naming conflicts.

Entities and Statements

Below is a list of the new commands / entities inside X#. There are also some new options for existing commands. A full list of changes will be available later.

 

DEFINE <id> := <Expression> The VO Define is back again in X#.
It will be compiled into a constant of the Globals class, the same class in which all Functions and Methods are implemented.
The biggest advantage of a DEFINE over the preprocessor DEFINEs in Vulcan.NET is that there is no longer a chance that a DEFINE with the same name as a Method, Property or Variable will lead to incomprehensible compiler errors.
USING STATIC <Name>

The STATIC modifier for USING (note that the # sign is no longer needed) allows you to name a static class. When you do so you can then use the methods of this class as functions.
For example:

USING STATIC System.Console

FUNCTION Start as VOID
WriteLine("X# is cool!")
RETURN

 

BEGIN USING <Var>
  <Statements>
END [USING]
The USING block allows you to control the lifetime of a variable.
If <Var> has a destructor then it will be automatically destructed once the block has finished
SWITCH <Expression>
CASE <Const>
  <Statements>
CASE <Const2>
CASE <Const3>
  <Statements>
OTHERWISE
  <Statements>
END [SWITCH]
The SWITCH statement generates a more efficient jump structure than the DO CASE command. Also the expression is only evaluated once.
BEGIN UNSAFE
  <Statements>
END [UNSAFE]
Allows unsafe code in the context of this block , regardless of the compiler setting for the project as a whole.
BEGIN CHECKED
  <Statements>
END [CHECKED]
The statements inside the block will have checked conversions, regardless of the compiler setting for the project as a whole.
BEGIN UNCHECKED
  <Statements>
END [UNCHECKED]
The statements inside the block will have unchecked conversions, regardless of the compiler setting for the project as a whole.
VAR <Identifier> := <Expression> This is a synonym for LOCAL IMPLIED

CLASS <Id> < <ParamName> >
WHERE <TypeConstraints>
   <Classmembers>
END [CLASS]

Creating Generic classes is now supported in X#, with all the features that C# also has
For example

CLASS MyList<T> WHERE T IS CLASS
..
END CLASS

or

CLASS MyList<T> WHERE T IS ICustomer, NEW()
..
END CLASS

 

ASYNC - AWAIT The ASYNC AWAIT infratructure is fully available inside X#

Expressions

Below are some new expressions that are available  in X#

<Expression> IS <Type> Allows to check an expression for a type. Can be used in stead of IsInstanceOf() and will perform better
Conditional Access Operator ? <Expression> ? <Expression>
Conditional access for properties, methods etc.
For example

nCount  := MyList?:Count

This translates to something like: 
VAR temp := MyList
IF temp  != NULL
  nCount := temp:Count
ENDIF

The expression on the Left hand side of the Questionmark will be evaluated only once !
<Expression> DEFAULT <Expression>
The default operator allows you to inline a check for NULL:

lResult := Foo() DEFAULT Bar()
This translates to the same as

lResult := Foo()
IF lResult == NULL
   lResult := Bar()
ENDIF

Foo() will be evaluated only once. And only when the result is NULL then Bar() will be evaluated.

LINQ Query expressions are now supported:

VAR CustQuery = FROM Cust in Customers WHERE Cust.City = "Athens" ORDER BY Cust.Zipcode Select Cust

The full LINQ feature set will be supported by X#:
FROM
LET
WHERE
JOIN
ORDER BY
EQUALS
INTO


3 comments

  • Hi Robert,

    seems very promissing ... especially the ability to create generics and using and defining async methods.

    BTW, is the ? in variable defintion allowed as an abbreviation for Nullable? Not a must have feature but a nice one because it lead's to shorten and IMO better readable code.

    HAND
    Armin
  • Armin,

    No the ? in the expression syntax is what is called the conditional accessor.
    The Nullable type is supported as well. I have simply forgotten to include it in the list of changes.
    There is soo much to mention :laugh:

    Robert

    [quote name=&quot;Armin Back&quot;]Hi Robert,

    seems very promissing ... especially the ability to create generics and using and defining async methods.

    BTW, is the ? in variable defintion allowed as an abbreviation for Nullable? Not a must have feature but a nice one because it lead's to shorten and IMO better readable code.

    HAND
    Armin[/quote]