Upload
xamarin
View
3.478
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Giant Disclaimer I’m here as me, doing my thing. These opinions are mine, Scott Hanselman. If I say something stupid and you’re a journalist, make sure to quote me as “Scott Hanselman, Stupid Guy.” I’m not the manager of anything important at Microsoft. I am a member of the .NET Community. I care.
How C# Saved My Marriage,
Enhanced My Career, and Made Me An Inch Taller
Scott Hanselman@shanselman
How C# Saved My Marriage,
Enhanced My Career, and Made Me An Inch Taller
Scott Hanselman@shanselman
_ _ _____ _ _ | | | | / __ \ _| || |_ | |_| | ___ __ __ | / \/|_ __ _| | _ | / _ \ \ \ /\ / / | | _| || |_ | | | || (_) | \ V V / | \__/\|_ __ _| \_| |_/ \___/ \_/\_/ \____/ |_||_| _____ _ ___ ___ ___ ___ _ / ___| | | | \/ | | \/ | (_) \ `--. __ _ __ __ ___ __| | | . . | _ _ | . . | __ _ _ __ _ __ _ __ _ __ _ ___ `--. \ / _` |\ \ / / / _ \ / _` | | |\/| || | | | | |\/| | / _` || '__|| '__|| | / _` | / _` | / _ \ /\__/ /| (_| | \ V / | __/| (_| | | | | || |_| | | | | || (_| || | | | | || (_| || (_| || __/ _ \____/ \__,_| \_/ \___| \__,_| \_| |_/ \__, | \_| |_/ \__,_||_| |_| |_| \__,_| \__, | \___|( ) __/ | __/ | |/ |___/ |___/ _____ _ _ ___ ___ _____ | ___| | | | | | \/ | / __ \ | |__ _ __ | |__ __ _ _ __ ___ ___ __| | | . . | _ _ | / \/ __ _ _ __ ___ ___ _ __ | __| | '_ \ | '_ \ / _` || '_ \ / __| / _ \ / _` | | |\/| || | | | | | / _` || '__| / _ \ / _ \| '__| | |___ | | | || | | || (_| || | | || (__ | __/| (_| | | | | || |_| | | \__/\| (_| || | | __/| __/| | _ \____/ |_| |_||_| |_| \__,_||_| |_| \___| \___| \__,_| \_| |_/ \__, | \____/ \__,_||_| \___| \___||_| ( ) __/ | |/ |___/ _ ___ ___ _ ___ ___ | | | \/ | | | | \/ | __ _ _ __ __| | | . . | __ _ __| | ___ | . . | ___ / _` || '_ \ / _` | | |\/| | / _` | / _` | / _ \ | |\/| | / _ \ | (_| || | | || (_| | | | | || (_| || (_| || __/ | | | || __/ \__,_||_| |_| \__,_| \_| |_/ \__,_| \__,_| \___| \_| |_/ \___| ___ _____ _ _____ _ _ / _ \ |_ _| | | |_ _| | || | / /_\ \ _ __ | | _ __ ___ | |__ | | __ _ | || | ___ _ __ | _ || '_ \ | | | '_ \ / __|| '_ \ | | / _` || || | / _ \| '__| | | | || | | | _| |_ | | | || (__ | | | | | | | (_| || || || __/| | \_| |_/|_| |_| \___/ |_| |_| \___||_| |_| \_/ \__,_||_||_| \___||_|
Scott Hanselman @shanselman
_ _ _____ _ _ | | | | / __ \ _| || |_ | |_| | ___ __ __ | / \/|_ __ _| | _ | / _ \ \ \ /\ / / | | _| || |_ | | | || (_) | \ V V / | \__/\|_ __ _| \_| |_/ \___/ \_/\_/ \____/ |_||_| _____ _ ___ ___ ___ ___ _ / ___| | | | \/ | | \/ | (_) \ `--. __ _ __ __ ___ __| | | . . | _ _ | . . | __ _ _ __ _ __ _ __ _ __ _ ___ `--. \ / _` |\ \ / / / _ \ / _` | | |\/| || | | | | |\/| | / _` || '__|| '__|| | / _` | / _` | / _ \ /\__/ /| (_| | \ V / | __/| (_| | | | | || |_| | | | | || (_| || | | | | || (_| || (_| || __/ _ \____/ \__,_| \_/ \___| \__,_| \_| |_/ \__, | \_| |_/ \__,_||_| |_| |_| \__,_| \__, | \___|( ) __/ | __/ | |/ |___/ |___/ _____ _ _ ___ ___ _____ | ___| | | | | | \/ | / __ \ | |__ _ __ | |__ __ _ _ __ ___ ___ __| | | . . | _ _ | / \/ __ _ _ __ ___ ___ _ __ | __| | '_ \ | '_ \ / _` || '_ \ / __| / _ \ / _` | | |\/| || | | | | | / _` || '__| / _ \ / _ \| '__| | |___ | | | || | | || (_| || | | || (__ | __/| (_| | | | | || |_| | | \__/\| (_| || | | __/| __/| | _ \____/ |_| |_||_| |_| \__,_||_| |_| \___| \___| \__,_| \_| |_/ \__, | \____/ \__,_||_| \___| \___||_| ( ) __/ | |/ |___/ _ ___ ___ _ ___ ___ | | | \/ | | | | \/ | __ _ _ __ __| | | . . | __ _ __| | ___ | . . | ___ / _` || '_ \ / _` | | |\/| | / _` | / _` | / _ \ | |\/| | / _ \ | (_| || | | || (_| | | | | || (_| || (_| || __/ | | | || __/ \__,_||_| |_| \__,_| \_| |_/ \__,_| \__,_| \___| \_| |_/ \___| ___ _____ _ _____ _ _ / _ \ |_ _| | | |_ _| | || | / /_\ \ _ __ | | _ __ ___ | |__ | | __ _ | || | ___ _ __ | _ || '_ \ | | | '_ \ / __|| '_ \ | | / _` || || | / _ \| '__| | | | || | | | _| |_ | | | || (__ | | | | | | | (_| || || || __/| | \_| |_/|_| |_| \___/ |_| |_| \___||_| |_| \_/ \__,_||_||_| \___||_|
Scott Hanselman @shanselman
What? No RETINA version?
I work here.
I work here. Remotely, actually.
We work in open source.
Before Microsoft
After Microsoft
My Story
When your hammer is C++ everything begins to look like a thumb.
Got some certifications…MC*.*
Got some certifications…MC*.*
Got some certifications…MC*.*
“Knock, knock.” “Who’s there?”
“Java.”
Java Programmer
Write Once Debug Anywhere • The Promise of Java has finally arrived!
Write once, Look like crap everywhere
My Language
; Use a simple lookup table created in a complicated way. :)
(defmacro ext(a b) `(setq tab (append tab (loop for x from ,a to ,b
collect x)))) (let (m (tab nil)) (ext 0 64) (ext 78 90) (ext 65 77)
(ext 91 96) (ext 110 122) (ext 97 109) (ext 123 255) (loop (setq m
(read-char)) (write-char (int-char (elt tab (char-int m))))))
Lisp
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))
)))))))))))))))))))))))))
))))))))))))))))))))))
))))))))))))))))))))
))))))))))))))))
)))))))))))))))
)))))))))))
))))
)))
))
))
)
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))
)))))))))))))))))))))))))
))))))))))))))))))))))
))))))))))))))))))))
))))))))))))))))
)))))))))))))))
)))))))))))
))))
)))
))
))
)
“These are your father's parentheses; Elegant weapons, for a more… civilized age.” xkcd.com/297/
; Do fu so it can be turned into a binary or something
main:
.loop:
; function calls are slow ;-)
mov eax, 3 ; magic number for read()
xor ebx, ebx ; file handle
mov ecx, buffer ; buffer to fill
mov edx, 4096 ; how many bytes to read
int 0x80
; if the program doesn't work, replace ebx with a 0
cmp eax, ebx ; ebx is 0 from the filehandle (we hope)
jle .done
; now eax contains the # of bytes read.
.rot_buffer:
mov edx, buffer;
mov ecx, table X86 ASM
HAI! IM IN YR Northwind HOW DUZ I ListProducts YR id PRODUCTS = GETPRODUCTS id OMG FOUND YR PRODUCTS IF U SEZ IM OUTTA YR Northwind
LOLCode
C#
null-coalescing
var res = obj ?? new MyObject();
checked and unchecked class Test { static readonly int x = 1000000; static readonly int y = 1000000; static int F() { return checked(x * y); // Throws OverflowException } static int G() { return unchecked(x * y); // Returns -‐727379968 } static int H() { return x * y; // Depends on default } }
Evolution of async Asynchronous Programming Model (APM) var request = HttpWebRequest.Create("http://www.microsoft.com"); request.BeginGetResponse(result => { try { using (var response = (HttpWebResponse)request.EndGetResponse(result)) { //now it’s STREAM READER TIME SO SUCK IT UP AND GET TO WORK using (var stream = new StreamReader(response.GetResponseStream())) { // ZOMG have to write an async read loop.... } } } catch (Exception ex) { } //THERE IS MORE CODE DOWN HERE OVERFLOWING INTO ANOTHER TALK ANOTHER DAY }, null);
Evolution of async Just Get’er Done and Block Model (synchronous) WebClient client = new WebClient(); client.DownloadFile("http://microsoft.com", "index.html");
Evolution of async Event-‐based Asynchronous Pattern (EAP) var wc = new WebClient(); wc.DownloadStringCompleted += (sender, e) => { // do it here, be aware of what thread you’re on }; wc.DownloadStringAsync("http://microsoft.com");
Evolution of async Async and await
var client = new HttpClient(); string data = await client.GetStringAsync(mscomuri);
Lambdas public IList<Album> FindAlbumsToGiveAway(IList<Album> albums) { var badAlbums = new List<Album>(); foreach (Album album in albums) { if (album.Genre == "Country") badAlbums.Add(album); } return badAlbums; }
Lambdas public IList<Album> FindAlbumsToGiveAway(IList<Album> albums) { return albums.Where(album => album.Genre == "Country").ToList(); }
The Anders Operator public IList<Album> FindAlbumsToGiveAway(IList<Album> albums) { return albums.Where(album => album.Genre == "Country").ToList(); }
=>
Don’t forget the “Resig!” ${}
I’m a phony
pho·ny also pho·ney (fō'nē) adj. pho·ni·er, pho·ni·est 1. a. Not genuine or real; counterfeit: a phony credit card. b. False; spurious: a phony name. 2. Not honest or truthful; deceptive: a phony excuse. 3. a. Insincere or hypocritical. b. Giving a false impression of truth or authenticity; specious.
C# keeps getting better
C#, once high level, can be pretty darn low level Share code across mobile and cloud Native native native NuGet is love! Generics, Linq, async/await You have skills/tools/code
Thanks, Stu!
Thanks, Stu!
I fix stuff
Mobile
1993
2013
Image via Josh Helfferich @digerati http://twitter.com/Digeratii/status/165324320179109888
Before the iPhone After the iPhone
1 billion mobile subscriptions
Source: InternaGonal Telecom Union (hJp://www.itu.int/ITU-‐D/ict/staGsGcs/at_glance/KeyTelecom.html)
that‘s one for every 7 people on earth
For many, a mobile device IS their computer.
Mobile only Web Users
“The avalanche has already started. It is too late for the pebbles to vote.”
“The avalanche has already started. It is too late for the pebbles to vote.” Kosh - Babylon 5
Mono and Xamarin and Community
This is the MVVM Framework you’re looking for
(OK, it’s in the social thing, and the Xbox game is crap, but the framework is lovely.)
MonoGame!!! Bastion!
Cool Libraries
MVVM MVVM Light Toolkit portable fork MvvmCross UpdateControls
IoC Autofac Ninject portable fork PortableIoC XPlatUtils (IoC and Messenger)
Other Json.NET MetroLog Simple.Odata OxyPlot PushSharp ZXing Barcode MonoCross
Portable Library for Azure Mobile Services
Portable Class Libraries
LOOK AT ALL THIS WHITESPACE
PCLs keep getting better!
Raising the “Lowest Common Denominator” Shipping new functionality as cross-platform
Async Targeting Pack HttpClient Microsoft.Composition (MEF) TPL Dataflow Immutable Collections
Code Sharing
Model-View-ViewModel (MVVM) Views How to display information Written in XAML
View Models What information to display Flow of interaction
Models Data objects Business logic Etc.
Platform-specific
Portable-ish (DRY) References
Databinds
Cross Platform App Architecture
Startup
Views
Windows Store App
Platform specific functionality
View Models
Models
Portable Class Library
Platform functionality abstractions
Startup
Views
Windows Phone App
Platform specific functionality
References References
Cross Platform Apps
Cloud
Windows Windows Phone
All in C# Cloud, too!
Xamarin.Android Xamarin.iOS
iPad, iPhone, Android Phone, Android Tablet, WP8, WP7
Disentanglement Demo
You are Powerful
C# - It’s everywhere you want to be
Embedded Windows Mac Linux
Phones Consoles Server Cloud
C# and .NET on the Open Source Micro Framework in as little as 64k!
C# and .NET on the Azure Cloud with
Open Source SDKs
We aren’t nearly as organized as we would need to be
to be half as evil as you think we are.
There’s two operating systems shipping on every phone. Native and JS. Target the one that meets your needs.
HTML is a great portability layer but it lags behind native functionality by definition
We are in control of our future.
We love .NET. Let’s go kick some butt.
Encourage Open Source. Encourage Community.
In fact, C# is the only language
that gets you into every App Store
on the planet.
We support you. We love .NET. Let’s go kick some butt.
Be well, write good code,
and stay in touch
@shanselman