Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Microsoft

Anders Hejlsberg on C# 3.0 386

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."
This discussion has been archived. No new comments can be posted.

Anders Hejlsberg on C# 3.0

Comments Filter:
  • by ergo98 ( 9391 ) on Sunday September 18, 2005 @08:10AM (#13588960) Homepage Journal
    But then, Bill Gates himself said that the only thing wrong with Delphi was that it wasn't a Microsoft product.

    What are you talking about? I used Delphi for years, and then switched to .NET, and while Anders of course brought a lot of Delphi-ism to the .NET Framework and C#, these new C# 3.0 additions are nothing like Delphi, and C# 2.0 is already worlds beyond what Delphi ever achieved. LINQ, and DLINQ, are very exciting improvements in removing the disconnect between the database and the middle/front tier, and given the tremendous importance of that it will be remarkable.

    The toughest thing about this sort of technology, though, is that it isn't complete and usable in real projects, so as developers we're uncertain how much time to waste playing with the demos and learning (how many developers must be pissed seeing the hype machine starting over C# 3.0, when they still don't even have the ability to use C# 2.0 in production - e.g. VS.NET 2005 is only at the RC stage). Unless you're a blogger or writer making money writing about how much it makes you wet your pants, there's just no practicality in it.
  • Re:So what? (Score:1, Insightful)

    by QunaLop ( 861366 ) on Sunday September 18, 2005 @08:12AM (#13588966)
    got angst? it is an update to a open specification for a computer language... for which there is hundreds of thousands of programmers and millions of dollars invested... ...clearly this is not newsworthy you might ask yourself why mandrake gets an "ad" when dell offers it as an option on 1 laptop model...
  • by Mr2001 ( 90979 ) on Sunday September 18, 2005 @08:19AM (#13588985) Homepage Journal
    In an implicitly typed local variable declaration, the type of the local variable being declared is inferred from the expression used to initialize the variable. When a local variable declaration specifies var as the type and no type named var is in scope, the declaration is an implicitly typed local variable declaration. For example:

    var i = 5;
    var s = "Hello";

    Can someone explain the point of this? C# is not JavaScript; these aren't true dynamically typed variables, the compiler just assigns a type for you instead of making you do it yourself. I can easily take half a second out of my day to figure out what type a variable should be, and end up with more readable code.
  • by hritcu ( 871613 ) on Sunday September 18, 2005 @08:20AM (#13588987) Homepage
    Do we really have to have a Slashdot post followed by a flamewar every time a guy at Microsoft opens his mouth?
  • by iGN97 ( 83927 ) on Sunday September 18, 2005 @08:27AM (#13589012) Homepage
    You type less, obviously.

    It also allows you to write pieces of code that are more generic. The LINQ samples have a lot of examples of this.

    For example:

    foreach (string s in collection) {
          Console.WriteLine(s);
    }

    means you have to change the type everytime you change the type in the collection.

    foreach (var item in collection) {
          Console.WriteLine(item);
    }

    means that you can use it with any time that implements ToString, which is pretty much any type.

    There are numerous other benefits from the type inference, and they become more apparent with lambda expressions, where you can write expressions like "x => x % 2 == 0" instead of writing the equivalent bool-returning delegate with a typed parameter.

    Most of the new features of C# 3.0 are quite impressive and more importantly very useful.
  • Way to go! (Score:5, Insightful)

    by RAMMS+EIN ( 578166 ) on Sunday September 18, 2005 @08:48AM (#13589057) Homepage Journal
    It seems that Microsoft is finally doing something with all the great research they funded. C# is becoming more and more like Lisp and ML, and might well become the first language in recent times that carries the approval of both academics and the industry. .NET as a whole gets many things right; multiple languages that can target the CLR and interoperate, special modifications made to create a friendlier environment for functional languages, registration of the core technologies with an independent standards body, publication of an implementation for multiple platforms, with source code, etc. etc.

    Of course, .NET doesn't get everything right, but it's amazing how many good things are in there, especially considering that it comes from Microsoft.
  • by Mr2001 ( 90979 ) on Sunday September 18, 2005 @08:49AM (#13589059) Homepage Journal
    I guess all the implicit typing additions make sense in the context of LINQ, where SQLish queries are translated into C# code involving lambda expressions. In all my years of coding in Delphi and now C#, I've never needed to use BDE, ADO, or any other OOP database interface, so I can't gauge how useful these additions will be.

    However, this example of yours seems like a bad one:
    foreach (var item in collection) {
        Console.WriteLine(item);
    }

    If you're changing the type of the collection, a few foreach loops are the least of your concerns - what about all the code that actually manipulates the items' methods and properties? And if you're using a snippet like that so much that you're tempted to paste it over and over to work with collections of different types, you should really change it to a generic method:
    static void PrintItems<T>(ICollection<T> collection)
    {
        foreach (T item in collection)
            Console.WriteLine(item);
    }

    In summary, I can see how these implicit typing additions would be useful for the compiler, or rather for the language designers to explain how the compiler will implement features like lambda expressions and LINQ, but I can't see myself ever using 'var' instead of an actual type name.
  • by phidiot ( 211304 ) on Sunday September 18, 2005 @08:57AM (#13589075) Homepage
    It looks like it would be useful when combined with LINQ type queries as in:

    var q =
    from c in customers
    where c.City == "Seattle"
    select new { c.Name, c.Age };

    q would result in an implicitly typed collection of objects that contain Name and Age properties only.

    Here [msdn.com] is a good description of using both
  • by RAMMS+EIN ( 578166 ) on Sunday September 18, 2005 @08:57AM (#13589076) Homepage Journal
    In the past, I've made the argument that forcing people to declare types lowers productivity and decreases legibility.

    The one good rebuttal I got was that it really helps to declare types on function parameters; it serves as a kind of documentation of the intended use and operation of a function. Plus, of course, it allows the compiler to catch errors where the function you write doesn't have the type you say it does.

    I guess that's also the reason Haskell programmers like to declare the types of their functions, even though it's optional in Haskell.
  • by SuperJason ( 726019 ) on Sunday September 18, 2005 @09:00AM (#13589085) Homepage
    I have a whole list of reasons, which have been hashed out millions of times in millions of other forums.

    I'll just give you the top reason that I use c#.

    In VB.NET, Build and Rebuild are the same thing! If you change one class and do a build, on a large project it can take MINUTES.

    The same project and change in c# can take SECONDS to build.

    The time savings alone could buy a lot of stuff.
  • by Mr2001 ( 90979 ) on Sunday September 18, 2005 @09:00AM (#13589086) Homepage Journal
    Having a declared type lets you know how you can use that variable. Can you pass it as a ref parameter to method XYZ that wants a "ref int"? Can you use it to store the result of method ABC, which returns a float?

    In a dynamically typed language, the answer is always yes because variables have no fixed type. But in C#, the variables still have fixed types; they're just hidden. You have to look at the declaration "var x = 5" and think "Hmm, I guess that's an int", just like the compiler does. And for declarations like "var y = SomeFunction()", you have to go look up SomeFunction to find out what type it returns before you can know y's type.

    It might save you a split second of typing to write "var" instead of a real type name, but 6 months from now when you have to find a bug in that code, it'll cost you just as much time to figure out what type those variables are.
  • by Sanity ( 1431 ) on Sunday September 18, 2005 @09:01AM (#13589089) Homepage Journal
    It is exciting to see developments like this in C#, particularly stuff like LINQ (the inelegance of using SQL from within other languages has bugged me for quite some time).

    Java's language features, by comparison to C#, seems to be moving along at a glacial pace, only recently getting features like foreach loops, and generics.

    I personally prefer Java because of Eclipse [eclipse.org], but Sun are really going to have to get a move on if Java is to remain competitive with C#.

  • by Anonymous Coward on Sunday September 18, 2005 @09:15AM (#13589135)
    The real problem is that while your competitors were rewriting their products in Java, you were sticking with VB. And now you want to blame Microsoft for that. Sorry, that's not gonna fly. And yes, I am a software developer. Rewriting into another language can get you a lot of benefits that you can quickly roll out into your application. It's not 'just' rewriting. And .NET does not necessarily mean platform/vendor lock, either.

    Not that that actually matters, because most people are all still using Windows anyway, and will be for a long time.
  • by ergo98 ( 9391 ) on Sunday September 18, 2005 @09:39AM (#13589220) Homepage Journal
    All hail our new fat client overloads. Oh joy.

    Fat clients? You do know that the majority of .NET development occurs in the web services/web app space, right? Even then, middle-tier services in .NET are just as usable by a web facade as they are a fat client. In no way is this a fat client-only technology.
  • Written in both-- (Score:4, Insightful)

    by Tominva1045 ( 587712 ) on Sunday September 18, 2005 @09:42AM (#13589223)
    As someone who has served as a consultant and written applications in both languages this is what I can add:

    My VB apps were much quicker to prototype- to provide something to a customer in helping them determine requirements when they aren't really sure what they need. Also, the VB apps are often easier to maintain (less cryptic code can be easier to maintain).

    My C# apps were usually written in that language because the client had a preference for it- not that any logical reason was given (unless you count putting C# in marketing information to justify higher costs). Also, because the lanugage can be more difficult to follow (meaning less likely the client's in-house developers can code or update it) than VB, consultans can often charge a higher hourly rate to code in it.

    Both languages build to the same IL output.

    Comments such as this one from above a great language for people who don't want to know to much about what thier program is actually doing - but VB .NET is, and will always remain a hack.

    show a real bias whilst not providing any detail whatsoever. So take them with a grain of salt. Unless your reading machine language, you don't really know what your appp is doing.

    It is possible to write great code in each. It is also possible to write really bad code in each. It comes down to the developers ability and preferences.

    If you have a nice fat contract and want to perch in your ivory tower looking down upon the commoners, go with C#.

    If you have demanding clients and need to give yourself some breathing room, go with VB.
  • by noamt ( 317240 ) on Sunday September 18, 2005 @09:44AM (#13589234) Homepage Journal

    foreach (var item in collection) {
                Console.WriteLine(item);
    }


    This example makes no sense.
    Is "collection" a collection of objects or something more concrete? If it's an object collection, s/var/object/ in your example.
    The compiler inferes the variable type at compile-time, not run-time. So "var" will become "object" anyway.

    var i=5; // same as int i=5;
    i="str"; // won't work, because i is an int.

    Of course, maybe I got it wrong..
  • by ChaoticCoyote ( 195677 ) on Sunday September 18, 2005 @09:51AM (#13589254) Homepage

    Why, oh why must language inventors continue to add every possible concept to their pet project? Must every language try to be everything to everyone?

    No programming language is suited to all applications; anyone who claims omnipotence for their particular language is exhibiting either ignorance or arrogance. A wise programmer knows how to use many tools in appropriate contexts; it's this sort of rational maturity that separates amateurs from professionals. It makes no more sense to develop a web-hosted applet in C++ than it does to write a high-performance batch-processing engine in Java. Using multiple programming languages isn't a simple matter of syntax -- it's a matter of divergent perspectives that force me to think about what I'm developing.

    A disturbing trend has emerged in the last decade, with developers trying to make every programming language applicable to every task; we add object-oriented features to COBOL and Fortran, add generic types to Java, and expand the C++ library with a plethora of complex templates. Now C# is "borrowing" all sorts of ideas from all over the map, without any thought for how all these pieces fit together into a cohesive and logical whole.

    In the end, we get bloated tools that include features ill-suited to their core design. Instead of focusing on a clear set of goals, languages compete in an edless feature competition that often ignores sound engineering practices.

    I have done professional C# programming, and the language does not impress me. Certainly it has some very good ideas -- but it lacks any sense of cohesion in design or intent, and it's ties to Microsoft make me leary of using it for long-term coding projects.

  • by MSBob ( 307239 ) on Sunday September 18, 2005 @10:10AM (#13589312)
    Java innovates but in a different area. There is a lot of emphasis on extending Java with Aspect Oriented Programming (AOP). There is an incredible extension to Java called AspectJ. You owe yourself to download AspectJ and its Eclipse plugin. You'll see the future of java programming when you try it.
  • by superid ( 46543 ) on Sunday September 18, 2005 @10:14AM (#13589328) Homepage
    I don't think this is a kitchen sink addition. I think this will be a welcome addition to a very large fraction of C# developers. First, my gut feeling is that the majority of non-trivial C# applications connect to databases of some kind, this will help that. Second, even if you don't use a DBMS this will be useful for complex operations on pretty much any data structure that you create.

    This will make me a lot more productive and I'm going to install it ASAP!

  • by XNormal ( 8617 ) on Sunday September 18, 2005 @10:15AM (#13589330) Homepage
    As an open-source I really hate to say this but...

    This is a terrific example of honest-to-god innovation from Microsoft.

    Yes, I know, the building blocks have been available in some form or another in many other platforms. But so far nobody has managed to bring all of this together so elegantly.

    The features are not just a random heap of syntactic sugar. They combine to create the query syntax (using lambdas) which can be either executed directly in C# (with the help of external methods) or be available as a runtime data structure (shades of lisp) that can be translated dynamically to an SQL or XQuery and sent to a remote server for execution. The type inference ensures that the query syntax is not littered by type declarations yet remains typesafe.

    Nice work, Anders. I guess the Comega team deserves much of the credit, but I have the feeling it was Anders who brought it all together into a clean and not too "academically smelling" framework.
  • by Anonymous Brave Guy ( 457657 ) on Sunday September 18, 2005 @10:33AM (#13589381)

    Do you actually have any solid information to support your claims here, or are you just expressing your personal opinion as fact?

    Almost all of the posters objecting to type inferencing here quote examples like your

    var y = SomeFunction()
    as an illustration of how code is less readable without a type. Guess what? Code isn't very readable if you call your functions SomeFunction anyway, and writing
    int y = SomeFunction()
    or
    SystemLibrary.MathModule.FloatingPoint.LongDouble y = SomeFunction()
    really doesn't help.

    On the other hand, if your functions and variables have meaningful names, you probably don't care whether the value returned is a float or a double most of the time. Type inference makes your code more generic, without losing any particularly useful information (if it is useful, you can still specify it), and the type safety of the system prevents the sort of

    double -> float -> loss of precision
    errors typical in languages like C.

    In other words, I see a lot of scare-mongering in this thread, but very little evidence that it's justified, other then people saying, "It's unfamiliar and I don't like it". Do you have anything more for us?

  • by XNormal ( 8617 ) on Sunday September 18, 2005 @10:48AM (#13589441) Homepage
    Why, oh why must language inventors continue to add every possible concept to their pet project? Must every language try to be everything to everyone?

    This isn't just a random heap of features. They all combine to create the query syntax which can run in-memory as C# code or be translated to external query languages such as SQL or XQuery and sent to a remote server for execution.

    No programming language is suited to all applications;

    But C# with embedded query syntax is an elegant solution to bridging high level languages and databases. This answers a very real and very pressing need in the industry.

    Certainly it has some very good ideas -- but it lacks any sense of cohesion in design or intent, and it's ties to Microsoft make me leary of using it for long-term coding projects.

    It only looks that way if you don't RTFA...
  • by Anonymous Brave Guy ( 457657 ) on Sunday September 18, 2005 @11:09AM (#13589532)
    As a Java programmer, it is exciting to see these developments in C#, it makes me wonder whether Java is destined to fall behind C# - it sure looks like that is happening....

    Perhaps. But then again, Java evolved very fast in its first few years, and a lot of what it evolved was crap, particularly the numerous poorly-considered additions to the library that now have to be supported pretty much forever. Policies on language features were made on evangelical grounds -- "We don't need templates!" springs to mind -- and a decade or so later, people are eating their words (as more conservative/deep-thinking programming communities have been telling them they would all along).

    There is a lot of merit to stability in programming languages that are used by real people for real jobs. Some languages go too slowly, IMHO: I think C++ is drifting off into specialist worlds with a single really active supporter at the expense of useful mainstream stuff with no champion, but that's more a result of the way the standards committees are set up than anything else. Likewise, Perl 6 is becoming almost a completely different language, which is no longer recognisable as an evolution of Perl 5. But at least there's time for people to keep up, and in the meantime, everyone's able to use a solid baseline in C++03/Perl5 for real work.

    These developments in a mainstream language like C# have potential to bring useful programming techniques into the mainstream, for the first time in some cases. Still, when most of the C# world is still exploring version 2, I can't help feeling that they'll either lose support or develop a community full of keen but under-informed developers producing naff code because they didn't have time to learn everything at once. Sometimes exciting isn't the best thing.

  • by vyvepe ( 809573 ) on Sunday September 18, 2005 @11:30AM (#13589625)

    * type names can get long, especialy when templates are used

    * why do you want to do the compiler's work

    * editor with intelisense will tell you the type for the expression in most cases so no need to repeat it

    * you do not need to modify so much places if type changes during development

    * and if you really want you can get the exact type, but mostly it is just waste of time

    AFAIK, they are going to add this to C++ too

  • by Detritus ( 11846 ) on Sunday September 18, 2005 @12:18PM (#13589821) Homepage
    Niklaus Wirth [wikipedia.org] designed Pascal. Anders Hejlsberg [wikipedia.org] wrote a number of popular Pascal compilers, such as Turbo Pascal.
  • by fupeg ( 653970 ) on Sunday September 18, 2005 @12:26PM (#13589856)
    The answer to your question is no. Java has clearly borrowed some things from C#, though C# itself heavily borrows from Java. The EJB 3.0 spec [jcp.org] for example will make use of dependency injection. Take a look at Groovy [codehaus.org] which will be integrated into Java (javax.script [java.net] in 6.0.)

    Now it is true that as a more widely used (on the Enterprsie level) language, Java is going to move more slowly than C#. C# is newer and trying to take mindshare from Java, so it must move faster. Just having a great IDE is not enough.
  • by ari_j ( 90255 ) on Sunday September 18, 2005 @01:08PM (#13590010)
    Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp.

    These changes to C# bring it closer to Common Lisp, and therefore make it easier to include those ad hoc implementations of it.
  • by oldCoder ( 172195 ) on Sunday September 18, 2005 @01:13PM (#13590034)
    Are there any examples of insertion? What to do with null fields? I haven't had time to study all the stuff yet...

    So, in wrap up, how far does this take us to the Brooks' "Magic Bullet" for programming? Does further tying data structure into code still provide the clean separation between code and data required by good design? Can I prevent my data definitions from proliferating all through my source base so when the DBA re-does the database I'm not stuck with obsolete and broken applications?

    And can I do stored procedures and give up SQL entirely or will DBA's need to learn both SQL and a new .NET language in addition to all their existing admin tools?

    Can I use Reflection to inquire of the structure of the data and generate code to manage the database? Or are the older solutions still the best for this?

    In what other ways will SQL-server and .NET become more tightly integrated? And when will the both become part of the Operating System like IE, with all the attending benefits?

    I see the polymorphism angle (XML/Databases/Arrays) but is there a way to inherit data definitions? To subclass them?

    And when will the WMI [microsoft.com], the Windows hierarchy in a GUI application, the programs own class hierarchy through Reflection, and the HTML-DOM be accessible through these new interfaces, or have I just run aground on the shoals of logic and imagination? A bridge too far? How about the files in a directory, or is that just WMI again?

    What tools and hacks will be need to deal with volatile (externally modified) dynamic data? SQL-server has some of it's own but coders still need to specify read-with-lock from read-without-lock. All the other data except for arrays and some XML is volatile (subject to modification by other threads or CPU's). Different data sources have different volatility models (db's, WMI, processes running on the OS, nodes on the net).

  • by Anonymous Brave Guy ( 457657 ) on Sunday September 18, 2005 @01:26PM (#13590092)

    I think there's a lot of truth in what you wrote there. That said, while specialist languages have their place, I'm increasingly wondering why no-one has yet produced the next great general purpose language.

    Why can't we have a simple, elegant syntax like much of Haskell or Python, with punctuation frenzies reserved for things like regular expressions and printf formats where history shows they work well? Why can't we have a grammar that's amenable to parsing by automated tools, to make it easy for IDEs to provide refactoring aids, consistent formatting, etc? Why can't I have an imperative language that still supports higher-order functions and the like? Why can't I have proper disjunctive types and pattern matching in a language that supports OO with RTTI/reflection capabilities anyway?

    I don't do professional compiler design, but I'm fairly familiar with the theory, and none of this seems to be prohibitively difficult. Indeed, most of it has been done in some form or other, somewhere. I just don't see why none of the places that invests so much in programming languages has managed to produce something like this yet. If they did, I don't see any reason we couldn't have a language suitable for a wide variety of applications, offering a clean, powerful syntax, yet still generating code that performs at a comparable speed to that from a low level language.

    The technology seems to exist, it's just the language that (bizarrely) doesn't yet. We seem to be stuck in a rut where the only languages that are willing to risk major departures from common syntactic conventions and tool sets are new scripting languages and academic research, and so far each of them has had some significant drawbacks when it comes to industrial-strength, large-scale projects.

  • Re:Not really (Score:3, Insightful)

    by spongman ( 182339 ) on Sunday September 18, 2005 @02:00PM (#13590211)
    that's fine if your program is so simple that every posible code path can be executed in a short amount of time, but for anything but the most trivial rograms this is impossible (see Turing for a reason why). This means that for dynamically typed languages, the onus is on testing to find a whole slew of errors that statically-typed languages can find at compile time.

    not a good solution for multi-K-line programs written by large teams of programmers.

  • by Anonymous Brave Guy ( 457657 ) on Sunday September 18, 2005 @04:31PM (#13591117)

    One of us is misunderstanding here, but I'm afraid it's not me.

    There is nothing about inferred typing that requires things to be of some base "object" type. Indeed, in many languages that use it, there is no base type, nor even necessarily the concept of inheritance.

    In the case of the code we were discussing:

    foreach (var item in collection) {
    Console.WriteLine(item);
    }
    it would be normal to deduce the type of item from the type of collection and the behaviour of the foreach ... in ... construct. That type would then be checked against the requirements for WriteLine, and an error generated at compile time if the types were incompatible. Whether C# specifically will be doing this, I don't know, not having read the specs for the new features in detail. There's no reason the use of type inferencing techniques generally can't, though.

    You seem to be looking at this from the point of view of C# and its current generics features only, and in that restricted context, perhaps there is indeed some silly performance hit. I'm looking at the pros and cons of inferred types generally, and in that more general context, there is no need for the clutter of generic syntax, and many languages work quite happily without it.

    BTW, even if your platform does implement this naively by using a universal base type, a performance hit of 500% for doing so is appalling, and suggests you have far deeper problems on that platform than how generics are handled!

Scientists will study your brain to learn more about your distant cousin, Man.

Working...