Chapter 8. Open Source Programming

In this chapter, we're going to review the current state of open source programming with Microsoft technologies and tools. This is something that has been referred to by many technology evangelists as the open source ecosystem.

In this chapter we will cover the following topics:

  • We'll start with the initial movements in this area and explore how they have evolved over time, summarizing the most important initiatives that any developer can access at this moment.
  • Later, we'll revise some of the most popular implementations, either on the side of tools (IDEs) or APIs and languages.
  • We'll look at programming with open source solutions, such as Node.js, how it's is supported within Visual Studio and how easy it is to create a project that uses Node with this environment, as well as how other IDE choices are available, such as Visual Studio Code.
  • Later, we'll go through perhaps the two most important and adopted open source initiatives in Microsoft: the Roslyn project, a set of APIs and services that provide extended support for the development experience; and TypeScript, the new language created by C# author Anders Hejlsberg, which allows programmers to use advanced JavaScript features today, with excellent support of IDEs and total backwards compatibility.

Historical open source movements

Microsoft began to pave the way in open source as far back as 2003, when the first moves were made in order to adopt GPL Licensing on some products, the most noticeable being the effort to standardize the .NET Framework platform in general and the C# Language in particular.

Actually, it was soon approved as a standard by ECMA (ECMA-334) and ISO (ISO/IEC 23270:2006).

Later on, the Mono Project (Xamarin) (https://en.wikipedia.org/wiki/Mono_(software)), which is now part of Microsoft, provided versions of .NET capable of running in Linux and MacOS. This was probably the first serious attempt to make C# universal. The Mono licensing model was clearly open (http://www.mono-project.com/docs/faq/licensing/), although their IDE was not (Xamarin Studio).

However, the acquisition of Xamarin by Microsoft brought even better news to developers, since now, clients of Visual Studio Community Edition could find Xamarin tools and libraries embedded in the IDE with all the value of building Android, iOS, and Windows Phone solutions seamlessly. Likewise, there's a free release of the product called Xamarin Studio Community Edition.

Other projects and initiatives

However, what's been discussed so far was only part of the landscape. From 2005, they started to contribute to well-known open source initiatives, such as Linux and Hadoop, in order to use internally open source products and tools and publish some results.

Some of the best-known projects were the .NET Foundation initiative and WinJS, a library to use JavaScript that allows access to the Windows APIs and that appeared aligned with the Windows 8 suite of operating systems, permitting developers to build applications made with HTML5, CSS3, and JavaScript.

Azure has been another important division where Microsoft started to show its interest in open source. To previous movements supporting Linux and MacOS directly in Azure, we have to add the recent announcement of SQL Server running in Linux (http://blogs.microsoft.com/blog/2016/03/07/announcing-sql-server-on-linux), and the availability of PowerShell for Mac OS and Linux.

The latest announcements, officially confirmed in November's Connect() event, only deepen that philosophy: Microsoft becomes a Platinum Partner of the Linux Foundation, one in three virtual machines running in Azure is a Linux "distro", and the inclusion of Bash in Windows 10 allows the native installation of several Linux "distros" in the system.

On the other side, Google has become a member of the .NET Foundation and it's actively collaborating in the standardization of C#. Microsoft is as of this moment, the company with the highest amount of "open source" projects contributing in Github.

Finally, the recent collaboration with Samsung and the Tizen initiative only extends the number of collaborations with the open source world.

Open source code for the programmer

What about the programmer? As we mentioned, to the announcement of the free Visual Studio Community Edition in 2013 followed the declaration that this tool is going to be free in later editions along with the opening of Xamarin Studio:

Open source code for the programmer

This change was proposed in the spring of 2015 with the publication of Visual Studio Code, (free and available for Windows, Linux, and MacOS). It's a development tool that joins the capabilities of an editor with the debugging features of an IDE.

How was Visual Studio Code coded so that it would work on the three platforms? Three projects? Not quite. It was done thanks to the other big movement that started in 2010, which we introduced in Chapter 04 Comparing Approaches to Programming and that I'll cover later in this chapter: TypeScript.

Other languages

Open source projects also appear with other tools and languages such as Node.js, now used as another type of project from Visual Studio (any version), Python, PHP, or Apache/Cordova. All these technologies are now part of the installable/programmable projects available from the IDE. This goes for GitHub as well, whose engineers collaborate to integrate it better with Visual Studio and Visual Studio Code.

In the case of Node.js, you have to install the templates for Visual Studio (a one-time, pretty straightforward operation), and you will be shown several templates when you select in to build a new project, as shown in the following screenshot:

Other languages

If you work with one of these projects, you'll discover that common tools on other platforms are, by default, available here as well, such as Grunt, Bower, NPM. Gulp, and so on.

Just for the sake of completeness, let's perform a basic demo of Node.js with these templates and see how it works. If you select Basic Node.js Express Application, a whole application will be generated from the templates, including the files required to launch a working instance of Node.js and a simple web page that uses Node as the localhost web server.

Tip

For detailed information on Node, you can check another title in this "Mastering" series, with detailed documentation, explanations and demos: "Mastering Node.js", by Sandro Pasquali (https://www.packtpub.com/web-development/mastering-nodejs).

By default, the project uses the Express library, which works seamlessly with Node. The view engine is also the most common one in these projects (it's called Jade, and you can change it at any time or use one of the alternatives available).

When reviewing the files generated, you'll notice a number of libraries that have been downloaded and updated in our project. This is the result of the IDE's interaction with the package.json configuration file, which establishes the libraries that the application depends on:

{
  "name": "ExpressApp1",
  "version": "0.0.0",
  "description": "ExpressApp1",
  "main": "app.js",
  "author": {
    "name": "Marino",
    "email": ""
  },
  "dependencies": {
    "express": "3.4.4",
    "jade": "*",
    "stylus": "*"
  }
}

This file instructs the IDE to download all libraries required and all the dependencies these libraries rely upon.

At launch, two windows will open. On the one hand, Console will open, and on the other hand, an instance of the default browser will open. In the console, Node.js is listening on two ports: the debugging port [5858] and the Express port [1337], which take care of web requests, as shown in the following screenshot:

Other languages

As you can see in the preceding figure, two requests have been made at runtime: the rendered page (which Jade generates from the basic source code in the index.jade file) and the style sheet, which was referenced in the layout.jade file that serves as the master page in this demo. Both worked fine (200 status).

On the other hand, the resulting page from mixing these two .jade files (the actual master or the main page) is shown in the selected browser (note that you can select more than one browser to create a multi-browser debugging session):

Other languages

Independently of the aspects of Node.js programming and its tools, you'll observe that the tool's support is very complete, so we can even mix projects that use different technologies in a single solution, and we don't depend on an installation of IIS for debugging purposes anymore:

Other languages

Other remarkable areas where the community is very active in the Microsoft Open Source ecosystem are as follows:

  • Entity Framework Core (now in version 1.1)
  • Microsoft Edge, where users can vote for new features under consideration and use the JavaScript internal engine (Chakra) for their own purposes (just like with Chrome's V8 engine)

    Note

    You can read more about, and collaborate on, these projects at https://developer.microsoft.com/en-us/microsoft-edge/platform/status/backdropfilter, as shown in the previous figure.

  • .NET Core is the latest member in the .NET family, which enables the building of applications that work on any platform: Windows, Linux, or MacOS
  • The Roslyn and TypeScript projects

And, many, many more

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.208.97