Tag Archives: anders hejlsberg

Microsoft’s new open source direction for C# and .NET (and native compilation too): Anders Hejlsberg explains

At the April 2014 Build conference Microsoft made some far-reaching announcements about its .NET platform and the C# programming language. Yes, there was talk of C# 6.0, the next version, but the real changes are more profound. Specifically:

C# and Visual Basic have a new compiler, itself written in C#, code-named Roslyn. Roslyn is not just a new compiler; Microsoft now calls it the “.NET Compiler Platform”.

There is a new commitment to open source for .NET projects. Microsoft formed the .NET Foundation to oversee existing open source projects, including  ASP.NET, Entity Framework, the Azure .NET SDK, and now Roslyn as well. “When it comes to development projects we are going to operate from the premise that open source is the default. Unless there are reasons why it does not work,” said C# lead architect Anders Hejlsberg.

image

Note that open source does not mean chaos. It does mean that you can fork the project if you want – the Roslyn license is Apache 2.0 – but getting Microsoft to accept new features you have contributed will not be trivial. Hejlsberg makes the point that language features are easy to add, but impossible to take away, so extreme care is necessary.

Microsoft is also supporting cross-platform C# to a greater extent than it has done in the past. The most obvious sign of this is its cooperation with Xamarin, which provides C# compilers for iOS and Android. Xamarin’s Miguel de Icaza got a top billing at Build, and is also involved in the .NET Foundation.

There is more though. The idea of standardised C# is re-emerging:

“The last ECMA standard was C# 2.0. There wasn’t a lot of demand for it, but that demand has recently risen and we have re engaged with the ECMA community to produce a standard for C# 5.0,” said Hejlsberg.

This bears some unpacking. Why was there little demand for ECMA C#? Partly I would guess from the assumption the C# was firmly in Microsoft’s grip, with Java the obvious choice for cross-platform development. The main interest was from the Mono folk (Miguel de Icaza again), which implemented .NET for Linux and the Mac with some success, but nothing to disturb Java’s momentum.

The focus now though is on mobile, and interest in C# is stronger, mainly from Microsoft-platform developers reaching beyond Windows. There is also Unity, which uses C# as a scripting language for developing games for multiple platforms, including iOS, Android, Windows, Mac, Linux, Xbox, PS3 and Wii – PS4 is coming very soon.

Microsoft has now consciously embraced multiple platforms, as evidenced by Office for iOS as well as the Xamarin collaboration. “We want C#developers to build great applications across different form factors and different device platforms,” said Jay Schmelzer Director of Program Management for Visual Studio.

You might observe that this position has been forced on the company by the rise of iOS and Android, a view which likely has some merit, but the impact it has on C# and .NET itself is still real.

I asked Hejlsberg to unpack the difference between the Roslyn project and C# 6.0, bearing in mind that both are covered on the Roslyn open source site; you can see the current status of C# 6.0 and the next Visual Basic here.

Roslyn is the name for the project that encompasses the new C#compiler and the new VB compiler and the new language services that they share. C# 6.0 is the name of the next version of the C #language which will have a specification and which will have an implementation. We are implementing C# 6.0 on the Roslyn platform. We are not going to continue to evolve our old C++ C# compiler – the C# compiler was originally written in C++ and has been evolved up through C# 5.0. That is where we are going to retire that code base, and going forward versions of C# will be built on Roslyn and therefore will be built open source. Unlike previously where, boom. C# came down from the sky with a set of features, it is going to happen more organically now, people will submit pull requests, open up issues, and you will see us work on these features. You will see them from inception to fruition.

“The C# team, the Roslyn team, the VB team, their day to day workplace now is the open source site. That is where they check-in code. It is a community in the making.

Even that is not all. At Build, Microsoft also announced .NET Native, which is a native compiler for C# and Visual Basic, now in preview for x64 Store apps. What is the difference between .NET Native and the existing NGen native compiler for .NET? Over to Hejlsberg:

NGen is the native feature that we currently support. NGen is really, “I’m going to JIT [Just in time compile] your code and then snapshot all the data structures and dump them in a file so that I can quickly rebuild that file later when you run this particular application”. But it is the same code generator and all the same features, and JIT is still there. NGen is really a way to pre-cache the JIT output and therefore get better performance, but it adds to the size of your app because you still have all the assemblies and metadata and then the NGen image as well.

.NET Native is a completely different approach. Instead of the JIT we use the backend from the C++ compiler. You can think of it as a linker that takes as input assemblies, and as output produces a PE [Portable Executable] executable. In the process this linker or code generator will analyse all the IL [Intermediate Language] that goes into the application and it will apply a thing known as tree-shaking where it eliminates all of the code that will never execute based on known execution roots.

In other words, the public static main of your program and also whatever pieces of your app that you designate as reflectable, they also become roots. Based on that we produce an optimised exe, and into that exe we link the pieces of the framework that you are referencing. We link in a garbage collector [GC], and it looks to the operating system just like an exe. When you run it, it runs a local GC in there and it is as efficient really as C++ code.

There are some restrictions associated with .net native, mainly that you can’t just willy-nilly reflect on the whole world. You can’t just generate new code and ask for that to be jitted because they may not be a JIT compiler. We are considering allowing you to link in a JIT compiler, but there are certain execution environments which don’t permit jitting, like Xbox. If you use reflection in your lap you have to tell us what to keep reflectable, because otherwise we will optimise it away.

According to Schmelzer:

The preview out today is scoped to Store app x64 and ARM. We haven’t run into any technical limitation that shows it can’t be done across the breadth, it is just a matter of request and need.

Open source, native code compilation, and an innovative compiler: it adds up to huge changes for C# and .NET, positive ones as far as I can tell.

The Xamarin connection is intriguing though. Developers in general admire the technology as far as I can tell, but it is expensive, and paying out for a Xamarin subscription on top of maybe MSDN for Visual Studio is too much for some smaller organisations and does not encourage experimentation. Might Microsoft acquire Xamarin and build Visual Studio into an IDE targeting all the major mobile platforms, but with special hooks to Azure-hosted services?

That prospect makes sense to me, though it would be a shame if the energetic Xamarin culture became bogged down in big-company bureaucracy. Currently though: no news to report.

Anders Hejlsberg says C# 6.0 to use Roslyn compiler, coming in next Visual Studio after VS 2013

A disappointment at Microsoft’s Build conference last month was lack of news about the next version of C#, version 6.0. C# architect Anders Hejlsberg did present a session, but it was on TypeScript, a language which compiles to JavaScript.

Aside: Hejlsberg talks about the new Xbox music app in Windows 8.1 (and Xbox One) which is written in JavaScript. It is a large app with 500,000  lines of code, and new features are now implemented in TypeScript (30,000 lines so far).

However, Hejlsberg did also talk about C# 6.0 at Build, during this Channel 9 Q&A, though you have to scroll through to reach the C# content (about 34 minutes in).

image

He confirmed that C# in Visual Studio 2013 is the same as before, but there will be new previews of the forthcoming “Roslyn” compiler soon, and that C# 6.0 will be in the “next Visual Studio after” which suggests Visual Studio 2014, presuming Microsoft sticks to its annual release cycle.

“We are at a point where the Roslyn compilers are done,” he said.

Roslyn, Hejlsberg explained, is the new compiler for “C#, and VB, and the language services in the IDE.”

Roslyn performance will be at least as good as the existing native compiler, says Hejlsberg. It is better suited to parallel processing so will take advantage of multi-core machines, “particularly for large projects.”

You can read more about Roslyn here. Microsoft describes it as “opening up the Visual Basic and C# compilers as APIs.” Practical benefits include features like instant porting of VB code to and from C#, and the use of C# and VB as macro languages within a .NET application.

Hejlsberg also says that Roslyn will enable a faster pace of evolution for C# in future.

Another aside: Xamarin, which provides a compiler for C# targeting iOS and Android, gets a nod of approval from Hejlsjberg. “I’m a great fan of their work,” he says.

Blogger (and former Microsoft Excel developer) Wesner Moise provides a transcript of the key points.

Here comes TypeScript: Microsoft’s superset of JavaScript

Microsoft’s Anders Hejlsberg has introduced TypeScript, a programming language which is a superset of JavaScript and which compiles to JavaScript code.

The thinking behind TypeScript is that JavaScript is unsuitable for large projects.

“JavaScript was never designed to be a programming language for big applications,” says Microsoft’s Anders Hejlsberg, inventor of C#. “It’s a scripting language.”

The ubiquity of JavaScript makes it remarkably useful though, with that now extending to the server thanks to projects like node.js. Microsoft is using node.js for its Azure Mobile Services.

TypeScript therefore lets you use features including type annotations, classes, modules and interfaces to make large projects more robust and maintainable.

Variable names are preserved when TypeScript is compiled. Further, since TypeScript is a superset, any JavaScript code can be pasted into a TypeScript project. The compiler is open source and you can download an early version here.

Microsoft is also trying to stay close to the specification for Ecmascript 6, the proposed next iteration of the official JavaScript standard, where relevant.

There is tooling for Visual Studio including a language service to provide code hinting, syntax highlighting and the like.

TypeScript differs from projects like Google Web Toolkit or Script#, both of which also emit JavaScript, in that it does not compile from one language into another; rather, it compiles into a reduced version of itself.

Why is Microsoft doing this? That is the interesting question. I would conjecture that it is partly self-interest. Microsoft itself has to write increasing amounts of JavaScript, for things like Office Web Apps (apparently written in Script#) and the new Azure portals. Azure Mobile Services uses JavaScript as mentioned above. JavaScript is also one of the options for coding apps for Windows 8. Better tools will help Microsoft itself to be more productive.

That said, the arrival of TypeScript will re-ignite the debate about whether Microsoft, while not anywhere close to abandoning .NET, is nevertheless drifting away from it, towards both native code in Windows and now JavaScript in the managed code space.

More information from Microsoft’s S Somasegar here.

Anders Hejlsberg on functional programming, programming futures

At TechDays in Belgium Micrososft’s C# designer and Technical Fellow Anders Hejlsberg spoke on trends in programming languages; you can watch the video here.

I recommend it highly, not so much because of any new or surprising content, but because in his low-key way Hejlsberg is a great communicator. The talk is mostly not about the far future, and much of what he covers relates directly to C# 4.0 and F# as found in Visual Studio 2010. Despite his personal investment in C#, Hejlsberg talks cheerfully about the benefits of F# and gives perhaps the best overview of functional programming I have heard, explaining what it is and why it is well suited to concurrency.

image

I will not try and summarise the whole talk here; but will bring out its unifying thought, which is that programming is moving towards a style that emphasises the “what” rather than the “how” of the tasks it encodes. This fits with a number of other ideas: greater abstraction, more declarative, more use of DSLs (domain-specific languages).

The example he gives early on describes how to get a count of groups in a set of data. You can do this using a somewhat manual approach, iterating through the data, identifying the groups, storing them somewhere, and incrementing the count as items belonging to each group are discovered.

Alternatively you can code it in one shot using the count keyword in LINQ or SQL (though Hejlsberg talked about LINQ). This is an example of using a DSL (Domain Specific Language), and also demonstrates a “what” rather than “how” approach to code. It is easier for another programmer to see your intention, as there is no need to analyse a set of loops and variables to discover what they do.

There is another reason to prefer this approach. Since the implementation is not specified, the compiler can more easily optimise your code; you do not care provided the result is correct. This becomes hugely important when it comes to concurrency, where we want the compiler or runtime to utilise many CPU cores if they are available. He has a screenshot of Task Manager running on a 128-core machine which apparently exists in Redmond (I can’t quite read the figure for total RAM but think it may be 128GB):

image

Hejlsberg says there was a language doldrums between 1995 and 2005, when many assumed that Java was the be-all and end-all. I wonder if this is a tacit admission that C#, which he was working on during that period, is not that different in philosophy from Java? The doldrums are over and we now have an explosion of new and revived languages: Ruby, Groovy, Python, Clojure, Boo, Erlang, F#, PowerShell and more. However, Hejlsberg says it makes sense for these to run on an existing framework – in practice either the Java or .NET runtime – since the benefits are so great.

Hejsberg also predicts that distinctions such as dynamic versus static languages will disappear as each language absorbs the best features from other languages. “Traditional taxonomies of languages are breaking down as languages pick paradigms from each other,” he says. The new language paradigm is multi-paradigm.

Just as C# has now acquired dynamic features, we can expect it to get better support for immutability in future (borrowed from functional languages).

Jewels from the loft: launch of Delphi, Netscape’s Constellation, HTML to die, Longhorn for developers

It’s the Easter holiday in the UK and I’ve suffered a bout of spring-clean fever. It is time, I decided, to clear out a mountain of old books and magazines.

A job like this always prompts reflections, the first of which is the sad decline of print journalism in the field of software development. It hurt to send piles of Byte, Exe, Dr Dobbs’s Journal, Application Development Advisor and others off for recycling.

image

A few things caught my eye. Exe June 1995, and there is a young Anders Hejlsberg talking to Will Watts about his new creation: Borland Delphi:

Before Delphi, you always had to make a choice. Do I go for the performance of a native code compiler, or the ease of use of a visual development environment? Do I go for a powerful object-oriented language, or a proprietary 4GL client/server tool? What programmers really want is all of the above, in one package. That’s what we set out to do.

What is striking about Delphi is that this was not hype. It delivered on that promise. It was better than its obvious rival, Microsoft’s Visual Basic, in almost every way (I will give VB a point for sheer ubiquity, especially in VBA guise). Delphi is still with us today, not bad after fifteen years. However, it never came close to VB’s market share, which shows that quality has never been the sole or even the most important determinant of sales success.

Next up is Byte, March 1998. “Reinventing the Web”, the cover proclaims. “XML and DHTML will bring order to the chaos”.

image

Inside there is a breathless description of how XML will change everything, and a quote from Jon Bosak:

HTML, this so-called ‘hypertext markup language,’ implements just a tiny amount of the functionality that has historically been associated with the concept of hypertext systems. Only the simplest form of linking is supported – unidirectional links to hard-coded locations. This is a far cry from the systems that were built and proven during the 1970s and 1980s.

Indeed. “We need to start replacing simple HTML with more powerful alternatives”, the article concludes. “The migration to XML must begin. The future of the Web depends on it.”

Here’s one thing that mostly did not work out as planned. The W3C tried to retire HTML, failed, and is now belatedly engaged in specifying HTML 5.

Byte March 1997 is also intriguing. Netscape’s Marc Andreessen smiles out of the cover.

image

Jon Udell, in the days before he disappeared into some Microsoft corridor, writes about Netscape’s “Constellation: the network-centric desktop”:

Netscape’s Constellation takes a less Windows-centric approach and puts more emphasis on location-independent computing, regardless of the platform. No matter what kind of system you’re using or where you are, Constellation presents a universal desktop called the Homeport. Although the Homeport can appear in a browser window, Netscape usually demonstrates it as a full-screen layer that buries the native OS – certainly one reason Microsoft is not embracing Constellation.

Netscape got a lot of things right, a true pioneer of what we now call cloud computing. What went wrong? Well, Microsoft went all-out to conquer Netscape by removing its browser dominance. Microsoft’s weapon was the free Internet Explorer.

It is all a pre-echo of what is happening now with Google and Microsoft, the difference being that Google has huge financial power thanks to its marriage of internet search and internet advertising. Unlike Netscape, Google is winning.

This blog is long enough; but I’ll give a brief mention to another jewel from the archives: a book given out at PDC 2003 entitled Introducing Longhorn for Developers.

image

It describes Microsoft’s vision for Longhorn: a radical new application model for Windows, building on XAML, WinFS and “Indigo”, the communication framework. It bears little resemblance to what eventually appeared as Vista, which is a shame as it was compelling in many ways.