What is duck typing? 🦆 Learn more about it. | Farhad Uneci posted on the topic | LinkedIn (2024)

Farhad Uneci

Software engineering athirst

  • Report this post

What is duck typing? 🦆Duck typing is a style of dynamic typing in which the type or the class of an object is determined by its behavior, specifically by the methods and properties it possesses, rather than by its explicit declaration or inheritance hierarchy. The name "duck typing" comes from the saying "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck."In programming languages that support duck typing, an object's suitability for a particular operation is determined by the presence of certain methods or properties, rather than by its inheritance or explicit type declaration. This allows for greater flexibility and code reuse, as objects from different classes or types can be used interchangeably as long as they support the required methods or properties.Key characteristics of duck typing:1. Dynamic Typing: Duck typing is closely associated with dynamically typed languages, where types are determined at runtime rather than compile time. Since the type of an object is determined by its behavior, objects can change types dynamically based on the methods they implement.2. Polymorphism: Duck typing enables polymorphic behavior without explicit inheritance or interface implementation. Objects can be used in different contexts as long as they support the required behavior, leading to more flexible and reusable code.3. Focus on Behavior: Duck typing focuses on what objects can do (their behavior) rather than what they are (their type or class). This promotes a more functional programming style where objects are used based on their capabilities rather than their specific types.Languages like Python and Ruby are often cited as examples of languages that support duck typing. In these languages, objects are not bound to specific types or interfaces, allowing for more dynamic and expressive code. However, it's important to note that while duck typing offers flexibility and simplicity, it also requires careful design and documentation to ensure that objects are used appropriately based on their behavior.

1

Like Comment

To view or add a comment, sign in

More Relevant Posts

  • Joel Plaut

    SharePoint Office 365 Architect

    • Report this post

    Today I'd like to consider classification of computer languages; especially since my posts have skipped between many types of languages, some of which go outside the bounds of traditional programming languages.Some are procedural, or algorithmic, following a step-by-step instruction flow, often referred to as Von Neumman architecture.Some are pattern matching, data languages; one can see there are a lot of kinds of languages. I take an expansive view on what might be called a language, least of all as it gives many more languages to write about.Let's list some of the categories of languages with the understanding that a given language can exist in multiple categories.High vs Low levelIn the old days, languages were viewed as "generations" with the first generation being Machine Language (1GL), above that is 2GL Assembly, most traditional languages fell into 3GL, with 4GL being more abstract problem oriented database/declarative languages, with 5GL being more abstract constraint based.Compiled vs interpretedSome languages, such as scripting languages (Python, PowerShell, Perl) are interpreted.Others require compilation, which offers the opportunity for better performance through optimization in the compilation, which also allows for more easily running on different target platforms.Scripting languages are a subset of Interpreted languages, often focused on specific applications.Constraint vs ConcatenativeConstraint based languages declare relationships between objects, also known as logic programming; examples include Claire, Prolog, CHIP (Constraint Handling in Prolog), and ECLiPSe.Concatenative languages are function-focused, and are the more common languages that are more accessible and familiar; the first being FORTH.Constraint programming languages are themselves categorized between perturbation vs refinement models.Stack orientedStack oriented languages allowed for the easy passing of parameters, and the easy use of RPN (Reverse Polish Notation) where operators pop operands off the stack and push the results back on top. Examples include PostScript, Forth, RPL, Beatnik, Befunge, Factor, Joy, Piet, Poplog and S-Lang.Strongly Typed vs Late BindingI appreciate the rigor from explicit typing and strongly typed and early binding languages, but there's a lot to love about the less structured dynamic,late binding or untyped languages.Suffice it to say, it's the author's prerogative to blindly stomp across all categories, taking a random walk across interesting and diverse languages, and welcome corrections and thoughts along the way.

    4

    1 Comment

    Like Comment

    To view or add a comment, sign in

  • Chee-Keong C.

    Data Scientist | Data Analyst, Data Science & Artificial Intelligence, 數據分析與人工智能, NLP, Risk Assessment, Forecasting Analytics,

    • Report this post

    Some news on code llama from huggingface:-- Codellama is designed to make it easy for non-technical users to build AI models without needing extensive knowledge of machine learning or programming.-- It's built on top of LLama2 model.-- Code Llama - Python is a language-specialized variation of Code Llama.-- Code Llama - Instruct is an instruction fine-tuned and aligned variation of Code Llama. It understand human language better and has been fine-tuned to generate helpful and safe answers in natural language.-- Languages the model understood including C, C++, Java, Python, Ruby, PHP, Perl, JavaScript, Haskell, Lisp, Scheme, Erlang, Clojure, Scala, Go, Rust, Swift, Kotlin, Dart, R, Julia, OCaml, F#, Elm, Elixir, TypeScript, C#, VB.NET, CoffeeScript, Lua, Groovy, D, Racket, Common Lisp, ClojureScript, Objective-C, C#, Visual Basic, C++.-- Same license and agreement as LLaMa 2.Credit:https://lnkd.in/gqfFRPK6

    Llama 2 learns to code huggingface.co

    1

    3 Comments

    Like Comment

    To view or add a comment, sign in

  • Cezary Jankowski

    Senior Python Data Scientist @ Nethone

    • Report this post

    Structural Pattern Matching in Python (available from version 3.10) is more than just a concise replacement for the if/elif/else ladder (or the switch statement from C).Structural Pattern Matching (also known as "match/case statements") allows destructuring dicts and objects, making it easy to add exception handling.Example from the PEP 636 (https://lnkd.in/e-ezVnTX):for action in actions:match action:case {"text": str(message), "color": str(c)}:ui.set_text_color(c)ui.display(message)case {"sleep": float(duration)}:ui.wait(duration)case {"sound": str(url), "format": "ogg"}:ui.play(url)case {"sound": _, "format": _}:warning("Unsupported audio format")Note: we can easily add the "catch-all" guard using "case _:". We also get rid of illegible, complex conditions (including type checking) and assignments.And when it comes to improving the readability of the code, an example from Guido himself shows a lot:https://lnkd.in/eNRFRabg#python #softwaredevelopment #programming

    PEP 636 – Structural Pattern Matching: Tutorial peps.python.org

    5

    1 Comment

    Like Comment

    To view or add a comment, sign in

  • Mohammad Fahim Ajmal

    Assistant Engineer In Network & Support

    • Report this post

    Sure. The Interpreter pattern is a design pattern in object-oriented programming that interprets instructions expressed in a language. The pattern defines a class for each non-terminal symbol in the grammar of the language, as well as a class for the terminal symbols. The interpreter class has a method for each non-terminal symbol that interprets the corresponding instruction. The terminal symbols are interpreted by their corresponding classes.Here is an example of how the Interpreter pattern can be used:A user wants to write a program to calculate the area of a triangle.The user creates a program that uses the Interpreter pattern.The program defines a class for each non-terminal symbol in the grammar of the language, such as "number", "variable", and "operator".The program defines a class for each terminal symbol in the grammar of the language, such as "3", "4", and "*".The program defines an interpreter class that has a method for each non-terminal symbol that interprets the corresponding instruction.The program defines a method for each terminal symbol that interprets the corresponding instruction.The program uses the interpreter class to interpret the instructions in the program.In this example, the interpreter class is responsible for interpreting the instructions in the program. The interpreter class has a method for each non-terminal symbol that interprets the corresponding instruction. The terminal symbols are interpreted by their corresponding classes.The Interpreter pattern can be used in a variety of situations where you need to interpret instructions expressed in a language. Some common examples include:Parsing: You can use the Interpreter pattern to parse a text file or a stream of data.Evaluating expressions: You can use the Interpreter pattern to evaluate expressions, such as mathematical expressions or logical expressions.Executing commands: You can use the Interpreter pattern to execute commands, such as shell commands or SQL commands.The Interpreter pattern is a powerful tool that can be used to interpret instructions expressed in a language. This can make your code more flexible and easier to maintain.Here are some of the benefits of using the Interpreter pattern:Flexibility: The Interpreter pattern makes it easy to add new instructions or change existing instructions. This is because the instructions are encapsulated in objects, which can be easily created or modified.Reusability: The Interpreter pattern makes it easy to reuse instructions. This is because the instructions are encapsulated in objects, which can be easily passed around and executed.Maintainability: The Interpreter pattern makes it easy to maintain code that uses the Interpreter pattern. This is because the instructions are encapsulated in objects, which makes it easy to understand how they work and to change them if necessary.

    Like Comment

    To view or add a comment, sign in

  • Albin Lamichhane

    Full Stack Developer with a Passion for Data Science

    • Report this post

    Hi everyone,I’m excited to share with you my latest blog post: How to Run Code Llama on Your Computer with Ollama.Code Llama is a state-of-the-art AI tool for coding that can generate code and natural language about code from both code and natural language prompts.It supports many popular programming languages, such as Python, C++, Java, PHP, and more.It can also be used for code completion and debugging.In this tutorial, I will show you how to use Code Llama locally on your own computer with Ollama, a tool for running and customizing large language models.You will learn how to install Ollama, download Code Llama, and run some examples of code generation and code explanation.You will also learn how to create and run a custom model using langchain and gradio, two Python packages that allow you to quickly build a web application for your language model.You will create a code teaching assistant named ai assistant that can answer code related questions using the codellama base model.This tutorial is suitable for anyone who is interested in AI, coding, and language models. You don’t need any prior experience with these topics, as I will explain everything step by step.I hope you find this tutorial useful and fun. Please feel free to leave your feedback, questions, or suggestions in the comments section. I would love to hear from you and learn from your insights.You can read the full blog post here: https://lnkd.in/dCZUp_xQThank you for your time and attention. Happy coding! 😊

    How to Run Code Llama on Your Computer with Ollama medium.com

    6

    Like Comment

    To view or add a comment, sign in

  • Tanvir Hossain

    8 Years of Experience | Frontend Software Engineer with T-shaped knowledge | JavaScript Expert | Core knowledge of JS | React JS | 2D-3D Visuals, ThreeJS, PixiJS | Programming Enthusiast | Seeking full-time opportunity

    • Report this post

    🆃🅷🅸🅽🅺 🆂🅸🅼🅿🅻🅴𝗥𝗲𝗴𝗲𝘅"Regex, short for regular expression, is a powerful tool for pattern matching and text manipulation. It allows you to search, match, and manipulate strings based on specific patterns. Whether you need to validate an email address, extract data from a text file, or replace certain characters, regex can help you accomplish these tasks efficiently.In regex, you can use metacharacters to define patterns. For example, the dot (.) matches any character, the asterisk (*) matches zero or more occurrences of the preceding character, and the plus sign (+) matches one or more occurrences. Additionally, you can use character classes like [a-z] to match any lowercase letter or \d to match any digit.Regex also supports special characters called anchors. The caret (^) matches the start of a line, while the dollar sign ($) matches the end of a line. These anchors are useful for validating entire strings or extracting specific portions of a text.To test your regex patterns, you can use online tools or programming languages that support regex, such as Python, JavaScript, or Java. These languages provide functions and methods to perform regex operations on strings.So, practice your regex skills and explore the vast possibilities it offers for pattern matching and text manipulation. With enough practice, you'll become proficient in crafting powerful regex expressions to solve various text-related problems."Feel free to use this text to practice your regex skills! Let me know if there's anything specific you'd like me to include or focus on in the practice text.

    2

    Like Comment

    To view or add a comment, sign in

  • hamza javed

    IT Expert

    • Report this post

    "Python in 20 Lines: A Compact Powerhouse"1. Imports: Import essential libraries like `requests` and `BeautifulSoup` for web scraping.2. URL: Define the URL of the webpage to scrape.3. Request: Make a GET request to the URL using `requests`.4. HTML Parsing: Use `BeautifulSoup` to parse the HTML content.5. Data Extraction: Extract relevant data such as headlines or links.6. Processing: Process the extracted data as needed.7. Output: Print or display the processed data.8. Error Handling: Implement basic error handling for connection issues or missing elements.9. Modularization: Keep the script concise by avoiding excessive modularization.10. Testing: Perform basic testing with sample inputs to ensure functionality.11. Documentation: Include brief comments for clarity.12. Version Control: Initialize a Git repository for version control.13. Security: Be cautious with external data sources to avoid security risks.14. Performance: Optimize for performance within the constraints of simplicity.15. Compatibility: Ensure compatibility across different Python versions.16. Style: Adhere to PEP 8 style guidelines for readability.17. Community Engagement: Seek feedback from the Python community for improvements.18. Learning: Continuously learn and improve Python skills.19. Packaging: Consider packaging for easier distribution.20. Contribution: Contribute to open-source projects to give back to the community.

    Like Comment

    To view or add a comment, sign in

  • Jacob Mongeri

    CTO at Kemsoft Masters Ltd | Driving Technological Innovation.

    • Report this post

    A Note on Syntax and Code BlocksWhen writing code, using correct syntax is critical. Even a small typo, like a missing parenthesis bracket or an extra comma, can cause a syntax error and the code won't execute at all. If your code results in an error or an exception, pay close attention to syntax and watch out for minor mistakes. A single wrong character could take hours to identify in long code so it is important to be mindful of syntax when writing code. Common syntax errors:·Misspellings·Incorrect indentations·Missing or incorrect key characters:·Bracket types - ( curved ), [ square ], { curly }·Quote types - "straight-double" or 'straight-single', “curly-double” or ‘curly-single’·Block introduction characters, like colons - :·Data type mismatches·Missing, incorrectly used, or misplaced Python reserved words·Using the wrong case (uppercase/lowercase) - Python is a case-sensitive language If your syntax is correct, but the script has unexpected behavior or output, this may be due to a semantic problem. Syntax is like the vocabulary, grammar, spelling, and punctuation of code. Semantics are the meaning and logic of coded statements. It is possible to have syntactically correct code that runs successfully, but doesn't do what we want it to do.Common semantic errors:·Creating functional code, but getting unintentional output·Poor logic structures in the design of the code

    2

    Like Comment

    To view or add a comment, sign in

  • Chris Curtis

    CTO & Enterprise Architect. AI. AGI. Mergers and Acquisitions. Supply-Chain. Retail. Finance. Data Science. Automated Change Delivery

    • Report this post

    Polymorphism in Inherited Third Generation Programming Languages and the IT Competence Gap, the Cliff Notes...Third-gen pooter langs were growing in popularity back in the 80s. Your C++ as I knew it, SmallTalk as my computer tutor John Gooday and Master of AI thinking in '95 knew it. And culinary god.First gen - assembler... near non-nonsense into nonsense on the readability scale as a functional delta.English... assembly language has a semblance of readability, their job is to translate into processor instruction sets; the digital quantum realm known as... dun dum dar... machine code. Beep-beep, [bop beep],.. etcSecond gen GOATs... Pascal, BASIC, cThird gen... bootstrapped from c in the case of c++, i.e. the c++ compiler actually includes a pre-copiler step from c++ to c, and then to assembly, then to machine code.An abstraction dimension addition or two later... from machine code to c++.What do each generation give us?1 was no good to anyone.2 was ok for geniuses3 could be done by nerds (#menerd)c++ et al enforce what we can categorise as the Polymorphism Advantage.The Polymorphism Advantage is when we create an extra end zero (plus) annual gain ROI by competitive advantage, between three and four orders of magnitude or higher.. we ourselves do 20 times (plus) so four to five times in order-of-magnitude.4th gen were database (yawn) query languages5th gen were all at the highest end of market like NoSQL/SQL hybrid Slimeline-yet-Beast leaders InterSystems and IRIS, the most esquisitely refined engineering I have ever seen.6th gen includes the split between Generative AI, and Dead-End (Supply-Chain, Retail) AI7th gen is us as market makers in Bootstrapped Emergent Virtual AGI.The last being tested now with simulated AGI to pass a derivative Turing Curve, nick-named, the Extended-Turing test. The simulated AGI should be indistinguishable in the present, with value space exploitation as a measure, and has answers that are self-evident in hindsight.This last one is an abstract process to refine the quadrant of what we dont know we dont know into the light using process (automation), we go from abstract, or general representation to the vertical market refinement needs in a tree efficiency pattern.This is basic, basic, fundamental c++ object oriented design, rehashed from the 80s and spat out again 40 years later. v 2 when the Original are gone. The First Nerds are all but gone-burger.No one RTFM since.lolCan you see the gap that is emergent at-scale? #leaders #ai #design #automation #job #programming #digital #future #engineering #language #database #culinary #sql #retail #nosql This is where the biggest innovations and gold mines are hiding for the future.

    5

    2 Comments

    Like Comment

    To view or add a comment, sign in

  • 엄복음

    DevOps Engineer

    • Report this post

    https://lnkd.in/g3kSGwEgGPTScript is a new scripting language to automate your interaction with a Large Language Model (LLM), namely OpenAI. The ultimate goal is to create a fully natural language based programming experience. The syntax of GPTScript is largely natural language, making it very easy to learn and use. Natural language prompts can be mixed with traditional scripts such as bash and python or even external HTTP service calls. With GPTScript you can do just about anything likeplan a vacation,edit a file,run some SQL, orbuild a mongodb/flask app.#gpt #ai #programing

    GitHub - gptscript-ai/gptscript: Natural Language Programming github.com

    2

    Like Comment

    To view or add a comment, sign in

What is duck typing? 🦆 Learn more about it. | Farhad Uneci posted on the topic | LinkedIn (25)

What is duck typing? 🦆 Learn more about it. | Farhad Uneci posted on the topic | LinkedIn (26)

789 followers

  • 50 Posts

View Profile

Follow

Explore topics

  • Sales
  • Marketing
  • Business Administration
  • HR Management
  • Content Management
  • Engineering
  • Soft Skills
  • See All
What is duck typing? 🦆 Learn more about it. | Farhad Uneci posted on the topic | LinkedIn (2024)

References

Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 5736

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.