SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
What is -duck typing is a style of dynamic typing in which an object's current set of methods and propertiesdetermines the valid semantics, rather than its inheritance from  - a particular class or implementation of a specific interface.DUCK TYPINGPROGRAMMING STYLEPresented byAbdun Nur Tomal
Define -may be phrased as follows:"When I see a bird that walks like a duckand swims like a duck and quacks like a duck, I call that bird a duck.“In duck typing, one is concerned with just those aspects of an object that are used,
rather than with the type of the object itself. DUCK TYPINGPROGRAMMING STYLE
For example :-in a non-duck-typed language,one can create a function that takes an object of type Duck and calls that object's -walk and -quack methods. In a duck-typed language, >the equivalent function would take an object of any type and >call that object's walk and quack methods. >If the object does not have the methods that are called then the function signals a run-time error. >It is this action of any object having the correct walk and quack methods being accepted by the function that evokesthe quotation and hence the name of this form of typing.DUCK TYPINGPROGRAMMING STYLE
example :-Duck typing is aided by habitually not testing for the type of arguments in method and function bodies,
relying on documentation, clear code, and testing to ensure correct use.
pseudo-code for a duck typed language:function calculate(a, b, c) => return (a+b)*c example1 = calculate (1, 2, 3)example2 = calculate ([1, 2, 3], [4, 5, 6], 2) example3 = calculate ('apples ', 'and oranges, ', 3) printto_string example1 printto_string example2 printto_string example3the result of the code would be:9[1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6] apples and oranges, apples and oranges, apples and orangesDUCK TYPINGPROGRAMMING STYLE
Thus, duck typing allows polymorphismwithout inheritance.

More Related Content

PDF
06. operator overloading
PPT
java swing
PPT
Data members and member functions
PPTX
Packages In Python Tutorial
PPT
Python Pandas
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PPTX
Jsp presentation
PDF
Java threads
06. operator overloading
java swing
Data members and member functions
Packages In Python Tutorial
Python Pandas
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Jsp presentation
Java threads

What's hot (20)

PPTX
this keyword in Java.pptx
PPTX
Single source Shortest path algorithm with example
PPTX
pointer-to-object-.pptx
PPTX
Paging and segmentation
PPTX
Pseudo code of stack Queue and Array
PPTX
Java Inheritance - sub class constructors - Method overriding
DOC
Time and space complexity
DOCX
Clips basics how to make expert system in clips | facts adding | rules makin...
PPT
Java operators
PPT
Chap 5 Tree.ppt
PDF
Java 8 Default Methods
PPS
Java Exception handling
PPTX
exception handling
PPTX
Data types in php
PPTX
Candidate elimination algorithm in ML Lab
PDF
Python Interview Questions And Answers 2019 | Edureka
PPTX
Java script array
PDF
C++ Files and Streams
PPTX
Constructor overloading & method overloading
PPTX
Introduction to data structures (ss)
this keyword in Java.pptx
Single source Shortest path algorithm with example
pointer-to-object-.pptx
Paging and segmentation
Pseudo code of stack Queue and Array
Java Inheritance - sub class constructors - Method overriding
Time and space complexity
Clips basics how to make expert system in clips | facts adding | rules makin...
Java operators
Chap 5 Tree.ppt
Java 8 Default Methods
Java Exception handling
exception handling
Data types in php
Candidate elimination algorithm in ML Lab
Python Interview Questions And Answers 2019 | Edureka
Java script array
C++ Files and Streams
Constructor overloading & method overloading
Introduction to data structures (ss)
Ad

Similar to Programming style - duck type (20)

ODP
Python quickstart for programmers: Python Kung Fu
PPT
Ruby For Java Programmers
PPT
Prototype js
PPT
Perl Presentation
ODP
Introduction to Perl - Day 1
PDF
Static types on javascript?! Type checking approaches to ensure healthy appli...
ODP
Beginning Perl
ODP
Introduction to Perl
PDF
So I am writing a CS code for a project and I keep getting cannot .pdf
PDF
Labs_20210809.pdf
PPT
Lecture 5 - Comm Lab: Web @ ITP
PPT
name name2 n2.ppt
PPT
ppt2
PPT
name name2 n
PPT
ppt30
PPT
ppt18
PPT
Ruby for Perl Programmers
PPT
name name2 n2
PPT
name name2 n
PPT
ppt21
Python quickstart for programmers: Python Kung Fu
Ruby For Java Programmers
Prototype js
Perl Presentation
Introduction to Perl - Day 1
Static types on javascript?! Type checking approaches to ensure healthy appli...
Beginning Perl
Introduction to Perl
So I am writing a CS code for a project and I keep getting cannot .pdf
Labs_20210809.pdf
Lecture 5 - Comm Lab: Web @ ITP
name name2 n2.ppt
ppt2
name name2 n
ppt30
ppt18
Ruby for Perl Programmers
name name2 n2
name name2 n
ppt21
Ad

More from Sentinel Solutions Ltd (6)

PDF
Aws amazon ec2
PPTX
PPTX
PPTX
PPTX
Programming Style - Duck Type
PPTX
Titanium Studio [Updated - 18/12/2011]
Aws amazon ec2
Programming Style - Duck Type
Titanium Studio [Updated - 18/12/2011]

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
A Presentation on Artificial Intelligence
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
KodekX | Application Modernization Development
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Monthly Chronicles - July 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
A Presentation on Artificial Intelligence
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
KodekX | Application Modernization Development
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation_ Review paper, used for researhc scholars
Chapter 3 Spatial Domain Image Processing.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
Advanced methodologies resolving dimensionality complications for autism neur...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Big Data Technologies - Introduction.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Monthly Chronicles - July 2025

Programming style - duck type

  • 1. What is -duck typing is a style of dynamic typing in which an object's current set of methods and propertiesdetermines the valid semantics, rather than its inheritance from - a particular class or implementation of a specific interface.DUCK TYPINGPROGRAMMING STYLEPresented byAbdun Nur Tomal
  • 2. Define -may be phrased as follows:"When I see a bird that walks like a duckand swims like a duck and quacks like a duck, I call that bird a duck.“In duck typing, one is concerned with just those aspects of an object that are used,
  • 3. rather than with the type of the object itself. DUCK TYPINGPROGRAMMING STYLE
  • 4. For example :-in a non-duck-typed language,one can create a function that takes an object of type Duck and calls that object's -walk and -quack methods. In a duck-typed language, >the equivalent function would take an object of any type and >call that object's walk and quack methods. >If the object does not have the methods that are called then the function signals a run-time error. >It is this action of any object having the correct walk and quack methods being accepted by the function that evokesthe quotation and hence the name of this form of typing.DUCK TYPINGPROGRAMMING STYLE
  • 5. example :-Duck typing is aided by habitually not testing for the type of arguments in method and function bodies,
  • 6. relying on documentation, clear code, and testing to ensure correct use.
  • 7. pseudo-code for a duck typed language:function calculate(a, b, c) => return (a+b)*c example1 = calculate (1, 2, 3)example2 = calculate ([1, 2, 3], [4, 5, 6], 2) example3 = calculate ('apples ', 'and oranges, ', 3) printto_string example1 printto_string example2 printto_string example3the result of the code would be:9[1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6] apples and oranges, apples and oranges, apples and orangesDUCK TYPINGPROGRAMMING STYLE
  • 8. Thus, duck typing allows polymorphismwithout inheritance.
  • 9. The only requirement thatfunction calculate needs in its variables is having the "+" and the "*" methods.
  • 10. The duck test can be seen in the following example:As far as the function in_the_forest is concerned, the Person object is a duck:class Duck: def quack(self):print("Quaaaaaack!") def feathers(self): print("The duck has white and gray feathers.") class Person: def quack(self): print("The person imitates a duck.") def feathers(self): print("The person takes a feather from the ground and shows it.") def name(self): print("John Smith") defin_the_forest(duck): duck.quack() duck.feathers() def game(): donald = Duck() john = Person() in_the_forest(donald) in_the_forest(john) game()DUCK TYPINGPROGRAMMING STYLE
  • 11. This way software can be developed by extending partially working duck typed code.In JavaScriptvar Duck = function () {}; Duck.prototype = { quack: function (){ alert("Quaaaaaack!"); }, feathers: function () { alert("The duck has white and gray feathers."); } }; var Person = function () {}; Person.prototype = { quack: function () { alert("The person imitates a duck."); }, feathers: function () { alert("The person takes a feather from the ground and shows it.");}, name: function () { alert("John Smith"); } }; varin_the_forest = function (duck){ duck.quack(); duck.feathers(); }; var game = function () { vardonald = new Duck(); var john = new Person(); in_the_forest(donald) in_the_forest(john) };game();DUCK TYPINGPROGRAMMING STYLE
  • 12. Resources –Wikipediahttp://en.wikipedia.org/wiki/Duck_typing#Concept_examplesDr. Dobb’shttp://drdobbs.com/cpp/184401971http://drdobbs.com/open-sourceBig Dingushttp://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/Apache Commonshttp://commons.apache.org/proxy/DUCK TYPINGPROGRAMMING STYLE
  • 13. Resources –Wikipediahttp://en.wikipedia.org/wiki/Duck_typing#Concept_examplesDr. Dobb’shttp://drdobbs.com/cpp/184401971http://drdobbs.com/open-sourceBig Dingushttp://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/Apache Commonshttp://commons.apache.org/proxy/DUCK TYPINGPROGRAMMING STYLE