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

Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Page 2: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

Richard Parker (twitter: @rikp)

.NET developer

Specialising in web apps + cloud

Love tech!

Page 3: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

.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

Page 4: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

System Programmers

Low Level

Speed, Performance

Application Programmers

Result Oriented

Not concerned with environment

C/C++

Page 5: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Page 6: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

.NET Framework

Console

WinForms

Windows Services

ASP.NET Applications

ASP.NET Web

Services

Mobile Applications

(WP7 etc)

Silverlight

Page 7: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Page 8: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

I/O Devices, Memory, CPU

System (O/S)

Common Type System

Common Language Runtime

Class Library

Page 9: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

Source Code

• C#, VB.NET…

CIL

• Common Intermediate Language

Native

• JIT compilation

CIL code is interchangeable

Networking

Security

I/O

Web

Page 10: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Page 11: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

C#, VB.NET

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

LOLCODE HAI

CAN HAS STDIO?

VISIBLE "HAI WORLD!"

KTHXBYE

Page 12: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

Many language choices

Compiled into CIL

All running on the CLR

CLR manages memory, threads etc.

CLR is CPU independent

Page 13: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

A look at the roles and responsibilities of the CTS

Page 14: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

How types are represented in memory Cross-language integration

Defines rules to be followed by languages

Rules defining type inheritance

Rules for object lifetime

Page 15: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Page 16: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

Everything is either a VALUE

or a REFERENCE

type

Page 17: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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.

Page 18: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

Stack

• Values

• Boxing

Heap

• References

• Unboxing

Page 19: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

Demo #1 Boxing and Unboxing Speed Comparison

Page 20: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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!

Page 21: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Page 22: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)
Page 23: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Page 24: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

Demo #2 Application Memory and Garbage Collection

Page 25: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Page 26: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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.

Page 27: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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().

Page 28: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

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

Code is organised into projects which can be grouped into solutions

Page 29: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)

Demo #3 Sharing Code Between Projects

Page 30: Richard Parker ://brainthings.files.wordpress.com/2011/07/... · Richard Parker (twitter: @rikp) .NET developer Specialising in web apps + cloud Love tech! .NET Framework (from 20,000ft)