SlideShare a Scribd company logo
1 of 55
Andy Bulka Technical Director Austhink Software www.austhink.com
Overview ,[object Object],[object Object],[object Object],[object Object]
Definition ,[object Object],[object Object],[object Object]
Language support ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example – C# class Program  { delegate void Action(); static Action GetAction() { int x = 0; Action a =  delegate  { Console.WriteLine(x); }; x = 1; return a; } static void Main(string[] args) { Action a = GetAction(); a(); }  }
Example – C# class Program { delegate void SomeDelegate(); public static void  InvokeMethod () { SomeDelegate del = delegate() { Console.WriteLine("Hello2"); }; del(); } } class Program { delegate void SomeDelegate(); public static void  InvokeMethod () {  SomeDelegate del =  new SomeDelegate( SomeMethod ); del(); } static void SomeMethod() { Console.WriteLine("Hello"); } } static void Main(string[] args) { InvokeMethod (); }
Example – Python ,[object Object],x = 1 def getf(y): return  lambda  n, m : n + m + x + y f = getf(1) print f(1,2) x += 100 print f(1,2) x = 1 def getf(y): def myf (n, m): return n + m + x + y return  myf f = getf(1) print f(1,2) x += 100 print f(1,2)
Uses – Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What’s a “block of code” ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How are parameters handled? Groovy ,[object Object],[object Object],[object Object],[object Object],[object Object]
How are parameters handled? Python  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How are parameters handled? C# ,[object Object],result = gNames.FindAll( delegate(string name) { return name.StartsWith(startingText); }  ); Where there delegate is declared public delegate  bool Predicate<T>(T obj)
Java – the final var problem e.g. ,[object Object],public void example() { final  double use=Math.random()*10000; SwingUtilities.invokeLater(  new Runnable() { public void run() { System.out.println(use); } }  ); }
Java – the final var problem ,[object Object],[object Object]
Java – final – hack using array ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java inner classes vs closures ,[object Object],[object Object],[object Object],[object Object]
Closures add “state” ,[object Object],[object Object],[object Object],[object Object]
Closure “tricks” ,[object Object],[object Object],[object Object],[object Object],[object Object]
Why not just use objects? ,[object Object],[object Object],[object Object]
Why not just use anonymous inner classes? ,[object Object]
Uses – injecting strategy ,[object Object],a = delegate { Console.WriteLine(x); }; a();
Uses – injecting strategy – Use OO ,[object Object],[object Object]
Uses - iteration - filtering ,[object Object],[object Object],[object Object],offices = [] for e in employees offices << e.office end offices = employees.collect {|e| e.office}
Uses – iteration – filtering – Requires Library support ,[object Object],[object Object],[object Object],managersOffices = employees. select {|e| e.manager?}. map   {|m| m.office} managers, plebs = employees. partition {|e| e.manager?} allManagers = employees. all ? {|e| e.manager?} noManagers = ! employees. any ? {|e| e.manager?} sortedEmployees = employees. sort  {|a,b|  a.lastname <=> b.lastname} sortedEmployees = employees. sort_by  {|e| e.lastname}
Uses - iteration –  filtering – Use List Comprehensions ,[object Object],[object Object],[object Object],offices = [e.office for e in employees]  managersOffices = [e.office for e in employees  if  e.isManager]
Uses - iteration –  filtering – Use Loops or OO ,[object Object],[object Object],[object Object]
Uses - Caching ,[object Object],[object Object]
Uses - Caching ,[object Object],static   SomeDelegate  Cache( SomeDelegate  f) {      bool  alreadyrun =  false ;      int  result = -1;      return   delegate      {          if  (!alreadyrun)          {              result = f();   // run it              alreadyrun =  true ;          }          return  result;      }; }
Uses - Caching ,[object Object],     class   Program      {          delegate   int   SomeDelegate ();          static   void  Main( string [] args)          {              int  rez;              SomeDelegate  del;                           del = Cache(Calculate);              rez = del();               Console .WriteLine(rez);              rez = del();   // this time, will return the cached value.              Console .WriteLine(rez);          }          static   int  Calculate()   // the function we are trying to cache          {              Console .Write( &quot;... &quot; );              return  5;          } ... 5 5 Press any key to continue . . .
Uses – Caching – Use OO ,[object Object],[object Object],[object Object]
Uses - set up, then clean up ,[object Object],[object Object],[object Object],[object Object]
Uses - set up, then clean up ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Uses - set up,  then clean up – Use OO ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Uses – delay evaluation ,[object Object]
Uses – delay evaluation ,[object Object],class View(object): def __init__(self, viewname): self.cmds = []  def SetLocation(self,  node , x, y): f =  lambda  : &quot;&quot; + &quot;view.SetLocation(%s, %d, %d)&quot; % ( node .ToNodeName(), x, y) self.cmds.append(f) def SetOffset(self,  node1, node2 , x, y): f =  lambda  : &quot;&quot; + &quot;view.SetOffset(%s, %s, %d, %d)&quot; % ( node1 .ToNodeName(),  node2 .ToNodeName(), x, y) self.cmds.append(f) # store lambdas/closures since don't want to execute each node.ToNodeName() till each rootnode.RecalcIndexes has been called for c in self.cmds: resultstr +=  c()  + CRLF  // executes the lambda
Uses – delay evaluation ,[object Object],class  Node: def __init__(self, val): self.val = val def  get(node): return lambda n, m : str(n) + &quot; &quot; + str(m+1) + &quot; &quot; + str(node.val) node = Node(10) f = get(node) print f(1,2)  # 1, 3, 10 node.val = 100 print f(1,2)  # 1, 3, 100
Uses – delay evaluation – Use OO ,[object Object],def  get2(node): class  Late: def  __init__(self, node): self.node = node def  Execute(self, n, m): return str(n) + &quot; &quot; + str(m+1) + &quot; &quot; + str(self.node.val) return Late(node) node = Node(10) o = get2(node) print o.Execute(1,2)  # 1, 3, 10 node.val = 100 print o.Execute(1,2)  # 1, 3, 100
Uses – delay evaluation – Use eval ,[object Object],[object Object]
Uses – share private state ,[object Object],[object Object]
Uses – share private state ,[object Object],[object Object],[object Object]
Uses – share private  state – Use OO ,[object Object],[object Object],[object Object],[object Object]
Uses – thread safety ,[object Object]
Uses – thread safety ,[object Object],[object Object]
Uses – thread safety ,[object Object],static List<string> GetNamesStartingWith(string startingText) { return g_Names.FindAll( delegate(string name) { return name.StartsWith(startingText); }); } static string g_StartingText; static bool NameStartsWith(string name) { return name.StartsWith(g_StartingText); } static List<string> GetNamesStartingWith(string startingText) { g_StartingText = startingText; return g_Names.FindAll(NameStartsWith); }
Uses – thread safety – use OO ,[object Object],class Searcher { string g_StartingText;  // local to each instance     public Searcher(string s)  {  g_StartingText = s;  } public bool NameStartsWith(string name) { return name.StartsWith(g_StartingText); } } static List<string> GetNamesStartingWith(string startingText) { Searcher s = new Searcher(startingText);  // use object to hide shared state return g_Names.FindAll(s.NameStartsWith); }
Uses - new control structures  ,[object Object],[object Object],[object Object]
Uses - new control structures  ,[object Object],[object Object],[object Object]
Uses - new control  structures – Use OO  ,[object Object],[object Object]
Uses - function factory ,[object Object],function AdderFactory(y) { return function(x){return x + y;} } var MyFunc; if (whatever) MyFunc = AdderFactory(5); else MyFunc = AdderFactory(10); print(MyFunc(123)); // Either 133 or 128. The anonymous inner function remembers what the value of y was when it was returned, even though y has gone away by the time the inner function is called! We say that the inner function is closed over the containing scope, or for short, that the inner function is a closure.
Uses - function factory – Use OO ,[object Object],def AdderFactory(y): return lambda x : x + y if False: MyFunc = AdderFactory(5); else: MyFunc = AdderFactory(10); print MyFunc(123)  class Adder: def __init__(self, y): self.y = y def Add(self, x): return x + self.y if False: o = Adder(5) else: o = Adder(10) print o.Add(123)
Uses – command Pattern ,[object Object],[object Object],[object Object],[object Object]
Uses - command Pattern ,[object Object],[object Object]
Uses - command Pattern – Use OO ,[object Object],[object Object],[object Object],[object Object],[object Object]
Are Closures really that cool? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary – OO vs closures ,[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++M Hussnain Ali
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented ProgrammingGamindu Udayanga
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programmingnirajmandaliya
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific LanguagesJavier Canovas
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IAjit Nayak
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyMartin Odersky
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundationKevlin Henney
 
File handling & regular expressions in python programming
File handling & regular expressions in python programmingFile handling & regular expressions in python programming
File handling & regular expressions in python programmingSrinivas Narasegouda
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language ComparisonRobert Bachmann
 
Python for katana
Python for katanaPython for katana
Python for katanakedar nath
 
Dart presentation
Dart presentationDart presentation
Dart presentationLucas Leal
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are DatabasesMartin Odersky
 

What's hot (20)

Groovy Programming Language
Groovy Programming LanguageGroovy Programming Language
Groovy Programming Language
 
java vs C#
java vs C#java vs C#
java vs C#
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented Programming
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific Languages
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 
File handling & regular expressions in python programming
File handling & regular expressions in python programmingFile handling & regular expressions in python programming
File handling & regular expressions in python programming
 
C sharp
C sharpC sharp
C sharp
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
Python for katana
Python for katanaPython for katana
Python for katana
 
Dart presentation
Dart presentationDart presentation
Dart presentation
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
 

Viewers also liked

Viewers also liked (12)

Closures
ClosuresClosures
Closures
 
Closures ppt
Closures pptClosures ppt
Closures ppt
 
Packaging of pharmaceutical products
Packaging of pharmaceutical productsPackaging of pharmaceutical products
Packaging of pharmaceutical products
 
Packaging of pharmaceutical products
Packaging of pharmaceutical productsPackaging of pharmaceutical products
Packaging of pharmaceutical products
 
Packaging
PackagingPackaging
Packaging
 
Packaging
PackagingPackaging
Packaging
 
Packaging ppt
Packaging pptPackaging ppt
Packaging ppt
 
Blister packing
Blister packingBlister packing
Blister packing
 
PACKAGING OF TABLETS: TYPES, MATERIALS AND QC.
PACKAGING OF TABLETS: TYPES, MATERIALS AND QC.PACKAGING OF TABLETS: TYPES, MATERIALS AND QC.
PACKAGING OF TABLETS: TYPES, MATERIALS AND QC.
 
Pharmaceutical packaging
Pharmaceutical packagingPharmaceutical packaging
Pharmaceutical packaging
 
Selection and evaluation of pharmaceutical packaging materials, containers an...
Selection and evaluation of pharmaceutical packaging materials, containers an...Selection and evaluation of pharmaceutical packaging materials, containers an...
Selection and evaluation of pharmaceutical packaging materials, containers an...
 
Pharma Packaging
Pharma PackagingPharma Packaging
Pharma Packaging
 

Similar to Andy On Closures

Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming LanguageYLTO
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxIndu65
 
maXbox Starter 31 Closures
maXbox Starter 31 ClosuresmaXbox Starter 31 Closures
maXbox Starter 31 ClosuresMax Kleiner
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 

Similar to Andy On Closures (20)

Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
 
Core java
Core javaCore java
Core java
 
C++ first s lide
C++ first s lideC++ first s lide
C++ first s lide
 
maXbox Starter 31 Closures
maXbox Starter 31 ClosuresmaXbox Starter 31 Closures
maXbox Starter 31 Closures
 
Viva file
Viva fileViva file
Viva file
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 

More from melbournepatterns (20)

An Introduction to
An Introduction to An Introduction to
An Introduction to
 
State Pattern from GoF
State Pattern from GoFState Pattern from GoF
State Pattern from GoF
 
Iterator Pattern
Iterator PatternIterator Pattern
Iterator Pattern
 
Iterator
IteratorIterator
Iterator
 
Concurrency Patterns
Concurrency PatternsConcurrency Patterns
Concurrency Patterns
 
Continuous Integration, Fast Builds and Flot
Continuous Integration, Fast Builds and FlotContinuous Integration, Fast Builds and Flot
Continuous Integration, Fast Builds and Flot
 
Command Pattern
Command PatternCommand Pattern
Command Pattern
 
Code Contracts API In .Net
Code Contracts API In .NetCode Contracts API In .Net
Code Contracts API In .Net
 
LINQ/PLINQ
LINQ/PLINQLINQ/PLINQ
LINQ/PLINQ
 
Gpu Cuda
Gpu CudaGpu Cuda
Gpu Cuda
 
Facade Pattern
Facade PatternFacade Pattern
Facade Pattern
 
Phani Kumar - Decorator Pattern
Phani Kumar - Decorator PatternPhani Kumar - Decorator Pattern
Phani Kumar - Decorator Pattern
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Prototype Design Pattern
Prototype Design PatternPrototype Design Pattern
Prototype Design Pattern
 
Factory Method Design Pattern
Factory Method Design PatternFactory Method Design Pattern
Factory Method Design Pattern
 
Abstract Factory Design Pattern
Abstract Factory Design PatternAbstract Factory Design Pattern
Abstract Factory Design Pattern
 
A Little Lisp
A Little LispA Little Lisp
A Little Lisp
 
State Pattern in Flex
State Pattern in FlexState Pattern in Flex
State Pattern in Flex
 
Active Object
Active ObjectActive Object
Active Object
 

Recently uploaded

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...SOFTTECHHUB
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingScyllaDB
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 

Recently uploaded (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 

Andy On Closures

  • 1. Andy Bulka Technical Director Austhink Software www.austhink.com
  • 2.
  • 3.
  • 4.
  • 5. Example – C# class Program { delegate void Action(); static Action GetAction() { int x = 0; Action a = delegate { Console.WriteLine(x); }; x = 1; return a; } static void Main(string[] args) { Action a = GetAction(); a(); } }
  • 6. Example – C# class Program { delegate void SomeDelegate(); public static void InvokeMethod () { SomeDelegate del = delegate() { Console.WriteLine(&quot;Hello2&quot;); }; del(); } } class Program { delegate void SomeDelegate(); public static void InvokeMethod () { SomeDelegate del = new SomeDelegate( SomeMethod ); del(); } static void SomeMethod() { Console.WriteLine(&quot;Hello&quot;); } } static void Main(string[] args) { InvokeMethod (); }
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.