Projects Seek To Extend Reach of C#
Apple's young Swift programming language is getting a lot of attention and being put to new uses as it evolves, but Microsoft's .NET stalwart C# language isn't exactly sitting still.
Here's a look at two of those projects recently in the news that provide such translation, albeit for quite different purposes: CoreRT and Bridge.NET.
This open source project
to extend the reach of C# is part of a greater effort on the part of Microsoft to provide .NET tooling that runs on Mac and Linux OSes in addition to Windows.
Microsoft developer Jeffrey T. Fritz explained the project in a blog post last week, in which he explained the current two-step process for creating .NET apps, involving a compiler that emits intermediate code (IL) that is in turn just-in-time (JIT) compiled to produce native code running on any target OS that supports the common language runtime (CLR).
The idea is to simplify that process to more easily produce native Windows, Mac and Linux apps without relying on the CLR, through ahead-of-time (AOT) compilation and "CodeGen" instead of using JIT.
"If we want to shortcut this two-step compilation process and deliver a 100 percent native application on Windows, Mac and Linux, we need an alternative to the CLR," Fritz said. "The project that is aiming to deliver that solution with an ahead-of-time compilation process is called CoreRT."
That project is based on RyuJIT, but that technology is limited to applications in which .NET is available, and it needs to be tweaked to handle other OSes or environments.
"If I really want to write some C# code and have it 'just work' on a new IoT device, I don't have any options until the RyuJIT is capable of generating machine code that works with that processor and operating system," Fritz said.
"One strategy we are investigating is the ability to transpile .NET code to C++ code that could be compiled with an appropriate C++ compiler for the target platform," he continued. "This strategy opens doors for hardware development because you would no longer need to wait for a Microsoft engineer to extend our compilers to support some new OS or new hardware in order to allow .NET developers to work with your product."
Fritz noted the complexity involved with CodeGen and transpilation of C# code and gave an update on the team's progress so far. For example, the CoreRT team this summer made progress in transpiling .NET interface code and dispatching it to C++. An interface is a C# construct that somewhat resembles a class but is used to provide a contract to define signatures of properties, methods, events and indexers that must be supported in classes and structs that implement an interface to provide specific functionality.
Although transpiling C# interface usage to C++ might seem simple, Fritz said it involved overcoming several coding challenges.
Despite those challenges, the CoreRT project can now transpile interface usage in a baseline scenario, for which the code can be found on GitHub.
"We believe that investing in C++ code generation is going to allow the .NET ecosystem to grow and support platforms that have not been invented yet," Fritz said. "With this approach, we no longer need to write JIT compilers for every environment, and can rely on the standardized and robust C++ compilers that are commonly available. To learn more about CoreRT and the CodeGen processes being constructed, follow the CodeGen label on the CoreRT issues repository. "We'll have more about CoreRT in the future as this framework progresses."
Another project that's progressing is Bridge.NET
In that regard, it can be viewed as an alternative to Xamarin, whose technology was recently acquired by Microsoft to help Visual Studio developers create native iOS and Android mobile apps solely with C#. Bridge.NET is available on GitHub under an Apache 2.0 license.
Released in March of last year by Object.NET Inc., Bridge.NET was recently the focus of a blog post published on the Dice.com careers site, written by David Bolton.
David Ramel is editor in chief of Visual Studio Magazine and Application Development Trends Magazine.