.NET What

So what exactly does .NET do, and what is all this framework business?

TL;DR → .NET allows you to develop apps for multiple platforms, using a common language and provides a standard for all APIs in the .NET ecosystem.

This blog was also published on Medium.


When delving a programming language, one undertakes an analysis of its syntax and structure. However, it’s important to recognize that a language primarily emerges as a consequence to facilitating the compiler’s ability to comprehend and transform the code into a machine-readable format.

Typically, a language is released with a runtime specific to each platform which is responsible for translating high level code into machine code, managing memory, threads and garbage collection. However the .NET architecture has introduced a system which provides some unique benefits.

History Lesson — Why the need?

Steve Ballmer first introduced .NET as a suite of products:

– Microsoft .NET platform — Includes .NET infrastructure and tools to build and operate a new generation of services.

– Microsoft .NET products and services — A core integrated set of building block services.

– Third-party .NET services — A vast range of partners and developers will have the opportunity to produce corporate and vertical services built on the .NET platform.

— Source: Microsoft White Paper, June 2000

This was initially created for Windows but has since grown into the .NET SDK we know today that supports pretty much all major platforms: Windows, Linux, Docker, Unity Engine, Android, iOS …

.NET provides you with four things:

  • Programming languages → Well… this is what you program in 🙂
  • Built-in packages → You are provided with out of the box packages for web/mobile/ML/desktop e.t.c — no more searching for good npm packages!
  • Data types → You might think why does .NET provide data types, isn’t this just what C# does? We will explain this further on.
  • Templates → Standard templates for web/mobile etc. When do you ever find that in native python!
  • Runtimes → Enables a developer to run any application on any platform

Interacting with .NET

On Microsoft’s website, you are able to download .NET here. Once installed, you are able to interact using the dotnet cli or using Visual Studio.

The command `dotnet new` lists all templates that you can start with — note the language and the types of app e.g server/forms/console e.t.c

‘dotnet new’ command showing templates

.NET also has other commands for running your application:

  • `dotnet build` → builds your application into the CLR binary
  • `dotnet run` → builds and runs application

.NET Architecture

So how does my computer understand high level languages?

There are three main forms of “code” that your .NET application takes:

  1. First, the high level language code.
  2. After compilation, an optimised more low level language aptly called the Intermediate Language (IL) code.
  3. At runtime, a binary file detailing binary processes.

All applications created using .NET go through this process.

An example is shown below of C# vs its IL generated code below. It is important to note that all high level concepts like access control (public vs private), don’t exist inside IL code — the compiler will strip these away to the core elements.

High Level Language vs IL Code — gist:3452051
High Level Language vs IL Code — gist:3452051

Architecture Overview

Below shows a diagram showing the process from writing your application to running on a specific OS.

  1. Write your program using a .NET language.
  2. The compiler checks syntax, semantics, analyses and optimises your code to a more machine readable format. Each compiler must be specific to a high language.
  3. All languages are compiled to a common intermediary language, meaning that, at runtime, the language you have written your code in does not matter!
  4. The runtime JIT compiler is specific to the OS that you are targeting to run on.
  5. This produces binary code that your OS can understand
  6. The OS then manages threading, and manages the application’s control flow

Java also goes through a similar process.

Overview of .NET build and run process
Overview of .NET build and run process

You might be thinking why go through all this hasstle? This architecture provides three main advantages:

  1. Applications are language agnostic — meaning .NET apps can communicate through a common API, the IL, no matter what high level language they are written in. This means that a C# application is able to communicate with and F# application, because the under the hood data types are the same.
  2. Applications can run on any platform after compilation — The IL is common between all languages, meaning that a single compiled application can be distributed across multiple platforms e.g Windows, Linux, Mobile…
  3. Provides common datatypes — in order to allow apps to communicate with eachother, .NET must provide common datatypes between all high level languages.

.NET can publish apps in two different modes: framework dependent or self-contained. The first requires a user to have a specific .NET runtime installed, however self-contained mode bundles up the runtime with your application so a user does not need .NET installed.

Interpreted languages, such as python, require a different runtime for each platform and extra caution when developing due to a lack of common datatypes. That being said, python now has multitude of compilers and interpreters, one being IronPython which allows Python to integrate with .NET CLR.


Thanks for Reading!

If you’d like to explore more about the topics discussed in this blog post or connect with me for further discussions and collaborations, feel free to check out my GitHub profile @TomSB1423.

Bonus Resources

NDC Conferences


If you are interested in hearing more, consider subscribing to posts!

Categories:

One response

  1. Nice post. I learn something totally new and challenging on websites

Leave a Reply

Your email address will not be published. Required fields are marked *