Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp)...

Preview:

Citation preview

Richard Parker http://blog.richard.parker.name

Richard Parker (twitter: @rikp)

.NET developer

Specialising in web apps + cloud

Love tech!

.NET Framework (from 20,000ft)

Why do we have it?

What problems does it try to solve?

What does the architecture look like?

Demos Q&A

System Programmers

Low Level

Speed, Performance

Application Programmers

Result Oriented

Not concerned with environment

C/C++

Code …

had to target a specific environment

wasn’t re-usable across platforms

errors could easily crash the system

Plus …

Writing code to target different platforms = tough

Very repetitive

.NET Framework

Console

WinForms

Windows Services

ASP.NET Applications

ASP.NET Web

Services

Mobile Applications

(WP7 etc)

Silverlight

Consistent OOP environment Environment must:

Minimise deployment and version conflicts

Promote safe execution of code

Eliminate performance issues of interpreted/scripted environments

Provide consistent experience across widely varying types of applications (Web/Win/Mob)

Be based on industry comm. standards

I/O Devices, Memory, CPU

System (O/S)

Common Type System

Common Language Runtime

Class Library

Source Code

• C#, VB.NET…

CIL

• Common Intermediate Language

Native

• JIT compilation

CIL code is interchangeable

Networking

Security

I/O

Web

Compile once, run on any CPU or O/S Manages

Code at execution time

Memory and threads

Garbage collection (more on this later)

Enforces type safety

C#, VB.NET

F#, J#, C++, [ … ]

LOLCODE HAI

CAN HAS STDIO?

VISIBLE "HAI WORLD!"

KTHXBYE

Many language choices

Compiled into CIL

All running on the CLR

CLR manages memory, threads etc.

CLR is CPU independent

A look at the roles and responsibilities of the CTS

How types are represented in memory Cross-language integration

Defines rules to be followed by languages

Rules defining type inheritance

Rules for object lifetime

Two types of type! Reference types

The value is a reference to another memory block containing the data

Object, String

Value types

The value is the data

Int, bool

Everything is either a VALUE

or a REFERENCE

type

Two types of memory

Stack (Value Types)

▪ Instance variables

▪ LIFO – think boxes stacked atop one another

▪ Static; i.e. primitive values live here

▪ The data is the value

Heap (Reference Types)

▪ Dynamic; i.e. complex types (objects)

▪ Pointers to other memory areas stored here

▪ Reference pointers allocated on the stack, though.

Stack

• Values

• Boxing

Heap

• References

• Unboxing

Demo #1 Boxing and Unboxing Speed Comparison

Stack data is de-allocated from memory sequentially, but:

Memory on the heap is not automatically de-allocated

It waits for the Garbage Collector

This can cause problems

But mostly – it’s fire and forget!

Manages allocation and release of memory Space not infinite! The GC must ‘collect’ in order to free memory Self-optimising

It’s boring and complicated Efficiently allocates objects on managed heap Reclaims unused objects for you Memory safety – objects cannot use content

of another object

Demo #2 Application Memory and Garbage Collection

Fundamental concepts you’ll need when starting your journey into the world of the .NET Framework

Namespaces are collections of objects and other namespaces

Logical containers Dot syntax denoting hierarchy

System.Web.UI is in the System.Web namespace, which is in the System namespace.

Base class – root of type hierarchy Derivation is implicit Common base methods:

Finalize()

GetType()

ToString()

Derived classes can and do override some of these base methods, like Equals().

The CLR allows code re-use between projects targeting different platforms

Code is organised into projects which can be grouped into solutions

Demo #3 Sharing Code Between Projects

Recommended