SlideShare uma empresa Scribd logo
1 de 45
Enterprise Software Development
@EricPhan | Chief Architect @ SSW
Why you should be
using the shiny new C#
6.0 features now!
Join the Conversation #DevSuperPowers @EricPhan
B.E. - Software Engineering, Certified Scrum Master
Eric Phan
@EricPhan
 Chief Architect @ SSW
 MCTS TFS, MCP
 Loves playing with the latest
technology
History
Summary
8 Cool C# 6.0 Features
Agenda
We’ve come a long way
Join the Conversation #DevSuperPowers @EricPhan
Join the Conversation #DevSuperPowers @EricPhan
History
• 2002 - C# 1.0 released with .NET 1.0 and VS2002
• 2003 - C# 1.2 released with .NET 1.1 and VS2003
• First version to call Dispose on IEnumerators which
implemented IDisposable. A few other small features.
• 2005 - C# 2.0 released with .NET 2.0 and VS2005
• Generics, anonymous methods, nullable types, iterator blocks
Credit to Jon Skeet - http://stackoverflow.com/a/247623
History
• 2007 - C# 3.0 released with .NET 3.5 and VS2008
• Lambda expressions, extension methods, expression trees, anonymous types,
implicit typing (var), query expressions
• 2010 - C# 4.0 released with .NET 4 and VS2010
• Late binding (dynamic), delegate and interface generic variance, more COM
support, named arguments, tuple data type and optional parameters
• 2012 - C# 5.0 released with .NET 4.5 and VS2012
• Async programming, caller info attributes. Breaking change: loop variable closure.
History
Summary
8 Cool C# 6.0 Features
Agenda
1. Auto Property Initializers
Join the Conversation #DevSuperPowers @EricPhan
Currently
public class Developer
{
public Developer()
{
DrinksCoffee = true;
}
public bool DrinksCoffee { get; set; }
}
C# 6.0
public class Developer
{
public bool DrinksCoffee { get; set; } = true;
}
Auto Property Initializers
Join the Conversation #DevSuperPowers @EricPhan
Auto Property Initializers
• Puts the defaults along with the declaration
• Cleans up the constructor
Join the Conversation #DevSuperPowers @EricPhan
2. Dictionary Initializers
When I was a kid…
var devSkills =
new Dictionary<string, bool>();
devSkills["C#"] = true;
devSkills["VB.NET"] = true;
devSkills["AngularJS"] = true;
devSkills["Angular2"] = false;
Dictionary Initializers
VS2013 C# 5.0
var devSkills = new
Dictionary<string, bool>()
{
{ "C#", true },
{ "VB.NET", true },
{ "AngularJS", true },
{ "Angular2", false},
};
VS2015 C# 6.0
var devSkills =
new Dictionary<string, bool>()
{
["C#"] = true,
["VB.NET"] = true,
["AngularJS"] = true,
["Angular2"] = false
};
Join the Conversation #DevSuperPowers @EricPhan
Dictionary Initializers
• Cleaner, less ‘{‘ and ‘}’ to try and match
• More like how you would actually use a Dictionary
• devSkills["C#"] = true;
Join the Conversation #DevSuperPowers @EricPhan
3. String Interpolation
Bad:
var firstName = "Eric";
var lastName = "Phan";
var jobTitle = "Chief Architect";
var company = "SSW";
var display = firstName + " " + lastName + ", " + jobTitle + " @ " + company;
String Interpolation
Better:
var firstName = "Eric";
var lastName = "Phan";
var jobTitle = "Chief Architect";
var company = "SSW";
var display = string.Format("{0} {1}, {3} @ {2}", firstName, lastName, company, jobTitle);
Join the Conversation #DevSuperPowers @EricPhan
String Interpolation
• Much clearer as you can see what variables are being
used inline
• Can do formatting inline too
• {startDate:dd/MMM/yy}
• {totalAmount:c2}
Join the Conversation #DevSuperPowers @EricPhan
4. Null Conditional Operator
public string[] GenerateCoffeeOrder(Coffee[] favCoffee)
{
var order = favCoffee.Select(x => $"{x.Name} - {x.Size}").ToArray();
return order;
}
Null Conditional Operator
What’s wrong with the above code?
public string[] GenerateCoffeeOrder(Coffee[] favCoffee)
{
if (favCoffee == null)
{
return null;
}
var order = favCoffee.Select(x => $"{x.Name} - {x.Size}").ToArray();
return order;
}
C# 6.0
public string[] GenerateCoffeeOrder(Coffee[] favCoffee)
{
var order = favCoffee?.Select(x => $"{x.Name} - {x.Size}").ToArray();
return order;
}
Null Conditional Operator
Fix by adding a null check
Join the Conversation #DevSuperPowers @EricPhan
Null Conditional Operator
• <Variable>?.<SomePropertyOrMethod>
• “?” If the variable is null, then return null
• Otherwise execute whatever is after the “.”
• Similar to the ternary operation (conditional operator)
• var tax = hasGST
? subtotal * 1.1
: subtotal;
• Saves you many lines of null checking with just one simple character.
Join the Conversation #DevSuperPowers @EricPhan
Null Conditional Operator
Join the Conversation #DevSuperPowers @EricPhan
public event EventHandler DevSuperPowerActivated;
private void OnDevSuperPowerActivated(EventArgs specialPowers)
{
if (DevSuperPowerActivated != null) {
DevSuperPowerActivated(this, specialPowers);
}
}
C# 6.0
public event EventHandler DevSuperPowerActivated;
private void OnDevSuperPowerActivated(EventArgs specialPowers)
{
DevSuperPowerActivated?.Invoke(this, specialPowers);
}
5. nameOf Expression
nameOf Expression
• In the previous example, it would probably be better
to throw an exception if the parameter was null
Join the Conversation #DevSuperPowers @EricPhan
public string[] GenerateCoffeeOrder(Coffee[] favCoffee)
{
if (favCoffee == null)
{
throw new ArgumentNullException("favCoffee");
}
var order = favCoffee.Select(x => $"{x.Name} - {x.Size}").ToArray();
return order;
}
nameOf Expression
• What’s the problem?
• Refactor name change
• Change favCoffee to coffeeOrders
Join the Conversation #DevSuperPowers @EricPhan
public string[] GenerateCoffeeOrder(Coffee[] coffeeOrders)
{
if (coffeeOrders == null)
{
throw new ArgumentNullException("favCoffee");
}
var order = coffeeOrders => $"{x.Name} - {x.Size}").ToArray();
return order;
}
Not Renamed!
nameOf Expression
Join the Conversation #DevSuperPowers @EricPhan
C# 6.0
public string[] GenerateCoffeeOrder(Coffee[] coffeeOrders)
{
if (coffeeOrders == null)
{
throw new ArgumentNullException(nameOf(coffeeOrders));
}
var order = favCoffee.Select(x => $"{x.Name} - {x.Size}").ToArray();
return order;
}
nameOf Expression
• Gives you compile time checking whenever you need
to refer to the name of a parameter
Join the Conversation #DevSuperPowers @EricPhan
6. Expression Bodied Functions & Properties
Join the Conversation #DevSuperPowers @EricPhan
Expression Bodied Functions & Properties
Currently
public class Coffee {
public string Name { get; set; }
public string Size { get; set; }
public string OrderDescription {
get {
return string.Format("{0} - {1}", Name, Size);
}
}
}
C# 6.0
public class Coffee {
public string Name { get; set; }
public string Size { get; set; }
public string OrderDescription => $"{Name} - {Size}";
}
C# 6.0
public class Coffee {
public string Name { get; set; }
public string Size { get; set; }
public string OrderDescription => $"{Name} - {Size}";
}
Join the Conversation #DevSuperPowers @EricPhan
Expression Bodied Functions & Properties
public class Coffee {
name: string;
size: string;
orderDescription: () => string;
constructor() {
this.orderDescription = () => `${this.name} - ${this.size}`;
}
}
TypeScript
What language is this?
Join the Conversation #DevSuperPowers @EricPhan
7. Exception Filters
Currently
catch (SqlException ex)
{
switch (ex.ErrorCode)
{
case -2:
return "Timeout Error";
case 1205:
return "Deadlock occurred";
default:
return "Unknown";
}
}
C# 6.0
catch (SqlException ex) when (ex.ErrorCode == -2)
{
return "Timeout Error";
}
catch (SqlException ex) when (ex.ErrorCode == 1205)
{
return "Deadlock occurred";
}
catch (SqlException)
{
return "Unknown";
}
Exception Filters
Join the Conversation #DevSuperPowers @EricPhan
Exception Filters
• Gets rid of all the if statements
• Nice contained blocks to handle specific exception cases
Join the Conversation #DevSuperPowers @EricPhan
Hot Tip: Special peaceful weekends exception filter*
catch (SqlException ex) when (HttpContext.Current.Identity.Name == "Boss Man"
|| DateTime.Now.DayOfWeek == DayOfWeek.Saturday
|| DateTime.Now.DayOfWeek == DayOfWeek.Sunday) {
// Do nothing
} * Disclaimer: Don’t do this
8. Static Using
Join the Conversation #DevSuperPowers @EricPhan
C# 6.0
using static System.Math;
public double GetArea(double radius)
{
return PI * Pow(radius, 2);
}
Currently
public double GetArea(double radius)
{
return Math.PI * Math.Pow(radius, 2);
}
Static Using
Join the Conversation #DevSuperPowers @EricPhan
Static Using
• Gets rid of the duplicate static class namespace
• Cleaner code
• Like using the With in VB.NET
Join the Conversation #DevSuperPowers @EricPhan
There’s more too…
Await in Catch and Finally Blocks
Extension Add in Collection Initializers
Join the Conversation #DevSuperPowers @EricPhan
History
Summary
8 Cool C# 6.0 Features
Agenda
Summary
• Start using these features now!
• VS 2013 + “Install-Package Microsoft.Net.Compilers”
• VS 2015 – Out of the box
• For Build server – Microsoft Build Tools 2015 or
reference the NuGet Package
With all these goodies…
• You should be 350% more productive at coding
• Get reminded about using these cool features with
ReSharper
2 things...
@EricPhan #DevSuperPowers
Tweet your favourite C# 6.0 Feature
Join the Conversation #DevOps #NDCOslo @AdamCogan
Find me on Slideshare!
http://www.slideshare.net/EricPhan6
Thank you!
info@ssw.com.au
www.ssw.com.au
Sydney | Melbourne | Brisbane | Adelaide

Mais conteúdo relacionado

Mais procurados

JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Pythongturnquist
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Rspec API Documentation
Rspec API DocumentationRspec API Documentation
Rspec API DocumentationSmartLogic
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSKnoldus Inc.
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma Christopher Bartling
 
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalQA or the Highway
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015CiaranMcNulty
 
Introduction to rest.li
Introduction to rest.liIntroduction to rest.li
Introduction to rest.liJoe Betz
 
To inject or not to inject - Dependency injection in a Kotlin world (Droidcon...
To inject or not to inject - Dependency injection in a Kotlin world (Droidcon...To inject or not to inject - Dependency injection in a Kotlin world (Droidcon...
To inject or not to inject - Dependency injection in a Kotlin world (Droidcon...Danny Preussler
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsKonrad Malawski
 
Python in the land of serverless
Python in the land of serverlessPython in the land of serverless
Python in the land of serverlessDavid Przybilla
 
Proxy Deep Dive Voxxed Belgrad 2015
Proxy Deep Dive Voxxed Belgrad 2015Proxy Deep Dive Voxxed Belgrad 2015
Proxy Deep Dive Voxxed Belgrad 2015Sven Ruppert
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
 
Clojure: Simple By Design
Clojure: Simple By DesignClojure: Simple By Design
Clojure: Simple By DesignAll Things Open
 
Admins: Smoke Test Your Hadoop Cluster!
Admins: Smoke Test Your Hadoop Cluster!Admins: Smoke Test Your Hadoop Cluster!
Admins: Smoke Test Your Hadoop Cluster!Michael Arnold
 
Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010guest3a77e5d
 
Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010Dave Furfero
 
Working Effectively With Legacy Perl Code
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Codeerikmsp
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)James Titcumb
 

Mais procurados (20)

JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Rspec API Documentation
Rspec API DocumentationRspec API Documentation
Rspec API Documentation
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
 
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert Fornal
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
 
Introduction to rest.li
Introduction to rest.liIntroduction to rest.li
Introduction to rest.li
 
To inject or not to inject - Dependency injection in a Kotlin world (Droidcon...
To inject or not to inject - Dependency injection in a Kotlin world (Droidcon...To inject or not to inject - Dependency injection in a Kotlin world (Droidcon...
To inject or not to inject - Dependency injection in a Kotlin world (Droidcon...
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applications
 
Python in the land of serverless
Python in the land of serverlessPython in the land of serverless
Python in the land of serverless
 
Proxy Deep Dive Voxxed Belgrad 2015
Proxy Deep Dive Voxxed Belgrad 2015Proxy Deep Dive Voxxed Belgrad 2015
Proxy Deep Dive Voxxed Belgrad 2015
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
 
Clojure: Simple By Design
Clojure: Simple By DesignClojure: Simple By Design
Clojure: Simple By Design
 
Admins: Smoke Test Your Hadoop Cluster!
Admins: Smoke Test Your Hadoop Cluster!Admins: Smoke Test Your Hadoop Cluster!
Admins: Smoke Test Your Hadoop Cluster!
 
Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010
 
Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010Making Ajax Sexy, JSConf 2010
Making Ajax Sexy, JSConf 2010
 
Working Effectively With Legacy Perl Code
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Code
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)
 

Semelhante a Why you should be using the shiny new C# 6.0 features now!

C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)Christian Nagel
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainKen Collins
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0William Munn
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project AnalyzedPVS-Studio
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 developmentFisnik Doko
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CDavid Wheeler
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkDaniel Spector
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfkatarichallenge
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptxStefan Oprea
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineJavier de Pedro López
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaCharles Nutter
 
Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»e-Legion
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Scott Keck-Warren
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingOrtus Solutions, Corp
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptHendrik Ebbers
 
Angular from a Different Angle
Angular from a Different AngleAngular from a Different Angle
Angular from a Different AngleJeremy Likness
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra Sencha
 

Semelhante a Why you should be using the shiny new C# 6.0 features now! (20)

C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own Domain
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project Analyzed
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 development
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdf
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptx
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offline
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
 
Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration Testing
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScript
 
Angular from a Different Angle
Angular from a Different AngleAngular from a Different Angle
Angular from a Different Angle
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
 

Último

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 

Último (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 

Why you should be using the shiny new C# 6.0 features now!

  • 2. @EricPhan | Chief Architect @ SSW Why you should be using the shiny new C# 6.0 features now! Join the Conversation #DevSuperPowers @EricPhan
  • 3. B.E. - Software Engineering, Certified Scrum Master Eric Phan @EricPhan  Chief Architect @ SSW  MCTS TFS, MCP  Loves playing with the latest technology
  • 4. History Summary 8 Cool C# 6.0 Features Agenda
  • 5. We’ve come a long way Join the Conversation #DevSuperPowers @EricPhan
  • 6. Join the Conversation #DevSuperPowers @EricPhan
  • 7. History • 2002 - C# 1.0 released with .NET 1.0 and VS2002 • 2003 - C# 1.2 released with .NET 1.1 and VS2003 • First version to call Dispose on IEnumerators which implemented IDisposable. A few other small features. • 2005 - C# 2.0 released with .NET 2.0 and VS2005 • Generics, anonymous methods, nullable types, iterator blocks Credit to Jon Skeet - http://stackoverflow.com/a/247623
  • 8. History • 2007 - C# 3.0 released with .NET 3.5 and VS2008 • Lambda expressions, extension methods, expression trees, anonymous types, implicit typing (var), query expressions • 2010 - C# 4.0 released with .NET 4 and VS2010 • Late binding (dynamic), delegate and interface generic variance, more COM support, named arguments, tuple data type and optional parameters • 2012 - C# 5.0 released with .NET 4.5 and VS2012 • Async programming, caller info attributes. Breaking change: loop variable closure.
  • 9. History Summary 8 Cool C# 6.0 Features Agenda
  • 10. 1. Auto Property Initializers Join the Conversation #DevSuperPowers @EricPhan
  • 11. Currently public class Developer { public Developer() { DrinksCoffee = true; } public bool DrinksCoffee { get; set; } } C# 6.0 public class Developer { public bool DrinksCoffee { get; set; } = true; } Auto Property Initializers Join the Conversation #DevSuperPowers @EricPhan
  • 12. Auto Property Initializers • Puts the defaults along with the declaration • Cleans up the constructor Join the Conversation #DevSuperPowers @EricPhan
  • 14. When I was a kid… var devSkills = new Dictionary<string, bool>(); devSkills["C#"] = true; devSkills["VB.NET"] = true; devSkills["AngularJS"] = true; devSkills["Angular2"] = false; Dictionary Initializers VS2013 C# 5.0 var devSkills = new Dictionary<string, bool>() { { "C#", true }, { "VB.NET", true }, { "AngularJS", true }, { "Angular2", false}, }; VS2015 C# 6.0 var devSkills = new Dictionary<string, bool>() { ["C#"] = true, ["VB.NET"] = true, ["AngularJS"] = true, ["Angular2"] = false }; Join the Conversation #DevSuperPowers @EricPhan
  • 15. Dictionary Initializers • Cleaner, less ‘{‘ and ‘}’ to try and match • More like how you would actually use a Dictionary • devSkills["C#"] = true; Join the Conversation #DevSuperPowers @EricPhan
  • 17. Bad: var firstName = "Eric"; var lastName = "Phan"; var jobTitle = "Chief Architect"; var company = "SSW"; var display = firstName + " " + lastName + ", " + jobTitle + " @ " + company; String Interpolation Better: var firstName = "Eric"; var lastName = "Phan"; var jobTitle = "Chief Architect"; var company = "SSW"; var display = string.Format("{0} {1}, {3} @ {2}", firstName, lastName, company, jobTitle); Join the Conversation #DevSuperPowers @EricPhan
  • 18. String Interpolation • Much clearer as you can see what variables are being used inline • Can do formatting inline too • {startDate:dd/MMM/yy} • {totalAmount:c2} Join the Conversation #DevSuperPowers @EricPhan
  • 20. public string[] GenerateCoffeeOrder(Coffee[] favCoffee) { var order = favCoffee.Select(x => $"{x.Name} - {x.Size}").ToArray(); return order; } Null Conditional Operator What’s wrong with the above code?
  • 21. public string[] GenerateCoffeeOrder(Coffee[] favCoffee) { if (favCoffee == null) { return null; } var order = favCoffee.Select(x => $"{x.Name} - {x.Size}").ToArray(); return order; } C# 6.0 public string[] GenerateCoffeeOrder(Coffee[] favCoffee) { var order = favCoffee?.Select(x => $"{x.Name} - {x.Size}").ToArray(); return order; } Null Conditional Operator Fix by adding a null check Join the Conversation #DevSuperPowers @EricPhan
  • 22. Null Conditional Operator • <Variable>?.<SomePropertyOrMethod> • “?” If the variable is null, then return null • Otherwise execute whatever is after the “.” • Similar to the ternary operation (conditional operator) • var tax = hasGST ? subtotal * 1.1 : subtotal; • Saves you many lines of null checking with just one simple character. Join the Conversation #DevSuperPowers @EricPhan
  • 23. Null Conditional Operator Join the Conversation #DevSuperPowers @EricPhan public event EventHandler DevSuperPowerActivated; private void OnDevSuperPowerActivated(EventArgs specialPowers) { if (DevSuperPowerActivated != null) { DevSuperPowerActivated(this, specialPowers); } } C# 6.0 public event EventHandler DevSuperPowerActivated; private void OnDevSuperPowerActivated(EventArgs specialPowers) { DevSuperPowerActivated?.Invoke(this, specialPowers); }
  • 25. nameOf Expression • In the previous example, it would probably be better to throw an exception if the parameter was null Join the Conversation #DevSuperPowers @EricPhan public string[] GenerateCoffeeOrder(Coffee[] favCoffee) { if (favCoffee == null) { throw new ArgumentNullException("favCoffee"); } var order = favCoffee.Select(x => $"{x.Name} - {x.Size}").ToArray(); return order; }
  • 26. nameOf Expression • What’s the problem? • Refactor name change • Change favCoffee to coffeeOrders Join the Conversation #DevSuperPowers @EricPhan public string[] GenerateCoffeeOrder(Coffee[] coffeeOrders) { if (coffeeOrders == null) { throw new ArgumentNullException("favCoffee"); } var order = coffeeOrders => $"{x.Name} - {x.Size}").ToArray(); return order; } Not Renamed!
  • 27. nameOf Expression Join the Conversation #DevSuperPowers @EricPhan C# 6.0 public string[] GenerateCoffeeOrder(Coffee[] coffeeOrders) { if (coffeeOrders == null) { throw new ArgumentNullException(nameOf(coffeeOrders)); } var order = favCoffee.Select(x => $"{x.Name} - {x.Size}").ToArray(); return order; }
  • 28. nameOf Expression • Gives you compile time checking whenever you need to refer to the name of a parameter Join the Conversation #DevSuperPowers @EricPhan
  • 29. 6. Expression Bodied Functions & Properties
  • 30. Join the Conversation #DevSuperPowers @EricPhan Expression Bodied Functions & Properties Currently public class Coffee { public string Name { get; set; } public string Size { get; set; } public string OrderDescription { get { return string.Format("{0} - {1}", Name, Size); } } } C# 6.0 public class Coffee { public string Name { get; set; } public string Size { get; set; } public string OrderDescription => $"{Name} - {Size}"; }
  • 31. C# 6.0 public class Coffee { public string Name { get; set; } public string Size { get; set; } public string OrderDescription => $"{Name} - {Size}"; } Join the Conversation #DevSuperPowers @EricPhan Expression Bodied Functions & Properties public class Coffee { name: string; size: string; orderDescription: () => string; constructor() { this.orderDescription = () => `${this.name} - ${this.size}`; } } TypeScript What language is this?
  • 32. Join the Conversation #DevSuperPowers @EricPhan 7. Exception Filters
  • 33. Currently catch (SqlException ex) { switch (ex.ErrorCode) { case -2: return "Timeout Error"; case 1205: return "Deadlock occurred"; default: return "Unknown"; } } C# 6.0 catch (SqlException ex) when (ex.ErrorCode == -2) { return "Timeout Error"; } catch (SqlException ex) when (ex.ErrorCode == 1205) { return "Deadlock occurred"; } catch (SqlException) { return "Unknown"; } Exception Filters Join the Conversation #DevSuperPowers @EricPhan
  • 34. Exception Filters • Gets rid of all the if statements • Nice contained blocks to handle specific exception cases Join the Conversation #DevSuperPowers @EricPhan Hot Tip: Special peaceful weekends exception filter* catch (SqlException ex) when (HttpContext.Current.Identity.Name == "Boss Man" || DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday) { // Do nothing } * Disclaimer: Don’t do this
  • 35. 8. Static Using Join the Conversation #DevSuperPowers @EricPhan
  • 36. C# 6.0 using static System.Math; public double GetArea(double radius) { return PI * Pow(radius, 2); } Currently public double GetArea(double radius) { return Math.PI * Math.Pow(radius, 2); } Static Using Join the Conversation #DevSuperPowers @EricPhan
  • 37. Static Using • Gets rid of the duplicate static class namespace • Cleaner code • Like using the With in VB.NET Join the Conversation #DevSuperPowers @EricPhan
  • 38. There’s more too… Await in Catch and Finally Blocks Extension Add in Collection Initializers Join the Conversation #DevSuperPowers @EricPhan
  • 39. History Summary 8 Cool C# 6.0 Features Agenda
  • 40. Summary • Start using these features now! • VS 2013 + “Install-Package Microsoft.Net.Compilers” • VS 2015 – Out of the box • For Build server – Microsoft Build Tools 2015 or reference the NuGet Package
  • 41. With all these goodies… • You should be 350% more productive at coding • Get reminded about using these cool features with ReSharper
  • 43. @EricPhan #DevSuperPowers Tweet your favourite C# 6.0 Feature Join the Conversation #DevOps #NDCOslo @AdamCogan
  • 44. Find me on Slideshare! http://www.slideshare.net/EricPhan6
  • 45. Thank you! info@ssw.com.au www.ssw.com.au Sydney | Melbourne | Brisbane | Adelaide