Re: Duck typing and safety.

2010-08-14 Thread Simen kjaeraas
Steven Schveighoffer schvei...@yahoo.com wrote: 1. a function may have the same name and usage, but have a completely different meaning. Human languages are funny that way. This means, your function could accept a type as a parameter and use it in a very wrong way. Most of the time,

Duck typing and safety.

2010-08-13 Thread simendsjo
While reading std.range, I though that a ducktyping design without language/library support can be quite fragile. Consider the following example: import std.stdio; struct S { void shittyNameThatProbablyGetsRefactored() { }; } void process(T)(T s) { static if(

Re: Duck typing and safety.

2010-08-13 Thread Mafi
Am 13.08.2010 19:01, schrieb simendsjo: import std.stdio; struct S { void shittyNameThatProbablyGetsRefactored() { }; } void process(T)(T s) { static if( __traits(hasMember, T, shittyNameThatProbablyGetsRefactored)) { writeln(normal processing); } else {

Re: Duck typing and safety.

2010-08-13 Thread Adam Burton
simendsjo wrote: While reading std.range, I though that a ducktyping design without language/library support can be quite fragile. Consider the following example: import std.stdio; struct S { void shittyNameThatProbablyGetsRefactored() { }; } void process(T)(T s) { static if(

Re: Duck typing and safety.

2010-08-13 Thread Ryan W Sims
this is avoided as the rename would break the interface. Is there any idoms you can use to avoid stuff like this? Relying on documentation doesn't seem like a good solution. If what you want is compile-time type safety, then duck typing is probably not for you. That's sort of the whole point

Re: Duck typing and safety.

2010-08-13 Thread simendsjo
On 13.08.2010 19:17, Steven Schveighoffer wrote: On Fri, 13 Aug 2010 13:01:47 -0400, simendsjo simen.end...@pandavre.com wrote: While reading std.range, I though that a ducktyping design without language/library support can be quite fragile. Consider the following example: import std.stdio;

Re: Duck typing and safety.

2010-08-13 Thread Steven Schveighoffer
, then duck typing is probably not for you. That's sort of the whole point behind duck typing: you defer typing decisions to runtime. If you need compiler breakage for something like that, use interfaces. No, duck typing is compile-time. Essentially, it goes like this: void foo(T)(T duck

Re: Duck typing and safety.

2010-08-13 Thread Steven Schveighoffer
On Fri, 13 Aug 2010 13:32:11 -0400, simendsjo simen.end...@pandavre.com wrote: On 13.08.2010 19:17, Steven Schveighoffer wrote: On Fri, 13 Aug 2010 13:01:47 -0400, simendsjo simen.end...@pandavre.com wrote: While reading std.range, I though that a ducktyping design without language/library

Re: Duck typing and safety.

2010-08-13 Thread Tomek Sowiński
simendsjo napisał: While reading std.range, I though that a ducktyping design without language/library support can be quite fragile. Consider the following example: import std.stdio; struct S { void shittyNameThatProbablyGetsRefactored() { }; } void process(T)(T s) { static if(