1 / 25

A C# Primer

A C# Primer. Robert Burke MLE 28 jan 03. Obligatory Strong Start. “C# still on track to become number 1 [programming language] within 2 years time” Tremendous Momentum: DirectX API Compact devices Next version of Office Platform for XML If you’ve used Visual Studio….

gay-morrow
Download Presentation

A C# Primer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A C# Primer Robert Burke MLE 28 jan 03

  2. Obligatory Strong Start • “C# still on track to become number 1 [programming language] within 2 years time” • Tremendous Momentum: • DirectX API • Compact devices • Next version of Office • Platform for XML • If you’ve used Visual Studio…

  3. What’s on tap today • In Summary: Why would you consider using C# for your next project?

  4. Disclaimer • Haven’t traditionally been a huge Microsoft fan • But, when they’re right… • So, if you can, put aside biases, religious attachment to (or disdain for) an OS, etc.

  5. Part I: Language Evolution C C++ Java C#

  6. Intimate with hardware, therefore very fast language Primarily used primitive types for working with data You handle all memory allocation and deallocation #include <stdio.h> void main(void) { printf("Hello world!"); } Part I: Language Evolution: C Image: Kernigan, Ritchie et al, C Programming Language

  7. Superset of C Introduction of objects and object-oriented programming to C Inheritance, etc. A very powerful language the power comes at a cost of complexity class EnglishGreeter : public Greeter { public: void ExtendGreeting() { printf("Hello!"); } }; Part I: Language Evolution: C++ class Greeter { public: virtual void ExtendGreeting() = 0; }; class FrenchGreeter : public Greeter { public: void ExtendGreeting() { printf("Bonjour!"); } }; int _tmain(int argc, _TCHAR* argv[]) { Greeter *myGreeter = new FrenchGreeter(); myGreeter->ExtendGreeting(); delete myGreeter; return 0; } Image: Stroustrup, The C++ Programming Language

  8. Purely object-oriented Handles all memory deallocation – “garbage collection” (Geek alert) “Elimination” of pointers Polished set of libraries (API) available on all platforms public interface Greeter { public void extendGreeting(); } public class EnglishGreeter implements Greeter { public void extendGreeting() { System.out.println("Hello!"); } } public class GraciousApplication { public static void main(String[] args) { new EnglishGreeter().extendGreeting(); } } Part I: Language Evolution: Java (1/3)

  9. Part I: Language Evolution: Java (2/3) • Possible to interact with “native” C/C++ code. • Very useful for: • Integrating “legacy” code • Speed: optimizing a critical bit of code • But, difficult to debug, for example: • Primitive type size can change between platforms • No common debugging environment

  10. Part I: Language Evolution: Java (3/3) • Garbage collection and cross-platform made possible by the Java Virtual Machine (JVM) • Compiles to interpreted bytecode instead of machine instructions • Multiple benefits: • Cross-platform • Garbage collection • Downsides: • Abstraction between you and hardware, therefore less deep control • A little slower, but “Just-In-Time” (JIT) compiling helps Your Java app Java API JVM (Virtual Machine) Operating System

  11. Part II: About C#

  12. Part II: Enter C# • A hybrid language incorporating features from C++ and Java (and Smalltalk, and…) • Looks a lot like Java, with keywords from C/C++ • Object oriented • Has a virtual machine, and garbage collection, among other Java parallels Your C# app .NET FrameworkClass Libraries CLR (Common Language Runtime) Operating System

  13. Hold up… What’s all this .NET malarky? • The .NET framework in context.NET for the common man.NET

  14. Comparative Language Studies

  15. C# Pros and Cons • Biggest Cons • Compared to C++: Simpler programming model comes at cost of some geek-power • Compared to Java: Currently, no CLR implementation for Mac • (but, a word on cross-platform: “Mono,” for Linux, in the pipe) • Biggest Pros • Compared to Java: Execution Speed • Java JVM code is designed to be interpreted • C# CLR code is always compiled (despite common misconception) • Compared to C, C++, Java: Development Speed

  16. The Need for Execution Speed • “98% of the speed, for 50% of the code” • That’s the Managed (C#) DirectX 9.0 stat • Well, Dolphin demo: 565 lines C# / 738 lines C++ = 76% of the code, but who’s counting. • DEMO: • Dolphin 37 fps C++, 36 fps C# • PointSprites 37 fps C++, 37 fps C# • Something hard to quantify - the smooth, smooth lovin’ of the CLR’s garbage collector. • StillLife’s 1600 particles/s, smooth, is unthinkable using existing Java JVM implementations

  17. Development Speed (because our time is worth it)™ • C# language design theme: making the intent explicit in situations which can easily lead to subtle bugs. • (geek alert) e.g. ‘Versioning’ keywords (override, new, virtual) • Language features not available to Java • Delegates • Properties • Type system • Rich capacity for interop with native code…3 different methods: • 1. "unsafe" (unverifiable) code blocks provide access to pointers • 2. “Platform invoke" - access other DLLs (Java's only option) • 3. COM interop - tap into old COM stuff

  18. Development Environment:Language doesn’t exist in a vacuum! • The .NET Framework Class Library • New set of very polished libraries • Accessible from C++, C#, Visual Basic.NET • C#’s objects and interfaces perfectly tailored • Common development environment hand-holds you • Comments • step into native code. etc. (DEMO)

  19. Deployment • And, importantly, the deployment method: • You make .EXEs and .DLLs. • What does someone else need to run a C# .exe? • Just the free .NET Framework

  20. Part III: Proof by Example Or, how to demo development speed, and where we might go from here.

  21. How to demo Development Speed? • Ching (Dec 2001 - present) • libraries for signal processing, as well as serial port communication, audio, video... • the foundation of all the projects I've built this year • Sponge (Half a week) • uses UDP to poll for computers on the LAN, considers their processor speed and available processing power, and distributes signal processing tasks between them. has the capacity to deploy signal processors to the other machines first • Still Life (<6 days) • built on an early version of Ching. Particle system, video input, video processing effects all in C#, using OpenGL

  22. How to demo interoperability, powerful libraries, collaboration? • Contributions to Breathing Space • Great demo of interop with existing software in C++. • Daragh has built and worked with an extensive amount of graphics code in C++. Used remote signal processing. He just calls a DLL’s get function • Heartheard (crappy working title) (2 days) • Exposed DirectSound3D and made an application with 3D audio and effects, which maps heart rate and breathing to audio. • Eva's Anthropos robot • Uses vision tracking modified from Still Life, using Signal Processing Network from Ching (which leads nicely to...)

  23. Collaboration? • If there is interest, I would manage the source tree more carefully • Could it lead to more complex projects? • 90% of the codebase compiled for the CompactFramework… how about that?

  24. Summary: Why would you use C# for your next project? • In a word: productivity • Just as Java learned from C++… • Nominal speed hit, tremendous productivity boost • Possibility of making use of existing Ching and MiniChing libraries

  25. Some props, and where to go next • Thanks • Eric Gunnerson and the GotDotNet team • MindGames, for letting me get away with this • Eva for being the world’s most patient guinea pig • You, for expressing interest… • Places to learn more • Jesse Liberty’s Programming C#, O’Reilly • http://www.gotdotnet.com (semi-official site) • http://www.csharphelp.com (community site) • news://microsoft.public.dotnet.languages.csharp • The third floor • Thoughts?

More Related