Title: A C
1A C Primer
- Robert Burke
- MLE
- 28 jan 03
2Obligatory 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 youve used Visual Studio
3Whats on tap today
- In Summary Why would you consider using C for
your next project?
4Disclaimer
- Havent traditionally been a huge Microsoft fan
- But, when theyre right
- So, if you can, put aside biases, religious
attachment to (or disdain for) an OS, etc.
5Part I Language Evolution
6Part I Language Evolution C
- Intimate with hardware, therefore very fast
language - Primarily used primitive types for working with
data - You handle all memory allocation and deallocation
- include ltstdio.hgt
- void main(void)
-
- printf("Hello world!")
-
Image Kernigan, Ritchie et al, C Programming
Language
7Part I Language Evolution C
class Greeter public virtual void
ExtendGreeting() 0
- 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!")
-
class FrenchGreeter public Greeter
public void ExtendGreeting()
printf("Bonjour!")
int _tmain(int argc, _TCHAR argv) Greeter
myGreeter new FrenchGreeter() myGreeter-gtExte
ndGreeting() delete myGreeter return 0
Image Stroustrup, The C Programming Language
8Part I Language Evolution Java (1/3)
- 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()
-
9Part 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
10Part 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
11Part II About C
12Part 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
13Hold up Whats all this .NET malarky?
- The .NET framework in context.NET for the common
man.NET
14Comparative Language Studies
15C 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
16The Need for Execution Speed
- 98 of the speed, for 50 of the code
- Thats the Managed (C) DirectX 9.0 stat
- Well, Dolphin demo
- 565 lines C
- / 738 lines C 76 of the code, but whos
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 CLRs garbage collector. - StillLifes 1600 particles/s, smooth, is
unthinkable using existing Java JVM
implementations
17Development 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 code3
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
18Development EnvironmentLanguage doesnt exist
in a vacuum!
- The .NET Framework Class Library
- New set of very polished libraries
- Accessible from C, C, Visual Basic.NET
- Cs objects and interfaces perfectly tailored
- Common development environment hand-holds you
- Comments
- step into native code. etc. (DEMO)
19Deployment
- 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
20Part III Proof by Example
- Or, how to demo development speed, and where we
might go from here.
21How 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 (lt6 days)
- built on an early version of Ching. Particle
system, video input, video processing effects all
in C, using OpenGL
22How 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 DLLs 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...)
23Collaboration?
- 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?
24Summary 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
25Some 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 worlds most patient guinea pig
- You, for expressing interest
- Places to learn more
- Jesse Libertys Programming C, OReilly
- http//www.gotdotnet.com (semi-official site)
- http//www.csharphelp.com (community site)
- news//microsoft.public.dotnet.languages.csharp
- The third floor
- Thoughts?