Keine Notizen für die Folie
Sample Dialog: Speaker Instructions: You should introduce yourself on this slide. Briefly address the topic of the evening and mention the length of the presentation. You can also discuss the nature of your organization (user group, etc.) while on this slide.
Sample Dialog: The .NET Framework is a new computing platform developed by Microsoft. It can be somewhat difficult to describe, because it plays a number of roles. It is a software development environment and SDK. It is a runtime environment for executable code, and it is a platform with many features of an OS. C# and other languages can be used to target the .NET Framework, and the .NET Framework as a platform is designed to target the Internet.
Sample Dialog: The common Internet software of today includes a client which communicates with a web server. The client is most likely running a browser or some other standard client such as an FTP client. The Server is running any of a number of server products to serve the client. Moving forward, the lines of communication will open up. Second and third tiers will communicate directly with clients. Clients will communicate with each other in a pier-to-pier relationship, and servers across realm and company boundaries will also communicate on a pier-to-pier bases. The nature of the communication itself will also expand. At this time most communication is either HTML over HTTP or HTTPS, or it is proprietary. However, moving forward, SOAP and XML will allow for more flexible communication between parties. Traditionally, writing software that runs on the client (typical applications, as well as client applications) is vastly different from writing server or back-end server programs. The tools and languages differ, as well as the libraries and reusable code. This makes programming for the Internet difficult and often inefficient. The .NET Framework is built from the ground up to target each level shown on this slide. Meanwhile the language, libraries, and tools you prefer can be used for client and server tasks. Speaker Instructions: There is a lot of sample dialog on this slide you can pick which points you wish to make. The last sentence is important though.
Sample Dialog: Before digging too deeply into what the .NET Framework is and does, I would like to show a little C# code. C# is only one of the languages that you can use to write .NET programs, however it is one of the most popular. Speaker Instructions: Consider bringing up this source code in an editor. Either way, walk through the code. Point out the class definition as well as the main function. Point out that this code has a C-based syntax much like Java or C++. Point out the use of preexisting types such as Application and Form. On the next slide you should compile and run the code, and perhaps briefly explain how it works.
Sample Dialog: Now I am going to compile and run the C# program from the last slide. As you can see it is a simple “Hello World” GUI application… Speaker Instructions: You can use Visual Studio or the command line compiler here to run this code. You should explain how the code works. Point out that this is an example of a managed application, and that you will define that term in more detail shortly. The source code for HelloGUI.cs is included as a Visual Studio.NET with this module.
Sample Dialog: The .NET Framework is made up of several parts. One of the most important pieces of the framework is the Common Language Runtime or CLR. The CLR is a runtime engine that manages .NET code as it is running. Management includes security management, memory management, thread management and a host of other system services. For this reason all code targeting the .NET Framework (including C# code) is called Managed Code There are a number of language compilers that produce managed executable files. C# is a popular language, but you can use Java, Visual Basic, C++, Cobol, PERL, etc. Speaker Instructions: It is important that the reader understand that what is true of managed code is true across all languages that can be managed. The cross language abilities of the .NET Framework are a big win for programmers. This is why it is helpful to refer to executables and modules as managed executables and managed modules, rather than always saying C# executables (since C# is a specific language).
Sample Dialog: You can see here the relationchip between your managed executable, the CLR, and the underlying operating system. The CLR runs on Windows (and other operating systems in the future). Managed code runs on the CLR, and makes use of reuseable object libraries (often managed as well). Legacy or unmanaged software runs along-side managed code. Speaker Instructions: Managed code is not interpreted. This slide can give that impression. It is important to note that this is not the case, and emphasize it later on when we cover JIT compiling.
Sample Dialog: What makes a managed executable managed is the fact that it is made up of IL instructions and metadata. IL stands for Intermediate Language, and is a “CPU independent assembly language.” Managed code logic is represented as IL rather than x86 machine language instructions. Metadata is also an important part of managed code. In fact, a managed EXE would not be manageable without its metadata. The metadata describes everything that can’t be described by IL. That is to say that metadata describes everything but the executable logic. This includes class definitions, method definitions, parameter types and return types. Between metadata and IL, the CLR has enough information about your managed code to insure type-safety at all times. Speaker Instructions: The type safety issue is an important one as code modules become increasingly distributed over the Internet. It might be a bit much to attempt to relay this in an hour session.
Sample Dialog: So if you look at this diagram, you can see that you start with a C# source file (this could be any .NET language), and then compile it. What the compiler produces is an .EXE file that contains Metadata and IL (always in the same file). This is a managed executable. Note that IL is not C#, and by the time your software is in binary form it has no relationship to its source language. Speaker Instructions: This last point is an important first step in understanding the language agnosticism of the .NET Framework. Language agnosticism is a major improvement over Java. If anybody asks if IL is basically another name for p-code say, “yes and no”. Here are the facts. IL is programming language agnostic, where p-code is typically tied to a language. IL builds on the good parts of p-code, but moves forward. Another difference is that IL is always JIT compiled, and executed in native machine language, where p-code is often interpreted. By the way, just FYI, Sun did not create p-code. P-code has existed long before Java. There were p-code Pascal compilers in the 70’s. (You don’t have to bring this up unless you are pressed by someone who thinks that IL is just a stolen idea).
Sample Dialog: One great thing about managed code is that it is NOT interpreted. ALL managed code runs in native machine language, even though it is represented as CPU independent IL. This is possible, because at runtime the CLR Just-In-Time compiles (or JIT compiles) the IL into native code, and then it executes the code. This really does allow for the best of both worlds between code interpretation and the performance of native machine language. Speaker Instructions: JIT compiling is a cool feature, and you should feel comfortable with the concepts behind it before presenting in class. There are often a number of questions on this topic. The tutorial goes into JIT compilation in some detail.
Sample Dialog: When a user executes a managed application, the system immediate loads the CLR unto the new processes. The CLR then begins JIT compiling the IL from the executable and executing it. It is not necessary for every IL instruction in an executable to be JIT compiled before it is run. This happens as needed. Once the code is running, it is run directly by the CPU. However, the JIT compiler emits code that insures that your program remains manageable by the CLR. So even though the code is running native, it is always managed code. Speaker Instructions: The notion of managed code running in native machine language can be tough to comprehend. But the point is that it is IL until the point of running. It is the CLR that creates the machine language, so it has all of the control necessary to maintain the managed status of the software.
Sample Dialog: One very important aspect that the CLR manages for your .NET code is memory management. All memory allocations come from a Managed Heap. Your code never explicitly frees memory. Once memory is no longer referenced by your software it is eligible for Garbage Collection. Although memory management can be a fun part of computer programming, it is important for managed code to allow the system to manage memory, because moving forward many applications will be comprised of objects developed elsewhere and distributed across the internet. Since we can’t trust these objects to have boundless access to memory, it is important that memory is managed. Additionally, so very painful and common memory bugs are impossible with managed code. Speaker Instructions: Often there are questions about performance related to the Garbage Collector. Here are some facts. Garbage collection takes time but happens rarely Meanwhile, managed heap allocations are MUCH faster than a malloc or new in C++ Memory fragmentation is impossible with the managed heap, so memory is used MUCH more efficiently with the managed heap.
Sample Dialog: Garbage collection can happen at any time that your program needs memory. It typically happens in response to a “new” operation. When a garbage collection occurs, garbage objects and memory buffers are removed from the managed heap. In this example, if a garbage collection were to occur during the execution of the Method() method, objects A and D would be cleaned up, because they are not referenced by code, nor are they referenced by objects that are referenced by code. Speaker Instructions: The arrows pointing from one object to the next in the managed heap indicate fields in objects that refer to other objects in the managed heap. The arrows pointing from the source code to the heap indicate reference variables on the stack in your running code, that refer to objects in the managed heap.
Sample Dialog: Because managed code is IL and metadata, it is possible for any compiler to be modified to produce managed code. All it needs to do is produce an EXE comprised of IL and Metadata, and now the exe can run with the CLR. There are many languages already in existence or in development that target the .NET Framework. The advantage is that programmers can use their language of choice while being able to use the same tools and code libraries as any other managed code. Speaker Instructions:
Sample Dialog: Visual Studio.NET is not part of the .NET Framework, however it is a great development environment for building .NET code. You can use the command-line compilers that come with the .NET Framework to build managed code, however Visual Studio.NET includes useful wizards and tools that the .NET Framework does not ship with. It is important to distinguish between Visual Studio and the .NET Framework. The .NET Framework is a platform (and an SDK). Visual Studio is an Integrated Development Environment that targets the platform that is the .NET Framework. Speaker Instructions: Visual Studio costs money, the .NET Framework is free.
Sample Dialog: Speaker Instructions: You should bring up Visual Studio.NET and create a C# windowed project. Drag and drop a button or two onto the form, and then build and run the application. Show the code that was produced by the designer. Point out that this code could be written from scratch, but that Visual Studio makes the development process much easier.
Sample Dialog: The CLR is object oriented through and through. So is C#. You will find that you make use of reusable object libraries a lot when writing managed code. The Framework Class Library (or FCL) is a huge object library that ships with the .NET Framework. It has many classes, interfaces, and structures (collectively called “types”), that help you do a number of common and advanced programming tasks. Familiarity with the FCL is critically important for a .NET developer. You will find classes in the FCL for creating and manipulating files, collection classes, windowing and GUI programming, web-sight development and hundreds more. Additionally, the FCL is built for extension, so it is common to write software that derives from classes in the FCL to extend their features. Speaker Instructions: The lines between applications and components will become much blurrier. This important in the evolution of the software industry in general.
Sample Dialog: Types in the FCL are arranged in a hierarchy of namespaces. It is helpful to be familiar with the namespaces, so that you can find related types more easily. A types full name includes its namespace. So in your code you may refer to a type named “Form”, however the CLR will always think of the type as System.Windows.Forms.Form, where System.Windows.Forms is the type’s namespace. Types are also published in files called assemblies. The sdk documentation indicates a types namespace and assembly. The namespace should be added to the top of your source module (if you are using the type) with a “using” statement. The assembly for a type should be added to your project references when building the program. Speaker Instructions: Become comfortable with assembly references and the using statement before presenting this slide. You will most likely get questions. The Visual Studio.NET IDE allows you to add references to your project. These references are assemblies, and the appropriate assembly to choose depends on the types that you are using in your sources.
Sample Dialog: Speaker Instructions: You should bring up the help topic for System.Windows.Forms.Form and walk through the different parts of the help. You can use the topic in the tutorial as a guideline for what parts to show in the help. The MOST important parts are the namespace and assembly items near the bottom of the help. But it is also useful to point out the sample code and other information in the topic.
Sample Dialog: Now that we have discussed the .NET Framework in general, it is good to cover what you can do with it. First of all, you can write typical applications. These are your standard GUI or console applications that run on the users machine. More importantly, however, managed code and the FCL are designed to promote Internet distributed code. This includes web-pages that run as software on the server side. This also includes web-services which are a non GUI server-side object. Web-servers can distribute managed objects to be executed locally on the client. In this respect, managed code can run just about anywhere, and makes for some very interesting application design possibilities. Finally, the CLR can be hosted in any application. This makes it possible to use managed code as the script or macro language for your program. Meanwhile, wherever managed code runs, it is always language agnostic, JIT compiled and executed natively, and it always has full access to the FCL. Speaker Instructions: The win here is that when you get comfortable writing any kind of C# application you can apply those skills to more advanced or vastly different types of applications. No more learning a whole net set of “stuff” just because your application is a different kind of application.
Sample Dialog: So now we can take a look at the distributed code slide, and apply our knowledge of managed code. If you are writing a client component, then your managed program is likely to using Windows.Forms for GUI and the FCL classes for communicating with servers. Client code can also be hosted in a browser. If you are writing web server code, then the CLR is hosted in a server product like IIS and you are probably writing Web Forms or Web Services code. Your software is still C# or VB or whatever language you choose, but now it runs with all of the services of a high-scalability web-server. Finally, second tier servers like data-base servers can host managed code. Managed code can be used as stored procedures or just about any logic in an application that hosts the CLR. The benefit is that you get to use tools, languages, and code that you are already comfortable with. Speaker Instructions: This is a repeat of the slide found earlier in the deck. When presenting this slide, you should point to a client box, and describe the kinds of managed code that runs there. Then the web-server, then the second tier. This helps round out the user’s understanding.
Sample Dialog: In closing I would like to demo a simple Web Forms application. This application runs on the server side, and is hosted in IIS. Any browser can be used to browse to this application. (It does not need to be running on Windows). Speaker Instructions: You should browse to the Draw.aspx file and show how the application works. Then you should show the source code for the application. Point out that the website is implemented using C# like any other application. If you have time, run through the logic of the code. Point out to the user that the code comes with the tutorial and they can try it themselves. Also point out that Web Forms are an advanced topic and that an entire session is devoted to the topic.
Sample Dialog: Speaker Instructions: Open the floor to questions