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.
114
Embed
How C# Save My Marriage, Enhanced My Career, and Made Me an Inch Taller, Scott Hanselman
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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.
“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; }
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.)