Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to .NET

Introduction to .NET

An old presentation I gave to some professional C/C++ programmers to introduce the high-level concepts of .NET, including the definition of .NET from three different points of view.

Chad Taylor

May 09, 2012
Tweet

More Decks by Chad Taylor

Other Decks in Programming

Transcript

  1. Common Language Specification •Specifies a common type system •Ensures language

    interoperability •Code can but does not have to conform to CLS ◦uint is not a CLS compliant type, but exists in C# •Allows for a wide variety of languages to be built to run in the same environment
  2. Common Language Runtime •Where Common Intermediate Language (CIL) code is

    compiled into native code ◦This means that you do not have to have different builds to optimize for different types of hardware ◦Your code is more portable •Provides garbage collection services •Supports uniform exception handling
  3. Application Framework •Common libraries focused on developer productivity •Used to

    build different types of applications: ◦Win32-based client applications (WinForms, WPF) ◦Windows Services (WCF) ◦Web Services ("classic" web services, WCF) ◦Web Applications (ASP.NET, ASP.NET MVC) ◦RIA applications (Silverlight)
  4. Programming Language Buffet •Because of the CLS, many different languages

    have been built to run on the CLR •Some examples: ◦C#, C++/CLI, VB.NET, F#, IronPython, IronRuby, Powershell •It is not uncommon to build different parts of a single application in different languages, based on requirements •You can even use multiple languages to build a single library (DLL)
  5. Polyglot Example •Polyglot: Written in several languages •A Win32 application

    using: ◦F# for business rule processing ◦C# for business modeling, data access APIs, and GUIs ◦VB.NET for MS Office interoperability layer
  6. Memory Management •The CLR manages memory allocation and deallocation ◦The

    new call in C# asks the CLR to find a location in memory large enough for your object ◦The CLR may or may not allocate new memory blocks for this purpose ◦The returned value is a reference that is tracked by the CLR ◦When all references to a single object fall out of scope, that object is a candidate for garbage collection
  7. Memory Management •This means: ◦new is a cheap operation ◦Garbage

    collection cleans up after your object, so you do not need to call delete ◦Garbage collection occurs outside your control, so you do not know when an object will be deallocated ◦If you do not control when garbage collection happens, how do you know when to release any unmanaged resources?
  8. The Dispose Pattern •Holding unmanaged resources (such as a database

    connection) is a common problem •To use the pattern, implement IDisposable •Call the IDisposable.Dispose() method as soon as possible •Can tell the garbage collector to ignore this class when it runs •C# provides some nice language constructs that make using the Dispose pattern even easier
  9. CIL and the JIT compiler •All high-level language code is

    compiled into a Common Intermediate Language (CIL) •Formerly known as Microsoft Intermediate Language (MSIL) •The runtime compiles the CIL into native code just-in-time (JIT) at runtime •Optimizes for the capabilities of the machine (e.g., SSE extensions, 3D Now!, etc.) •This means that the code you write today will run faster on tomorrow's hardware without a recompile or redistribution •This means that you do not have to have different optimized builds when you ship your application
  10. Summary •.NET has many aspects - the CLR, the CLS,

    and the application framework •.NET encourages the use of the right language for the job, even multiple languages for a single application •.NET enables developers to be incredibly productive by managing some of the more difficult aspects of programs, such as memory management •.NET provides a JIT compiler with the CLR that ensures that applications developed in .NET are optimized to the greatest extent possible