C#'s greatest mistakes

Russel Winder russel at russel.org.uk
Mon Nov 29 01:46:28 PST 2010


On Sun, 2010-11-28 at 16:23 -0500, Roman Ivanov wrote:
[ . . . ]
> LINQ _is_ an object API. The query-like syntax is just a misfeature.

or desirable and useful feature!

> But it's not _just_ an object API, because it translates statement into
> expression trees, which can be analyzed and used to generate different
> code or code in a different language.
> 
> Let's say you have a list of objects and need to get only the ones whose
> name starts with "D". You can express the predicate via lambda
> expression: x => x.Name.Length > 0 && x.Name[0] == 'D'. Simple, right?
> Here is the problem. You can apply this expression to every object in
> the list, but you don't always want to. What if it's a database table
> with 10000 records? You don't want to retrieve all those records,
> especially if there is already an index. LINQ allows to analyze the
> lambda function and generate an appropriate SQL query. At lest that how
> I understand it.

This is exactly how things are done in Groovy using builders.  Because
of the met-object protocol the DSL for interacting with SQL is a tree
builder.  The built query gets issued as needed.

The fact that you have an incomplete query just means that the query is
incomplete not that the idea of having a sane language-based DSL instead
of having to build SQL queries with string manipulation is wrong.
Surely using language features to build a query in the knowledge of the
equivalent of well-formedness and validity is better than using string
manipulation and hoping for the best.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101129/fe4069ef/attachment.pgp>


More information about the Digitalmars-d mailing list