Slashdot Mirror


Anders Hejlsberg on C# 3.0

spongman writes "Channel9 has a video of Anders Hejlsberg demoing C# 3.0. The new language enhancements include implicitly typed locals, extension methods, strongly-typed lambda expressions, anonymous types, and LINQ - a builtin SQL-like syntax for data access. The spec, samples and a working compiler can be found on MSDN."

3 of 386 comments (clear)

  1. Who is Anders Hejlsberg? by bogaboga · · Score: 5, Informative
    For those just like myself who might not know who Anders Hejlsberg is, I post a link http://en.wikipedia.org/wiki/Anders_Hejlsberg that might help you understand who this man is.

    I did not know he was very instrumental in developing Pascal, a language I was an expert at one in the mid nineties.

  2. Re:Looks more like Delphi every release by bheer · · Score: 5, Informative
    Er, it might help if you actually read the spec. This isn't 'embedded SQL' in the sense of Pro*C -- the 'queries' are really a bit of (helpful) syntactic sugar over an object-oriented, typesafe set of expressions (you'll see the lambda expressions, new to C#, used heavily here):

    from c in customers
    where c.City == "London"
    select c.Name
    turns into

    customers.
    Where(c => c.City == "London").
    Select(c => c.Name)


    Of course, if you don't like it you can always pass strings of SQL text to the data layer, or do everything with StoredProcs -- after all, DLINQ helpfully shields you from ADO.NET but nothing stops you from using ADO.NET either directly or through alternate layers like NHibernate.

    This should also answer your point about optimised SQL generation ... the programmer does not type SQL into C#, SQL gen is still done in the background.

    Also, I can't believe that MS C# is going to include support for MySQL, Postgresql etc, like Hibernate, NHibernate, JDO etc.

    They don't have to. Implementing DLINQ is really as simple as implmenting a pattern (which Helsberg called the 'query expression pattern') and adding your own DB-specific code.

    Currently Oracle and DB/2 ship libs for ADO.NET, you can be quite sure they'll ship libs for DLINQ. If the MySQL and Postgres communites want DLINQ support badly enough, I'm sure someone will write it.
  3. Re:Why implicitly typed locals? by dotcher · · Score: 5, Informative
    C# 3.0 also gains anonymous value types. You can do something like:
    var c = new {Name = "Fred Bloggs", Age = 12};
    Now, what type is c? It's an anonymous struct type, with two members - Name and Age. As it's anonymous, it's obviously not possible to declare it using the standard syntax.

    The language is still strongly, statically typed, though - the following would throw a compile-time error:

    c.Dept = "CS";
    Now, as to why this construct was added to the language in the first place: these anonymous types are useful when using LINQ to query a data source:
    var expr = people.Select(p => new {
    p.Name, BadCoder = p.Age == 11
    });

    foreach (var item in expr)
    Console.WriteLine("{0} is a {1} coder",
    item.Name,
    item.BadCoder ? "bad" : "good");
    expr and item are both given the appropiate type for the data they contain, with no need to explicity define the types. Most of the benefits of strong static typing are retained with this approach, and there's no need to define a type to store data for every weird query you run against the database.

    One benefit that is lost is the ability to share these types across assembly boundaries, which might be an issue in real, three-tier applications. On the other hand, if there's a need to pass data directly from the database to the client application, what's the point of having the middle tier in the first place? So, this might turn out to be a non-issue.

    (My examples were taken or adapted from this white paper, which is an overview of the LINQ project, including the new syntax added to C# 3.0.)