Transcript Document
.NET Whirlwind Intro for Rice Michael Stuart Sr. Consultant [email protected] Will Rice class of 1991 Chris Wafer Lowly Consultant [email protected] Jones class of 2000 Outline Who are we? (not an existential conundrum) What is .NET? Tools—Visual Studio OO, design patterns Mobile development CLR, CTS, CLI OO, JIT, GC Practical development with .NET 2002 vs. 2003, RTM vs. Everett vs. Whidbey Mongo debugging, templates, visual designers .NET Framework Overview Marketing mantra vs. reality Platform…for web services .NET CF (Compact Framework) Web Services Questions Who are we? Chris— Recent Rice grad, real CS not flaky other pseudoscience Consultant at Microsoft in South Region Specializes in .NET development Fingers possessed by l33t hax0rs of yore Thinks M3 is faster than M-Coupe, too young to know better Michael— Lovable but slightly addled uncle-type Old Rice grad—Biochem/Bio+PoliSci, M.D. Hacker of old, cut teeth in 6502 Assembler Specialized in .NET dev Currently working with PAG team on patterns What is .NET? Marketing mantra vs. reality Platform…for web services .NET Framework—Visual Studio, actual runtime, languages, web services are _really_ “.NET” “.NET Servers”—are .NET enabled but not necessarily written in .NET (CS2k, BizTalk…) Much more to-the-point: .NET is a platform for Web Services Other Loosely-coupled programming model New paradigm for Microsoft-based developers Much easier to write good code Focus on logic, not plumbing—we’ll wear the plumber jeans Tools 2002 vs. 2003, RTM vs. Everett vs. Whidbey VS.NET—complete tool for developing .NET (and old-school) software Encompasses all languages—C#, VB.NET, J#, 20+ others RTM—Framework v. 1.0.3705 Everett—currently beta, v. 1.1.4322 Whidbey—future, big changes (generics, built-in patterns, etc.) Mongo debugging, templates, visual designers Debugging—over the river, through the woods… Templates—strong future Designers—beloved RAD tools, beefier underpinnings now .NET Framework Overview CLR, CTS, CLI OO, JIT, GC .NET Framework Overview 2 Infrastructure for the .NET Platform Common Language Runtime Manages running code Verifies type safety Provides garbage collection, error handling, threading Security Provides common type system Provides access to system resources Native API, COM interop, etc. A collection of unified classes .NET Framework Overview 3 Win32 and the .NET Framework C# Visual Basic .NET ASP .NET ADO .NET Enterprise Services COM: Not Dead Yet CLR MSMQ Visual J#... COM+ Active Directory IIS Win32 CLR Executes code, maintains security, handles component “plumbing” and dependencies WMI Unified Class libraries Unifies Programming models across languages Factored for extensibility Designed for tools Enterprise Services The services required for mission critical applications: Transactions, Messaging, Partitions, Object Pooling and Events XML and Data Access ADO .NET interfaces any database, loosely coupled data access and native XML data format; leverages the huge library of ODBC OLE DB drivers XML Web Services and Scripting High-productivity environment for building and operating XML Web services .NET Framework Overview 3 CLR Duties Manages running code Threading Memory management / GC JIT to native COM Interop Security, type safety, bounds checks, assembly loading, remoting, etc. (all runtime stuff) Fine-grained evidence-based security Code access security IL can be verified to guarantee type safety No unsafe casts, no un-initialized variables and no out-of-bounds array indexing Role-based security Integrated with underlying OS .NET Framework Overview 4 ILDASM! Compilation and Execution Compilation Source Code Language Compiler Code Metadata IL_000c: br.s IL_002a IL_000e: ldloc.1 IL_000f: callvirt instance object [mscorlib]System.Collections. IEnumerator::get_Current() IL_0014: castclass [mscorlib]System.String IL_0019: stloc.0 IL_001a: ldstr "Flea's name : " MSIL Execution Native Code JIT Compiler Before execution (ngen) or the first time each method is called .NET Framework Overview 4 Simplified Development Eliminates COM plumbing No more … Registration GUIDs .IDL files HRESULTs IUnknown AddRef/Release CoCreateInstance =>self describing components =>hierarchical namespaces =>source code to metadata =>structured exceptions =>root object class =>garbage collector =>”new” operator Practical Development with .NET Demo—how to set up quickie web service (asmx) Demo—web-service-based Forth calculator Demo—Interfaces and Abstracts Demo—Virtual vs. Non-Virtual calls Debugging down to the metal: Memory view Register view X86 ASM view Demo—delegates and events Demo—how to screw up Boxing/Unboxing Demo—UIP “pet project” Demo—database access application (??) Practical Development with .NET Demo—how to set up quickie web service (asmx) Basic web service requires ASMX file + code ASP.NET HttpModule hooks up ASMX to code Compiles and JIT’s code Generates WSDL dynamically (SOAP contract) Core syntax: <%@ WebService Language="c#" Class="Calculator " %> [WebMethod] (try THAT in J2EE ) Practical Development with .NET Demo—web-service-based Forth calculator Now consume the calculator web service we made Uses stack-based calc Uses Compact Framework Accesses web service from Pocket PC device Note use of derived stack— IN FUTURE FRAMEWORK, GENERICS will do this Practical Development with .NET Demo—Interfaces and Abstracts .NET supports Abstract base class Base functionality Not instantiable Good use: “is a kind of”, abstract entity meaningless— Multiple interface implementation Single inheritance—NO multiple inheritance Mammal abstract base—but there’s no plain “mammal” animal Lion : Mammal—concrete derivative has meaning but borrows basic functionality such as sleep, heartbeat from abstract Interface implementation Heavy use of “marker” interfaces in .NET (IDisposable) Provides strict contractual obligation No base functionality Practical Development with .NET Demo—Virtual vs. Non-Virtual calls Non-default virtual in .NET Public void Foo() in class A Public new void Foo() in Class B : A Public virtual void Foo() in class C Public override void Foo() in Class D : C D.Foo does D.Foo; ((C)D).Foo STILL does D.Foo Be careful of deep inheritance chains B.Foo does B.Foo; ((A)B).Foo does A.Foo If middle of chain does “new”, THAT is where it stops! UNLESS you play games with versioning .NET avoids “Base Class Fragility” with versioning! Practical Development with .NET Demo—delegates and events Fundamental Rule #1: Delegate syntax: “A Delegate is a Type-Safe Function Pointer!” James Gosling (father of Java) calls Anders Heljsberg “Mr. Function Pointers” Anders is too polite to respond public delegate void DoneCookingDelegate(); Delegates are always multi-cast; you can chain them up Delegates can be declared anywhere; if they’re accessible they’re good Delegates point to a concrete endpoint that matches signatures EVENTS in .NET are special-case delegates Practical Development with .NET Demo—how to screw up Boxing/Unboxing How is .NET so FAST? Value Types vs. Reference Types Singly-rooted hierarchy; ALL objects derive from System.Object—ints, strings, doubles, even kids with chickenpox An Int32 is an object if you treat it like one, otherwise it’s stack-allocated Value types go on stack—int, double, long, struct, double, decimal, uint, etc. Reference types are officially objects all the time and go on HEAP .NET can BOX—convert value type to ref type .NET can UNBOX—convert ref to value Be Careful—boxing implicit, unboxing explicit QUESTIONS??? Thank you all Very Much! Michael Stuart—[email protected] Chris Wafer—[email protected]