SlideShare une entreprise Scribd logo
1  sur  11
New C#4 Features – Part III 
Nico Ludwig (@ersatzteilchen)
2 
TOC 
● New C#4 Features – Part III 
– Why dynamic Programming 
– Dynamic Programming in VB 
– Dynamic Programming in C#4 
● Sources: 
– Jon Skeet, C# in Depth 
– Chaur Wu, Pro DLR in .NET 4 
– Programming Microsoft® LINQ in Microsoft .NET Framework 4 
– MSDN Magazine 05/10, 06/10, 0710, 02/11 
– Software Engineering Radio; Episode 28: Type Systems, <http://www.se-radio.net/2006/09/episode-28-type-systems/> 
– Software Engineering Radio; Episode 49: Dynamic Languages for Static Minds, 
<http://www.se-radio.net/2007/03/episode-49-dynamic-languages-for-static-minds/>
3 
Dynamic Typing as major new Feature in .Net 4/C#4 
● A big topic in .Net 4 is interoperability. 
● Interoperability with other technologies is often a pain. 
– COM interop. 
– Explorative APIs that sit upon a dynamic object model (e.g. DOM). 
– Remoting technologies with loosely coupling, like SOA and cloud computing do rise. 
● Services (read: operations or methods) may be available or not. 
– Domain Specific Languages (DSLs). 
– New scripting languages came into play, (some even base on the CLR). 
● They're especially employing dynamic typing. 
– => As developers we encounter more and more things having a dynamic interface. 
● Besides interoperability, dynamic typing enables other features. 
– Scripting .Net and with .Net. opens your application's object model to be scripted. 
– Mighty data-driven patterns (expando objects and dynamic Expression Trees).
4 
Leering at VB: Dynamic Programming 
<DynamicProgrammingVB> 
Shows dynamic typing, late binding, duck typing and COM 
automation with VB. 
Key aspects of dynamic programming: 
1. Dynamic Typing 
2. Late Binding 
3. Duck Typing 
(4. Dynamic Objects)
5 
Static Typing vs. dynamic Typing – Part I 
● Programming languages can be divided into statically and dynamically typed ones, whereby basically: 
– Statically typed languages make type checks at compile time. 
● Expressions are of a known type at compile time, variables are fixed to one type at compile time. 
– Dynamically typed languages make type identification and checks at run time. 
● Dynamically typed languages claim "convention over configuration/static check". 
– The believe is that discipline is more important than technical guidance. 
– The conventions work, because duck typing allows consistency at run time. 
– Conventions must be checked with unit-tests, a compiler can just check the syntax. 
– (Unit tests are required: they make dynamic code safe, because the compiler can't .) 
● In dynamic typing the objects' types you're dealing with could be unknown. 
– The types are checked at run time and may even change at run time! 
– In static typing the objects' types are known and checked at compile time.
6 
Static Typing vs. dynamic Typing – Part II 
● Incompatible interfaces (e.g. missing methods) are handled differently. 
– Static typing uses methods that must be bound at compile time successfully. 
– Dynamic typing rather uses messages being dispatched at run time. 
● In static typing we have typing before run time, but 
● in dynamic typing an object decides, whether it accepts a message. 
– In dynamic typing messages that are not "understood" can be handled at run time. 
● Methods and fields could be added or removed during run time. 
● Possible perception: Not: "Are you of this type?", rather: "Can you respond to this message?" 
● Static type-checks, rely on explicit conversions; dynamic type-checks are deferred to run time and explicit conversions are required. 
– This is called late binding. 
– Late binding resolves textual symbols at run time (e.g. property names). 
– Early binding means to resolve all textual symbols early at compile time. 
– Static polymorphism is class-based polymorphism with static interfaces and dynamic dispatch. 
– Dynamic polymorphism means that objects don't need a common static interface like classes as we need no dynamic dispatch.
7 
So eventually: Dynamic Programming in .Net 4 and C#4 
● The .Net framework and C# are based on static typing, nothing changed here. 
– I.e. types and their interfaces are resolved/bound at compile time. 
● C#4 allows dynamic typing in a statically typed language. 
– C# stays a statically typed language primarily, but it has new dynamic features now. 
● Dynamic type analysis can be done via reflection, but it's difficult to read. 
– Dynamic typing makes the syntax much more appealing, even natural. 
● The .Net 4 framework introduces the Dynamic Language Runtime (DLR). 
– The DLR is a library that enables dynamic dispatching within a CLR language. 
● The new C#4 keyword dynamic is the syntactical entrance into the DLR. 
– If you apply dynamic you tell the compiler to turn off type-checks.
8 
Syntactical Basics of dynamic Coding in C#4 
<BasicSyntax, Dispatching> 
Shows the syntax basics of dynamics, dynamic expressions in C# and 
dynamic dispatching.
9 
Syntactical "Mechanics" of dynamic in C#4 – Part I 
● The static type of dynamic objects is dynamic. Variables still need a declaration. 
– For the "programming experience" dynamic is just a type (you can have dynamic members and closed generic types using dynamic 
(e.g. List<dynamic>)). 
● Almost each type is implicitly convertible to dynamic. 
● But dynamic expressions are not convertible to anything, except in: 
– overload resolution and assignment conversion 
– and in control flow: if clauses, using clauses and foreach loops. 
● Dynamic Expressions use values of type dynamic. They're evaluated at run time. 
● From a syntax perspective dynamic works like object w/o the need to cast. 
– You can write direct calls to the methods you expect to be present (duck typing).
10 
Syntactical "Mechanics" of dynamic in C#4 – Part II 
● The type dynamic isn't a real CLR type, but C# mimics this for us. 
● The type dynamic is just System.Object with run time binding. 
– For non-local instances of dynamic the compiler applies the custom attribute System.Runtime.CompilerServices.DynamicAttribute. 
● (Fields, properties and method's and delegate's parameters and return types.) 
● Restrictions: 
– The type dynamic can not be used as base class and can not be extended. 
– The type dynamic can not be used as type constraint for generics. 
– You can't get the typeof(dynamic). 
– You can neither access constructors nor static members via dynamic dispatch. 
– You can only call accessible methods via dynamic dispatch. 
– Dynamic dispatch can't find extension methods. 
– Dynamic dispatch can't find methods of explicitly implemented interfaces.
11 
Thank you!

Contenu connexe

Tendances (20)

Programming Methodology
Programming MethodologyProgramming Methodology
Programming Methodology
 
10. sub program
10. sub program10. sub program
10. sub program
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Compiler
CompilerCompiler
Compiler
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
08 subprograms
08 subprograms08 subprograms
08 subprograms
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
SPC Unit 2
SPC Unit 2SPC Unit 2
SPC Unit 2
 
Groovy DSLs - S2GForum London 2011 - Guillaume Laforge
Groovy DSLs - S2GForum London 2011 - Guillaume LaforgeGroovy DSLs - S2GForum London 2011 - Guillaume Laforge
Groovy DSLs - S2GForum London 2011 - Guillaume Laforge
 
Advanced C - Part 1
Advanced C - Part 1 Advanced C - Part 1
Advanced C - Part 1
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Community Tech Days C# 4.0
Community Tech Days C# 4.0Community Tech Days C# 4.0
Community Tech Days C# 4.0
 
Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 
Internal domain-specific languages
Internal domain-specific languagesInternal domain-specific languages
Internal domain-specific languages
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
 

En vedette

New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_viNico Ludwig
 
SVR17: Data-Intensive Computing on Windows HPC Server with the ...
SVR17: Data-Intensive Computing on Windows HPC Server with the ...SVR17: Data-Intensive Computing on Windows HPC Server with the ...
SVR17: Data-Intensive Computing on Windows HPC Server with the ...butest
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_iiNico Ludwig
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05CHOOSE
 
Introduction to F#x
Introduction to F#xIntroduction to F#x
Introduction to F#xRyan Riley
 
Introduction to Reactive Extensions
Introduction to Reactive ExtensionsIntroduction to Reactive Extensions
Introduction to Reactive ExtensionsPeter Goodman
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive ExtensionsKiev ALT.NET
 
Pertemuan 1. introduction to image processing
Pertemuan 1. introduction to image processingPertemuan 1. introduction to image processing
Pertemuan 1. introduction to image processingAditya Kurniawan
 
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNew c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNico Ludwig
 
F:\Universidad Tecnologica Israel
F:\Universidad Tecnologica IsraelF:\Universidad Tecnologica Israel
F:\Universidad Tecnologica Israelsantiago
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharpsarfarazali
 
Getting the MVVM Kicked Out of Your F#'n Monads
Getting the MVVM Kicked Out of Your F#'n MonadsGetting the MVVM Kicked Out of Your F#'n Monads
Getting the MVVM Kicked Out of Your F#'n MonadsRichard Minerich
 
Texas STaR
Texas STaRTexas STaR
Texas STaRllyarbro
 
F# with Excel at F# in Finance, London Nov 2013
F# with Excel at F# in Finance, London Nov 2013F# with Excel at F# in Finance, London Nov 2013
F# with Excel at F# in Finance, London Nov 2013Adam Mlocek
 

En vedette (20)

New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
 
SVR17: Data-Intensive Computing on Windows HPC Server with the ...
SVR17: Data-Intensive Computing on Windows HPC Server with the ...SVR17: Data-Intensive Computing on Windows HPC Server with the ...
SVR17: Data-Intensive Computing on Windows HPC Server with the ...
 
Test first
Test firstTest first
Test first
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_ii
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
 
Introduction to F#x
Introduction to F#xIntroduction to F#x
Introduction to F#x
 
Introduction to Reactive Extensions
Introduction to Reactive ExtensionsIntroduction to Reactive Extensions
Introduction to Reactive Extensions
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive Extensions
 
Introduction to C# 3.0
Introduction to C# 3.0Introduction to C# 3.0
Introduction to C# 3.0
 
Pertemuan 1. introduction to image processing
Pertemuan 1. introduction to image processingPertemuan 1. introduction to image processing
Pertemuan 1. introduction to image processing
 
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNew c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_v
 
F:\Universidad Tecnologica Israel
F:\Universidad Tecnologica IsraelF:\Universidad Tecnologica Israel
F:\Universidad Tecnologica Israel
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Texas
TexasTexas
Texas
 
Getting the MVVM Kicked Out of Your F#'n Monads
Getting the MVVM Kicked Out of Your F#'n MonadsGetting the MVVM Kicked Out of Your F#'n Monads
Getting the MVVM Kicked Out of Your F#'n Monads
 
Texas STaR
Texas STaRTexas STaR
Texas STaR
 
The Power of F#
The Power of F#The Power of F#
The Power of F#
 
F# with Excel at F# in Finance, London Nov 2013
F# with Excel at F# in Finance, London Nov 2013F# with Excel at F# in Finance, London Nov 2013
F# with Excel at F# in Finance, London Nov 2013
 
C# 4.0 - Whats New
C# 4.0 - Whats NewC# 4.0 - Whats New
C# 4.0 - Whats New
 
Beginning linq
Beginning linqBeginning linq
Beginning linq
 

Similaire à New c sharp4_features_part_iii

New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNico Ludwig
 
Apache Big Data Europe 2016
Apache Big Data Europe 2016Apache Big Data Europe 2016
Apache Big Data Europe 2016Tim Ellison
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNico Ludwig
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introductionmengistu23
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxZiyadMohammed17
 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_iNico Ludwig
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler DesignMarimuthu M
 
Half-automatic Compilable Source Code Recovery
Half-automatic Compilable Source Code RecoveryHalf-automatic Compilable Source Code Recovery
Half-automatic Compilable Source Code RecoveryJoxean Koret
 
03 the c language
03 the c language03 the c language
03 the c languagearafatmirza
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterTim Ellison
 

Similaire à New c sharp4_features_part_iii (20)

C# Fundamental
C# FundamentalC# Fundamental
C# Fundamental
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
C-Sharp 6.0 ver2
C-Sharp 6.0 ver2C-Sharp 6.0 ver2
C-Sharp 6.0 ver2
 
Memory models in c#
Memory models in c#Memory models in c#
Memory models in c#
 
Apache Big Data Europe 2016
Apache Big Data Europe 2016Apache Big Data Europe 2016
Apache Big Data Europe 2016
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_i
 
News In The Net40
News In The Net40News In The Net40
News In The Net40
 
Phases of Compiler.pdf
Phases of Compiler.pdfPhases of Compiler.pdf
Phases of Compiler.pdf
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
Half-automatic Compilable Source Code Recovery
Half-automatic Compilable Source Code RecoveryHalf-automatic Compilable Source Code Recovery
Half-automatic Compilable Source Code Recovery
 
03 the c language
03 the c language03 the c language
03 the c language
 
Subprogram
SubprogramSubprogram
Subprogram
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark faster
 

Plus de Nico Ludwig

Grundkurs fuer excel_part_v
Grundkurs fuer excel_part_vGrundkurs fuer excel_part_v
Grundkurs fuer excel_part_vNico Ludwig
 
Grundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivGrundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivNico Ludwig
 
Grundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiGrundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiNico Ludwig
 
Grundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiGrundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiNico Ludwig
 
Grundkurs fuer excel_part_i
Grundkurs fuer excel_part_iGrundkurs fuer excel_part_i
Grundkurs fuer excel_part_iNico Ludwig
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivityNico Ludwig
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivityNico Ludwig
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNico Ludwig
 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNico Ludwig
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNico Ludwig
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNico Ludwig
 
Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiNico Ludwig
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiNico Ludwig
 
Review of c_sharp2_features_part_i
Review of c_sharp2_features_part_iReview of c_sharp2_features_part_i
Review of c_sharp2_features_part_iNico Ludwig
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_iiNico Ludwig
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_iiNico Ludwig
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_iNico Ludwig
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_iNico Ludwig
 

Plus de Nico Ludwig (20)

Grundkurs fuer excel_part_v
Grundkurs fuer excel_part_vGrundkurs fuer excel_part_v
Grundkurs fuer excel_part_v
 
Grundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivGrundkurs fuer excel_part_iv
Grundkurs fuer excel_part_iv
 
Grundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiGrundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iii
 
Grundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiGrundkurs fuer excel_part_ii
Grundkurs fuer excel_part_ii
 
Grundkurs fuer excel_part_i
Grundkurs fuer excel_part_iGrundkurs fuer excel_part_i
Grundkurs fuer excel_part_i
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iii
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
 
Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iii
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_ii
 
Review of c_sharp2_features_part_i
Review of c_sharp2_features_part_iReview of c_sharp2_features_part_i
Review of c_sharp2_features_part_i
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i
 

Dernier

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Dernier (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

New c sharp4_features_part_iii

  • 1. New C#4 Features – Part III Nico Ludwig (@ersatzteilchen)
  • 2. 2 TOC ● New C#4 Features – Part III – Why dynamic Programming – Dynamic Programming in VB – Dynamic Programming in C#4 ● Sources: – Jon Skeet, C# in Depth – Chaur Wu, Pro DLR in .NET 4 – Programming Microsoft® LINQ in Microsoft .NET Framework 4 – MSDN Magazine 05/10, 06/10, 0710, 02/11 – Software Engineering Radio; Episode 28: Type Systems, <http://www.se-radio.net/2006/09/episode-28-type-systems/> – Software Engineering Radio; Episode 49: Dynamic Languages for Static Minds, <http://www.se-radio.net/2007/03/episode-49-dynamic-languages-for-static-minds/>
  • 3. 3 Dynamic Typing as major new Feature in .Net 4/C#4 ● A big topic in .Net 4 is interoperability. ● Interoperability with other technologies is often a pain. – COM interop. – Explorative APIs that sit upon a dynamic object model (e.g. DOM). – Remoting technologies with loosely coupling, like SOA and cloud computing do rise. ● Services (read: operations or methods) may be available or not. – Domain Specific Languages (DSLs). – New scripting languages came into play, (some even base on the CLR). ● They're especially employing dynamic typing. – => As developers we encounter more and more things having a dynamic interface. ● Besides interoperability, dynamic typing enables other features. – Scripting .Net and with .Net. opens your application's object model to be scripted. – Mighty data-driven patterns (expando objects and dynamic Expression Trees).
  • 4. 4 Leering at VB: Dynamic Programming <DynamicProgrammingVB> Shows dynamic typing, late binding, duck typing and COM automation with VB. Key aspects of dynamic programming: 1. Dynamic Typing 2. Late Binding 3. Duck Typing (4. Dynamic Objects)
  • 5. 5 Static Typing vs. dynamic Typing – Part I ● Programming languages can be divided into statically and dynamically typed ones, whereby basically: – Statically typed languages make type checks at compile time. ● Expressions are of a known type at compile time, variables are fixed to one type at compile time. – Dynamically typed languages make type identification and checks at run time. ● Dynamically typed languages claim "convention over configuration/static check". – The believe is that discipline is more important than technical guidance. – The conventions work, because duck typing allows consistency at run time. – Conventions must be checked with unit-tests, a compiler can just check the syntax. – (Unit tests are required: they make dynamic code safe, because the compiler can't .) ● In dynamic typing the objects' types you're dealing with could be unknown. – The types are checked at run time and may even change at run time! – In static typing the objects' types are known and checked at compile time.
  • 6. 6 Static Typing vs. dynamic Typing – Part II ● Incompatible interfaces (e.g. missing methods) are handled differently. – Static typing uses methods that must be bound at compile time successfully. – Dynamic typing rather uses messages being dispatched at run time. ● In static typing we have typing before run time, but ● in dynamic typing an object decides, whether it accepts a message. – In dynamic typing messages that are not "understood" can be handled at run time. ● Methods and fields could be added or removed during run time. ● Possible perception: Not: "Are you of this type?", rather: "Can you respond to this message?" ● Static type-checks, rely on explicit conversions; dynamic type-checks are deferred to run time and explicit conversions are required. – This is called late binding. – Late binding resolves textual symbols at run time (e.g. property names). – Early binding means to resolve all textual symbols early at compile time. – Static polymorphism is class-based polymorphism with static interfaces and dynamic dispatch. – Dynamic polymorphism means that objects don't need a common static interface like classes as we need no dynamic dispatch.
  • 7. 7 So eventually: Dynamic Programming in .Net 4 and C#4 ● The .Net framework and C# are based on static typing, nothing changed here. – I.e. types and their interfaces are resolved/bound at compile time. ● C#4 allows dynamic typing in a statically typed language. – C# stays a statically typed language primarily, but it has new dynamic features now. ● Dynamic type analysis can be done via reflection, but it's difficult to read. – Dynamic typing makes the syntax much more appealing, even natural. ● The .Net 4 framework introduces the Dynamic Language Runtime (DLR). – The DLR is a library that enables dynamic dispatching within a CLR language. ● The new C#4 keyword dynamic is the syntactical entrance into the DLR. – If you apply dynamic you tell the compiler to turn off type-checks.
  • 8. 8 Syntactical Basics of dynamic Coding in C#4 <BasicSyntax, Dispatching> Shows the syntax basics of dynamics, dynamic expressions in C# and dynamic dispatching.
  • 9. 9 Syntactical "Mechanics" of dynamic in C#4 – Part I ● The static type of dynamic objects is dynamic. Variables still need a declaration. – For the "programming experience" dynamic is just a type (you can have dynamic members and closed generic types using dynamic (e.g. List<dynamic>)). ● Almost each type is implicitly convertible to dynamic. ● But dynamic expressions are not convertible to anything, except in: – overload resolution and assignment conversion – and in control flow: if clauses, using clauses and foreach loops. ● Dynamic Expressions use values of type dynamic. They're evaluated at run time. ● From a syntax perspective dynamic works like object w/o the need to cast. – You can write direct calls to the methods you expect to be present (duck typing).
  • 10. 10 Syntactical "Mechanics" of dynamic in C#4 – Part II ● The type dynamic isn't a real CLR type, but C# mimics this for us. ● The type dynamic is just System.Object with run time binding. – For non-local instances of dynamic the compiler applies the custom attribute System.Runtime.CompilerServices.DynamicAttribute. ● (Fields, properties and method's and delegate's parameters and return types.) ● Restrictions: – The type dynamic can not be used as base class and can not be extended. – The type dynamic can not be used as type constraint for generics. – You can't get the typeof(dynamic). – You can neither access constructors nor static members via dynamic dispatch. – You can only call accessible methods via dynamic dispatch. – Dynamic dispatch can't find extension methods. – Dynamic dispatch can't find methods of explicitly implemented interfaces.

Notes de l'éditeur

  1. &amp;quot;Programming Microsoft® LINQ in Microsoft .NET Framework 4&amp;quot; provides a good overview of programming with Expression Trees.
  2. Interop often meant to use Object and casting all over. It makes sense to base scripting languages on the CLR, because it already offers some features: type loader, resolver, memory manager, garbage collector etc. In Java we found this development some years ago (JSR 292 and JSR 223). - Some new scripting languages have been built on top of the JRE (Groovy, Clojure and Scala) and others have been migrated (JRuby and Jython).
  3. The feature, which we discuss here as dynamic typing, is also known as loosely typing. - The main idea is that a dynamically typed variable is just a named placeholder for a value.
  4. Esp. do dynamically typed languages not require to declare a type at compile time. Example conventions: (esp. naming conventions) Ruby on Rails&amp;apos; scaffolding pattern and also ASP.Net MVC. Dynamic typing and unknown types are typically found in JavaScript (also called loosely typing in JavaScript) programming. The type-changes at run time are not expressed by polymorphism in dynamic typing! - The needed consistency is solely expressed by duck typing!
  5. Missing methods: Mind the problem of unavailable Services in a SOA. In Ruby and Python methods can be removed during run time. If a method wasn&amp;apos;t found in Obj-C, the method invocation can be forwarded and handled at run time. If the case of unknown methods was not handled by the programmer doesNotRecognizeSelector: will be called, which will eventually throw NSInvalidArgumentException (&amp;quot;unrecognized selector sent to instance &amp;lt;address&amp;gt;&amp;quot;). In Smalltalk doesNotUnderstand: will be called, which, if not handled by the programmer, will be handled by the runtime (or the debugger).
  6. In Obj-C you can use the static type id to enable dynamic typing on objects. The COM type IDispatch is indeed also an enabler for dynamic dispatching/late binding, when scripting and COM automation come into play. For a long time VB was the only language, in which you can switch between early bound (static) and lately bound (dynamic) typing (Option Explicit On/Off, Option Strict On/Off). In past versions of VB, e.g. in VB 6 this ability was based on the VB- and COM-type VARIANT. But VARIANT is best explained to be an example of weak typing rather than of dynamic typing.
  7. The keyword dynamic can be understood as &amp;quot;System.Object with run time binding&amp;quot;. At compile time, dynamic variables have only those methods defined in System.Object, at run time possibly more. But dynamic can be used as type argument for a generic type as base class (not a generic interface).
  8. If you need to do more with a dynamic object than, say, assigning values to it, e.g. calling methods, the DLR starts its work to dispatch the resulting dynamic expressions. In C#, the C# language binder will come into play in that situation, and if you apply dynamic dispatch in your code, you will need to add a reference to the assembly Microsoft.CSharp.dll in VS 2010. - The good news is that this assembly will be referenced by default, when you setup a new C# project in VS2010. Ctors and static members can&amp;apos;t be dynamically dispatched! You have to stick to instance methods or you have to use polymorphic static typing and factories.