duck-typing

Python and dictionary like object

I currently toying with Python 3.1 and I need a deep update function for dictionaries (a function that willl recursively update child dictionaries that are inside a parent dictionary). But I think, in the future, my function could have to deal with objects that behave like dictionaries but aren't. And furthermore isinstance and type are...

Duck typing library for Silverlight?

Do you know any duck typing library for Silverlight? There are a few for full-blown .Net framework but I'm looking for something lighter. ...

Is the untyped .net DataSet a duck typed DTO?

Okay, I'm accessing the fields of a data row inside a data set using indexers, but let's consider this as just a syntactical feature. Would you go so far and call it a duck typed thing that is reduced to getters and setters, in other words a data transfer object? ...

Duck typing: how would you treat this situation.

Hi, Relatively new to python. I recently posted a question in regards to validating that a data type is boolean. [http://stackoverflow.com/questions/1708349/use-a-single-decorator-for-multiple-attributes%5D%5B1%5D The answers given referenced duck typing. I have a simple example, and want to make sure I understand. If my code is: cla...

Consequences of implementing to_int and to_str in Ruby

I have a class which exposes a string value and an int value (a command output and exit code respectively). In addition to exposing them through to_s and to_i, I'm also using to_str and to_int, like so: class Status def to_s @output end alias :to_str :to_s def to_i @status.exitstatus end alias :to_int :to_i end My...

Implementing safe duck-typing in C#

After looking at how Go handles interfaces and liking it, I started thinking about how you could achieve similar duck-typing in C# like this: var mallard = new Mallard(); // doesn't implement IDuck but has the right methods IDuck duck = DuckTyper.Adapt<Mallard,IDuck>(mallard); The DuckTyper.Adapt method would use System.Reflection.Emi...

"Duck typing" etymology?

Is there a story behind the name ''duck typing'', I've heard ''if it looks like a duck, and sounds like a duck, let's call it a duck'' (or something like that), but why a duck? Why not ``if it looks like a _ and sounds like a _, let's call it a _''. It sounds like a Flying Circus sketch, but I don't remember it. Is there a story behind ...

Objective-C inheritance method matching

I've come across a strange scenario related to class inheritance in Objective-C. Let's say i have three classes A, B and C that inherit from a base class X. Classes A, B and X have the constructor: - (id)InitWithString:(NSString*)someString andDelegate:(id<SomeProtocol>)aDelegate the only difference being that every class uses a diff...

Duck typing, must it be dynamic? [CW]

Wikipedia currently says about duck-typing: In computer programming with object-oriented programming languages, duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class or implementation of a sp...

Generics and Duck-Typing XML in .NET?

I'm working with some XML representations of data instances. I'm deserializing the objects using .NET serialization but something in my soul is disturbed by having to write classes to represent the XML... Below is what I'd LOVE to do but I don't know if the syntax or if it is even possible: Consider the following: dim xmlObject = Som...

Module "duck typing" pitfalls?

I just started experimenting with a new technique I name (for the moment at least) "module duck typing". Example: Main Module import somepackage.req ## module required by all others import abc import Xyz Module abc __all__=[] def getBus(): """ Locates the `req` for this application """ for mod_name in sys.modules: ...

Should I define interfaces in Duck Typed languages?

I'm just about to write my first application in a duck typed language (Groovy). If I was to write the same application in a static typed language then I would need to define some interfaces. Obviously because of the duck typing in Groovy they are not actually required. At the moment I am thinking that it might make sense to define them ...

Duck-Typing in ColdFusion

What is duck-typing and how is ColdFusion related? ...

Most Up-To-Date C# Duck-Typing Library

The title says it all, basically. What is the current state of the art on duck typing for C# below version 4.0? I know about Duck Typing Project, I know that BLTookit has something to that end, but I'd like to know if I'm missing something really wicked apart from DLR languages and C# 4.0. The inevitable: ...

Does C# have an equivalent to Scala's structural typing?

In Scala, I can define structural types as follows: type Pressable = { def press(): Unit } This means that I can define a function or method which takes as an argument something that is Pressable, like this: def foo(i: Pressable) { // etc. The object which I pass to this function must have defined for it a method called press() that ...

Simulating aspects of static-typing in a duck-typed language

In my current job I'm building a suite of Perl scripts that depend heavily on objects. (using Perl's bless() on a Hash to get as close to OO as possible) Now, for lack of a better way of putting this, most programmers at my company aren't very smart. Worse, they don't like reading documentation and seem to have a problem understanding ...

Should I use concrete Inheritance or not?

I have a project using Propel where I have three objects (potentially more in the future) Occasion Event extends Occasion Gig extends Occasion Occasion is an item that has the shared things, that will always be needed (Venue, start, end etc) With this - I want to be able to add in extra functionality, say for example, adding "Band" ...

Optional structural typing possibilty in C++ or anyother language?

In C++ how to tell compiler that Ogre::Vector3 IS_SAME_AS SomeOtherLIB::Vector3 ? I feel that.. in languages like c++ which are not structural typed but there are cases when it makes sense. Normally as game developer when working with 4+ libraries that provide sort or their own Vector3 implementation. The code is littered with ToOgre, T...

Duck type testing with C# 4 for dynamic objects.

I'm wanting to have a simple duck typing example in C# using dynamic objects. It would seem to me, that a dynamic object should have HasValue/HasProperty/HasMethod methods with a single string parameter for the name of the value, property, or method you are looking for before trying to run against it. I'm trying to avoid try/catch bloc...

Duck Typing DynamicObject derivate

I wrote a class that allows a derivate to which of its properties can be lazy loaded. The code is: public abstract class SelfHydratingEntity<T> : DynamicObject where T : class { private readonly Dictionary<string, LoadableBackingField> fields; public SelfHydratingEntity(T original) { this.Original = original; t...