Peter said:
There may be no well-defined order, but the hash table still does have
order. As long as you don't modify the hash table (or any other
collection in .NET), the elements in the collection will always be
returned in the same order.
That said, I'm a bit puzzled by the direction this debate's taken. The
assertion that SQL is _strictly_ set-based doesn't make sense to me
either, since when you query the database, records always have to be
returned in _some_ order. Even if the database doesn't impose a
specific order on the data, it still has some inherent order, just as a
theoretically orderless collection in .NET still has order.
By definition, a set returned by sql has an undefined order, unless you
specify the ordering. So running the same unordered query on a database
can result in different orderings.
the consumption of the set you see returned by the RDBMS seems to have
an order, but that's just the result of sequential traversing a cursor.
The set the cursor points to is a set without order.
Linq is based on the consumption of sets which is always done in some
order, as you say, so the set becomes a sequence. In haskell, the Monad
concept is a concept that describes this closely. It's not a surprise
that the lead designer of linq is also the founder of haskell
That said, it's IMHO wrong to state that sql is sequence based just
because the results are consumed sequentially. The _operations_ in sql
aren't sequence based, although internally the operations might be
performed using sequence consuming functions. In linq they are, and this
is a fundamental difference: it makes it tough to project a linq query
onto sql, as linq can assume that a set IS ordered, but in sql you can't.
Likewise, while it's true that the LINQ syntax is very much centered
around the IEnumerable<T> interface, there's nothing about the interface
that requires the sequences to be well-defined. A collection _could_ in
fact return elements in random order for consecutive iterations. It's
only practicality that causes that not to happen in practice.
So, saying that LINQ and SQL are two entirely different beasts doesn't
make sense to me.
just because you consume a set sequentially? Linq operators and
functions operate sequential on the sources, in sql this isn't defined:
they operate on sets, and how that's done (e.g. using sequences
internally) isn't known nor important. Because linq uses sequences and
not sets like sql, it can do more on the functionality level but less on
the overall algorithmic O level.
LINQ clearly has borrowed quite a lot from SQL and
can behave very similarly to SQL in many ways. This whole "one deals in
sets, the other deals with sequences" things seems like a complete
non-starter.
Perhaps you should read more into set-oriented algebra vs. sequence
operations then. Or for example try to project linq queries onto sql and
you'll then see that for many queries a conversion has to take place
which isn't obvious.
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------