Wednesday, September 17, 2008

Dotnet and C# Begginner Series Part-1

Important Learning

1. Common Language Specification is a part of Common Type Systems which in turn is a part of Common Language Runtime.

2. We can take any language and if we can have or make a .net aware compiler for that language then we are done ie we can start writing code in that language and it will run on .net framework installed machines.We needn’t worry about the platform now, as .net will take care for that.

3. Single file assemblies and multifile assemblies.The difference is that we can have all our referenced code in a single assembly it is beneficial when we have only a small application and our client needs to download only a small part ie only that assembly and that’s done.But if we are making a big application in which there are thousands of small application so we neednot place everything into a single assembly whereas we can place things in different assemblies the benefit is that if our clients need some network related stuff so he can download that assembly and start working he needn’t download the whole application as such so it reduces the download time and make process faster.

4. What actually happens for those people who don’t know .net and are programmers in other languages is that first we write code in any .net language let’s be concerned now with only the languages which ship with .net.Now all these languages such as VB.Net ,C#,C++/CLI,J#, follow Common Type Specification and Common Language System.So if you write Dim myInt as Integer in and someone else write int myInt in C# it will be compiled by vbc.exe and csc.exe to same thing ie Sys.Int32 which is the example of Common Type System and thus it means they are same at the Intermidiate Language Level

5. What these compilers do is they generate Intermediate Language which is not instruction set specific ie which is not platform specific ie it does not contain any platform specific information which earlier COM assemblies ie .dll and .exe used to do.

6. One important point which comes here is that the assemblies generated by .net are different then the dll and exes generated by the COM components.

7. COM used to generate platform specific dlls or exe’s but .net generates dll’s and exe’s which contain metadata and CIL .

8. This metadata consists of manifest files which contains information about the assembly like versioning,culture information,and list of externally referenced assemblies which are required to run that assembly.

9. CIL or Common Intermidiate Language or MSIL or IL whatever you can call it is in some sense same like Java Bytecode ie they both are not platform specific.

10. ByteCode in Java contains information which Java Virtual Machine understands and then generate or run the required operating system calls and resource allocation based on operating system and the architecture.For example if I have written in my Java Code that allocate me 2MB of ram.Now the bytecode will ask the virtual machine to allocate the resource now it’s the duty of virtual machine to do the heavy lifting and make system calls or any other thing to allocate the resource.

11. So lets consider different OS only not different architectures os let say x86 architecture,and Windows platform ,now here for allocating RAM the system call could be alloc_mem(amount) so it’s the work of Virtual machine to make this call.

12. On x86 and Linux this system call might change and we could have mem_alloc(totalamount) so again it’s the work of JVM specific to x86 Linux to make that call and execute the code.

13. So a question can be why not have a single JVM which could do all this for all platforms and architecture.In theory we can have single JVM also which can first perform a check for architecture and then for the operating system and then execute in a specific way,but its not necessary because such JVM will be huge in size and too complex and slow and also as it has bigger size it would be a waste of time and network resources for the client to download that.

14. If the client doesnot need any support for Windows , Solaris,Mac,Novell and etc.. he only needs it for linux then why should he download all crap.Thus I think they have different JVM’s there might be other limitations when we come to architecture.

15. So this was the story of JVM similar thing happens here in .net also when we get CIL now when we want to run and execute this code we need a Just In Time compiler which will compile this to the platform specific information.

16. So there are two compilations going on one when the code was compiled from its base language to the IL and another compilation is when the IL code is executed.

17. This second compilation is also managed by .net framework it searches for the platform and make the required calls and allocate the required resources just like we have seen in the concept of JVM

18. For .net languages we have support of Base Class Libraries which are simply collections of pre-defined classes which we can use as starting point and then implement bigger things over them.

19. This BCL is divided into many parts grouped under various meaningful namespaces.


Post a Comment