Pages

Wednesday, 10 June 2015

C# and the .NET Framework

Windows Programming In Late 1990s

Some programmers say that learning programming language history is useless. But eventhough I'm not historian, I can't even agreed with that quote. By learning that we know the aim of new language development, and what's the feature it has. It can make you easier to migrate when you are not friendly with the new languages.

In Late 1990s, programming with Microsoft platform has fractured into a number of branches. Some programmers were using the raw Win32 API, but most were using Microsoft Foundation Classes (MFC)when others had used Component Object Model (COM). All these technologies had their own problems. Like table shown below:
Technology Disadventages
Win32 API Was not object-oriented, so using it required a lot more work than MFC
MFC was object-oriented but was inconsistent and getting old.
COM was very complex in its actual coding and required lots of ugly,inelegant plumbing.

Besides, all they can do were only developing code for desktop rather than internet. At the time, programming for the Web was an afterthought and seemed very different from coding for the desktop.

Time has changed. Developers need something to cover up both desktop and internet with easy, powerful and save way. They called it next generation platform. Which has Goal:
Execution Environment Development Environment
Security Object Oriented
Multiplatform Communication using industry standards
Performance Simplified Development
Language independence
Interoperability

Enter Microsoft .NET

In 2002, Microsoft released the first version of the .NET Framework, which promised meet the goals for the next-generation systems. It provides features shown in table below:

Security
  • C# is a type-safe language, meaning that instances of types can interact only through protocols they define, thereby ensuring each type’s internal consistency. For instance, C# prevents you from interacting with a string type as though it were an integer type.
  • C# supports static typing, meaning that the language enforces type safety at compile time. This is in addition to type safety being enforced at runtime.
  • C# is also called a strongly typed language because its type rules (whether enforced statically or at runtime) are very strict. For instance, you cannot call a function that’s designed to accept an integer with a floating-point number, unless you first explicitly convert the floating-point number to an integer.
Multiplatform The system runs on a broad range of computers, from servers and desktop machines to PDAs and cell phones.
  • C# code may run on the server and dish up HTML that can run on any platform. This is precisely the case for ASP.NET.
  • C# code may run on a runtime other than the Microsoft Common Language Runtime (CLR). The most notable example is the Mono project, which has its own C# compiler and runtime, running on Linux, Solaris, Mac OS X, and Windows.
  • C# code may run on a host that supports Microsoft Silverlight (supported for Windows and Mac OS X). This technology is analogous to Adobe’s Flash Player.
Performance The CLR has a service called the garbage collector (GC), which automatically manages memory for us. The GC automatically removes objects from memory that program will no longer access. This frees programmers from explicitly deallocating the memory for an object, eliminating the problem of incorrect pointers and memory leaks encountered in languages such as C++.
Object Oriented C# is a rich implementation of the object-orientation paradigm, which includes encapsulation, inheritance, and polymorphism. The distinctive features of C# from an object-oriented perspective are:
  • Unified type system: The fundamental building block in C# is an encapsulated unit of data and functions called a type. C# has a unified type system, where all types ultimately share a common base type. This means that all types, whether they represent business objects or are primitive types such as numbers, share the same basic set of functionality. For example, an instance of any type can be converted to a string by calling its ToString() method.
  • Classes and interfaces: In a traditional object-oriented paradigm, the only kind of type is a class. In C#, there are several other kinds of types, one of which is an interface. An interface is like a class, except that it only describes members. The implementation for those members comes from types that implement the interface. Interfaces are particularly useful in scenarios where multiple inheritance is required (unlike languages such as C++, C# does not support multiple inheritance of classes).
  • Properties, methods, and events: In the pure object-oriented paradigm, all functions are methods. In C#, methods are only one kind of function member, which also includes properties and events (there are others, too). Properties are function members that encapsulate a piece of an object’s state, such as a button’s color or a label’s text. Events are function members that simplify acting on object state changes.
Communication using industry standards The system uses industry-standard communication protocols, such as XML, HTTP, SOAP, JSON, and WSDL.
Simplified Development Deploying programs written for the .NET Framework can be much easier than it was before, for the following reasons:
  • No need to register the registry: means that in the simplest case, a program just needs to be copied to the target machine and it’s ready to run.
  • Side-by-side execution, which allows different versions of a DLL to exist on the same machine. This means that every executable can have access to the version of the DLL for which it was built.
Language independence .Net has Common Language Infrastructure (CLI) which is a set of standards that ties all the components of the .NET Framework into a cohesive, consistent system. It lays out the concepts and architecture of the system and specifies the rules and conventions to which all the software must adhere.

Component Function
Common Language Runtime (CLR)
  • Memory management and garbage collection
  • Code safety verification
  • Code execution, thread management, and exception handling
Common Language Specification (CLS) specifies the rules, properties, and behaviors of a .NET-compliant programming language.
Base Class Library (BCL) Supply a large class library used by the .NET Framework
Metadata Definitions and Semantics Rule to describe code, so it's easy to maintain
Common Type System (CTS) Defines a rich set of intrinsic types, with fixed, specific characteristics for each type.
Common Intermediate Language (CIL) Provide a way to interoperabiliy and multiplatfrom execution
Interoperability The .NET Framework frees the programmer from the COM legacy. There's no need to register a component to the registry.

The Evolution of .Net

Release Feature
5.0 Asynchronous functions
4.0
  • Dynamic binding
  • Optional parameters and named arguments
  • Type variance with generic interfaces and delegates
  • COM interoperability improvements
3.0
  • Implicitly typed local variables (var keyword)
  • Object initializers
  • Lambda expressions
  • LINQ
  • Expression trees
  • Automatic properties
2.0
  • Generics
  • Partial classes
  • Anonymous method
1.0 Initial C#
  • .NET framework class Library
  • Common Language Runtime and ASP.NET

0 comments:

Post a Comment