OT: on IDEs and code writing on steroids
ary at esperanto.org.ar
Mon May 18 10:58:30 PDT 2009
> Reply to Ary,
>> BCS wrote:
>>> Reply to Andrei,
>>>> I've repeatedly failed to figure out the coolness of C#, and would
>>>> appreciate a few pointers. Or references. Or delegates :o).
>>> The coolness of c# is that (in order, IMHO) 1) the tools are world
>>> class, 2) the support is back by MS, 3) the docs are great, and 4)
>>> the language is highly consistent and conservative, e.i. nothing is
>>> added until they've got it right.
>>> Aside from #4, the *language* isn't anything to write home about.
>> Have you seen Linq? That's *amazing*!
> LINQ is the only thing c# has the is a notable language feature, but I
> don't think it adds anything that puts it much above the rest of the
> crowd in any way.
>> You can deal with expression ASTs and do really cool stuff with that.
>> Like doing:
>> var results = someObjectsThatAreGoingToBeTakenFromTheDb.Where(o =>
>> o.Name == "Foo");
> I think this will work:
> int delegate(int delegate(ref T)) Where(T array, bool delegate(T) dg)
> struct Ret
> T Array;
> bool delegate(T) Dg;
> int opApply(int delegate(ref T) idg)
> foreach(ref T t; Array)
> if(Dg(t)) if(int ret = idg) return ret;
> return ret;
> return &(Ret(array,dg)).opApply;
> If not, a little tweeking shloudl cover it.
This is for filtering an array. What this does in C# is to translate
that code into this (more or less, this is just the idea!):
SqlConnection conn = ...;
conn.executeQuery("select * from SomeTable Where Name = 'Foo'");
What the "Where" method does it to receieve an expression tree for "o =>
o.Name = 'Foo'", and using a visitor it converts it to an SQL statement.
In D you don't have expression trees. The best you could do it to give
it a string, but then you loose autocompletion, refactoring, nice
compiler error messages and probably many other things.
The best thing about this is that the expression is represented using a
class, say Func<From, To>. So you could say:
Func<From, bool> predicate = (From f) => f.Name == "Foo";
Now you can do:
From array = ...;
In the first case, the predicate will be executed at run-time for each
object in the array, much like your D example does. In the second case,
however, predicate will be translated to SQL.
More information about the Digitalmars-d