Programming Windows: Hello, C# (Premium)

In 1996, Anders Hejlsberg, the genius responsible for Turbo Pascal, Object Pascal, and Delphi, left Borland to come to Microsoft. His original task was to help the software giant fully embrace Java by making the language a full-fledged member of the Visual Studio family and to extend its capabilities so that it could create real Windows applications using a RAD (rapid application development) environment similar to Visual Basic.

The results, Visual J++ and the Windows Foundation Classes, were perhaps too successful: In 1997, Java owner Sun sued Microsoft for violating the licensing conditions of its contract. The lawsuit signaled the deathblow to Microsoft’s internal efforts to fully embrace Java at every level. “That was the genesis for us understanding … that it’s really hard to do what’s right for your customers by extending someone else’s platform,” Hejlsberg said recently. “We’ve got to build our own.”

That was the beginning of .NET, which would emulate the Java runtime environment but be completely designed, built, and maintained by Microsoft. and as Anders noted, “of course we needed a programming language.” Originally called COOL, for C++ Object-Oriented Language, this new language would very closely resemble Java.

“Can you imagine the opportunity to have a company like Microsoft put their might behind a [new] programming language that you’re going to create,” he reminisced, noting that there were others at Microsoft who had been positioning themselves to design this future language before he won out. “I was totally flabbergasted that I was given that opportunity.”

By the time the language was announced in July 2000, it had been renamed to C#, which is pronounced “see sharp.” The original version of its compiler was written in C++ or, as Anders calls it “C+-“ (as in “C plus minus”) because they “didn’t use all of C++.” Someone named Peter Golde wrote the core implementation of the original C# compiler, Anders says. Anders himself wrote the C# language specification.

“C# is a simple, modern, object-oriented, and type-safe programming language,” that original language spec explained. “It will immediately be familiar to C and C++ programmers. C# combines the high productivity of Rapid Application Development (RAD) languages and the raw power of C++.”

Anders and Microsoft often compared C# to C++ rather than Java for obvious reasons, and still do. But C# is very clearly modeled after Java, and not C++, the latter of which was designed to be a superset of the C programming language. Meanwhile, both Java and C# are “C-like languages” (or what some people call “curly brace languages”) that are not burdened by syntactical compatibilities with some ancient forebearer.

C# was immediately criticized, both by Java’s creators—James Gosling called C# an “imitation” of Java “with reliability, productivity and security deleted,” a ludicrous claim—and by some third parties. But these critics were missing the point: C# was literally designed to emulate the Java language, just as the .NET runtime environment was designed to emulate the Java runtime environment. But each was controlled by Microsoft, not Sun. And each included important advantages over its primary inspiration.

For example, since Anders was starting from scratch, he gave C# some important improvements over Java, including properties as a first-class language construct. And a key advantage of the .NET platform from the beginning was its language neutrality: Any programming language could be designed to work within the .NET platform and could be used in place of Microsoft languages like C# and Visual Basic .NET.

In any event, C# has gone on to become the primary programming language for developers working in the so-called Microsoft stack, and it long-ago surpassed the usage of other Microsoft languages like Visual Basic. NET and Visual C++. Anders had done it again.

As for the language itself, it may be helpful to consider the basic Java console application I described in my Visual J++ article. It looks like so:

class hello
{
    public static void main(String args[])
    {
        System.out.println("Hello, Java!");
    }
}

In his C# Language Specification v1.0, Anders provides a similar example program, but written in C# 1.0. It looks like so (with minor formatting and output text changes to be consistent with the above example):

using System;
class Hello
{
    static void Main() 
    {
        Console.WriteLine("Hello, C#!");
    }
}

I assume the similarities are obvious. What’s interesting, perhaps, is that this code compiles and runs fine today using Visual Studio 2019.

And I know that’s not particularly exciting. But C#, like its Visual Basic .NET stablemate, could also be used to create full-featured Windows applications using a new .NET-based RAD environment called Windows Forms. We’ll look at that next.

 

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Thurrott