Welcome to the .Net
-
Upload
amr-shawky -
Category
Documents
-
view
162 -
download
2
Transcript of Welcome to the .Net
Amr ShawkyDeveloper Head @ MSTC-HTI. Software-Web Developer intern at Boxoit. Twitter - @shawkyamr0
Introduction to the .NET and C#
Me
HOW TO COMMAND A COMPUTER ? LIFE OF WINDOWS PROGRAMMERS BEFORE THE .NET FRAMEWORKTo command a computer’s hardware, you must speak its language which is binary language (Zeros and Ones) so we need to give the data like (the numbers, characters,…) a code representing it and we also we need to give the instructions a binary representation.
For example:To represent “5” in 7 bits: 0000101
But is it Simple ? >> (First Problem).
ASSEMBLY PROGRAMMING LANGUAGE It’s an almost exactly like the machine language (zeros and ones) but it uses words instead of zeros and ones BUT how can the computer understand it ?!The Assembler have the answer of this question. The Assembler is a program that translates your program- written in assembly language- into machine code (zeros and ones) Assembly considered a low-level programming language with no abstraction as you deal with hardware directly like registers of the processor.
But it is Complex >> (Second Problem) >> let’s take a peak at it
ASSEMBLY PROGRAMMING LANGUAGE
HIGH LEVEL PROGRAMMING LANGUAGES High-Level Programming Languages solved the complexity of assembly language and gives an abstraction for the programmer isolating it from using assembly instructions.This abstraction is provided by the Compiler. The Compiler is a program / set of programs that translate your source code – written in a high level language – into assembly language then the assembler translate it into machine code.
Many programmers find C++ a difficult programming language for many reasons like:
- Manual Memory Management - Ugly Pointers - Ugly Syntactical Constructs // (Third Problem)
WHAT ABOUT LANGUAGES INTERACTION? I mean if we have an application written in C++, how will it interact with an application written in VB ?!
In 1991, Microsoft introduced its application development framework, Component Object Model “COM”, which is an architecture that says:
“If you build your data types in accordance with the rules of COM, you end up with a block of reusable binary code”
So, Languages can interact using COM but there is a problem !! COM Data Type representation is Complex !! (Fifth Problem)
LET’S CONTINUE OUR STORY By late 2000, Microsoft introduced the first beta version of .NET Framework in order to solve these problems.
But “What’s the meaning of the Framework in general ?! “Software Framework is a set of tools like Code Libraries, Compilers, that help in developing a project. From a Programmer’s point of view, it can be considered a Runtime Environment(an environment where your source code run) and libraries to use it in your source code.
A CLOSER LOOK AT THE .NET FRAMEWORK
“Life in a Multi-Language World”.NET Framework support numerous programming languages (C#, Visual Basic, F#, S#, so on) as programmers are a very particular lot when it comes to the choice of a programming language.
*The Second Problem* has been solved as if you finds C/C++ difficult due to its Ugly Arithmetic Pointers or its Ugly Syntactical Constructs you can use any .NET language that you feel good with.
No pointers required! C# programs typically have no need for direct pointer manipulation.
// Automatic memory management through garbage collection.
WHAT’S THE . NET ASSEMBLIES ?! All .NET compilers emit a file of *.dll or *.exe extension which is called Assembly File. The assembly file consists CIL “Common Intermediate Language” Code , Metadata, and Assembly Manifest. Let’s talk about these components one by one.
During compilation of any .NET programming language, your source code is translated to another language called Common Intermediate Language or Microsoft Intermediate Language (MSIL) rather than being translated to object code. This Intermediate language can sit above any instruction set of any processor.
EXAMPLE.. If I write a program that calculates the average of two integers in C# and I re-write the same program in Visual Basic, the C# compiler and the VB compiler will emit the same Assembly File with the same CIL Code.
But Why Using CIL ?! The answer of this question will direct us to the solution of the first problem as the main benefit of CIL is (LANGUAGE INTEGRATION) where all .NET languages are able to interact within a well-defined binary area.
SO, YOU CAN INTERACT WITH ANY .NET APPLICATION REGARDLESS OF THE LANGUAGE WITH WHICH IT’S DEVELOPED!
LET’S CONTINUE.. Now, the two problems have been solved. Let’s continue discovering .NET features.As I mentioned before, the assembly file contains a metadata and assembly manifest in addition to CIL. I expect now that you get the meaning of CIL so I'll start talking about metadata and assembly manifest.
The Metadata: describes every type (e.g., class, structure, enumeration) defined in your code, as well as the members of each type (e.g., properties, methods, events).
Assembly Manifest contains metadata that describes the assembly itself (e.g., assembly name, version number, list of all files in the assembly, so on).
BASE CLASS LIBRARY (BCL)“Framework” in general, Framework can be considered as a Runtime Environment plus Predefined Class Libraries to be directly used by the programmer
NAMESPACES ! But how are all the types (classes) organized within BCL ?! .NET makes extensive use of namespace concept to keep all the types within BCL well-organized. So, we can consider the namespace as a logical grouping of related types contained in an assembly.
*Remember: All the .NET languages use BCL so all the .NET languages use the same namespaces.
Example: All the classes related to file input and output will be placed in the same namespace which is called “System.IO”.
LET’S SUMMARIZE All what we talked about with respect to the .NET Framework can be summarized as the following:
.NET Framework support numerous programming languages where each has its own compiler but all the .NET compilers emit assemblies.
All .NET compilers translate your source code to Common Intermediate Language Code that takes place in the assemblies to enable language interaction.
The assembly file also contains metadata that describes the types (classes, structures,…) you used in your source code in addition to assembly manifest that describes the assembly itself.
.NET provides the programmer Base Class Library that includes number of predefined classes that represents many services to be used directly by the programmer. Also, this encapsulation provides a shelter from the complexity of API Calls.
.NET makes an extensive use of “namespace” concept to keep all the related types well-organized within BCL where all the related types are placed in the same assembly.
All the .NET languages use BCL with the same namespaces where there are two root namespaces (Microsoft and System).
ENOUGH WITH COMPILATION TIME AND LET’S MOVE TO .NET RUN-TIME The framework can be considered from the programmer’s point of view as a Runtime Environment ( WHERE YOUR APPLICATION RUNS ! )
“Common Language Runtime” (CLR) Yes, all the .NET languages go through the same runtime layer which is Common Language Runtime (CLR). CLR can be considered the virtual machine component of the .NET framework which is responsible for execution the .NET programs.
A PEAK ON CLR. CLR is responsible for translating the CIL Code to machine instructions so that it can be executed, also its responsible for low level details like garbage collection, application hosting, memory management, and various security checks.
LET’S GO WITH THE FLOW 1. First you write the source code in any .NET language like C#. 2. The C# Compiler translate your code to Common Intermediate Language emitting an assembly file or may be multi assembly files where the metadata (describing the types you used in your code) and the assembly manifest (describing the assembly itself) are placed.
3. CLR resolves the location of the assemblies needed for execution. (According to the namespaces you used in your source code).
4. CLR reads the metadata in the assemblies to find the requested types. 5. CLR layout the requested types in the main memory (RAM). 6. CLR compiles the CIL Code associated with the assemblies into machine language through a compiler termed as “JITT” (Just In Time Compilation).
7. Finally, the machine language instructions are executed.
Q&A
@ShawkyAmr0about.me/amr.shawky
shawkyamr0.wordpress.com