Click here to Skip to main content
Click here to Skip to main content

Introduction to C# 3

By , 13 Sep 2005
 

Introduction

Just look at the C# 3 future, it's so pretty I want it now. Check out the videos that they have there. There is so much good stuff there, and it's only the start.  First of all, read the C# 3.0 spec [doc file], or just read the rest of the post to see the highlights.

Type Inferencing and Implicitly Typed Arrays

I got addicted to that when using Boo, it's something so simple, but it saves so much. In most cases, it means no more casting hell. Andres let it slip in a presentation about a year ago, in essence, it means:

var sum = 0;
var intArray = new [] { 1,2,3,4};
foreach ( var i in intArray )
{
    sum += i;
}

This is a very cool idea, especially since you can use it for the foreach construct, which should make for far better code. Did you notice how I declared the array? new [], without a type, the compiler just fixed it up automatically.

Extensions Methods

This is a feature that lets you add new instance methods to a class, without touching the class code and even if the class is already compiled. The idea opens up so many possibilities that it's just staggering. Fowler talked about it in Refactoring. Other languages, such as SmallTalk and Ruby already have it (SmallTalk has it for 30 years, I think), and it has proved to be a useful feature. You could add methods to System.Object, which would then be "inherited" by any object. Consider adding ToXmlString() for all objects, for instance. Or persistence to database. And no, it's not just syntactic sugar, those things are important. This mean that you're no longer at the mercy of the class designer. It's a truly powerful tool. The nicest thing about it, I think, is that it'll work with generics, so you get a host of goodness for very little effort. Here is the example from the spec:

public static class Sequence{
            public static IEnumerable<S> Select<T,S>(
                        this IEnumerable<T> source, Func<T,S> selector)
            {
                        foreach (T element in source) yield return selector(element);
            }
            public static IEnumerable Select<T,S>(
                        this IEnumerable source, Func<T,S> selector)
            {
                        foreach (T element in source) yield return selector(element);
            }
} 

What does the above say? Well, it means that you can now use Select() on any object that implements IEnumerable. You could even use them on your 1.0 and 1.1 collections! Can you say goodness? This is cool on so many levels that it's not even funny.

Here is another nice thing that you can do:

public static class ExtermalObjectMethods
{
    public static bool IsNull(this object obj)
    {
         return obj == null;
    }
}
object nullObj = null;
if (nullObj.IsNull() )
   Console.WriteLine("Object is null");

Just how cool is that?

Extension properties, events and operators are currently considered, but not yet supported. I certainly hope that Microsoft will implement those, as they would allow a much nicer syntax for a lot of things (an IsNull property, for a start). Adding operators to interfaces is another big problem that this can solve.

Lambda Expressions

This is like anonymous methods, only with an even easier syntax. This is something that I don't think most .NET developers will appreciate now, but they certainly would two years from now, when the functional goodness will be fully entranced. Here is how you would extract all the names from a list of customers:

string[] names = GetListOfCustomers().Select( c => c.Name );

Can you see the beauty of it? The "c => c.Name" is the lambda expression, which is just a way to tell the compiler to do the dirty work, instead of having to do it ourselves using anonymous delegates. If it was all that they were good for, they wouldn't amount to much, but they have quite a few other usages, as you'll see shortly.

Object and Collection Initializers

This is something that we had for quite some time in attributes, which is now coming to both object initialization and collections initialization. The idea is actually very simple, consider the class Person:

var ayende = new Person{Name = "Ayende", Surname = "Rahien"};
var persons = new List<Person> { 
    new Person{Name = "Ayende", Surname = "Rahien"}, 
    new Person{Name = "Foo", Surname = "Bar"}
} 

Just consider the shear amount of code that you would've to write in order to do the same today (or even in 2.0).

Anonymous Types

No, it's not Java's anonymous classes, but it's a nice enough feature. It means that you can declare a type by just using it.

var ayende = new {Name = "ayende", WebSite = http://www.ayende.com/};
Console.WriteLine(ayende.WebSite);

This would create a new type with Name and WebSite properties. While this may save some typing in certain cases, I'm not certain that this is a useful feature. You cannot use it outside of a method's boundary, since it has no type that you can access.

This is nice, but I don't like the way it's implemented now. Boo has something similar, but since Boo has type inferencing throughout the language there it actually makes sense, since it allows to return a strongly typed object from a  method, instead of an object array. Here is the Boo example:

def MethodThatReturnSeveralArgs():
    return tuple { Int: 1, Name: "Ayende", Null: null, TimeStamp: DateTime.Now}

print MethodThatReturnSeveralArgs().Name 

Since declaring variables using the var syntax is limited to local variables, I think this is unnecessarily limited.

Query Expressions

I expect this to be the big thing for C# 3, just as generics are the big thing for C# 2. The idea is to allow an SQL like syntax for selecting objects from a database/memory/XML directly into the language. The idea is quite involved, and I'm sure it will generate a lot of discussion. The idea is to be able to do the following:

var payingCustomers = from c in db.Customers
where c.Orders.Count > 0 
select new { Email = c.Email, Name = c.Name };
foreach (var c in payingCustomers)
{
   SendDiscountOffer(c.Email, c.Name);
}

There are all sorts of ways where you can plug into this statement and do all sorts of cool things with it. db.Customers may be an in memory class, or it can redirect the query to database, to remote machine, etc. This is also apparently the use case for anonymous types, as return types from lambda expressions. It's nice, but it's not enough. It should be expanded to regular methods as well, in my opinion. I suggest checking the spec anyway, I'm just touching the edge here, and I'm sure that there are a lot of cool implementations that I'm missing here.

Expression Trees

They are a way to turn lambda expressions into data. The idea is to be able to do this:

var valuedCustomers = session.Select(x => x.IsValued==true); 

What is this? Well, what happened here is that we saved the lambda expression "x => x.IsValued==true" and passed it to a persistence layer, which would parse the expression, and load from the database all the rows for which the expression is true.

The important thing here is that the Select method is not using a opaque string, but code that can be type checked and verified by the compiler. Presumably refactoring tools for C# 3 will also support this, so it will make life even easier.

For the author of the Select() method, life would be much easier as well. He won't have to parse strings, but rather deal with an AST tree. From experience, I know that dealing with ASTs is not the easiest thing in the world, but it's certainly much better than dealing with strings.

Summary

All in all, I really like the direction that C# 3 is heading for. Functional programming is not appropriate all the time, but it can save quite a bit of typing and a lot of awkward syntax. I'm very excited about the new abilities, and I think that they will present a quantum leap much bigger than 1.1 -> 2.0. Considering that those are just the language enhancements, I can hardly grasp the amount of goodness we will get in the class library and the associated tools.

I expect quite a lot of noise about query expressions (yes, they are cool). And a lot of activity in the area of lambda expressions as data, since it's a cool way to express much more than just ORM syntax.

The future is bright indeed.

History

  • 13th September, 2005: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ayende @ Rahien
Israel Israel
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 4memberrushijoshi25 May '11 - 0:25 
Good but not covering indepth
QuestionMore readable ???memberHumanOsc1 Sep '06 - 5:58 
What by the heck is that... A hybrid of javascript, sql and c... No it's c#3... Smile | :)
 
This extensions isn't more readable... Maybe, It's only an improvement for the author of a code snippet which is to lazy to write a type name or to explicity declare a class...
 
I can't imagine that this will be cost much lesser time to understand a foreign code which copious used this extension...
 
I believe c# isn't extended... It's more a retrogression to a unpracticable and unreadable language...
 
I'm so disappointed... Mad | :mad:
AnswerRe: More readable ???memberWillemM3 Jun '07 - 7:01 
Atually var is needed for the LINQ query operators. It's pretty unreadable to work with explicitly typed variables in the case where the LINQ queries get more complex. Also if you change one thing in the query, you most probably need a small change to the type declaration for the variable that is holding the result.
 
I really hope noone is going to use var for all those utility variables. That would mean a huge step backward for the quality of software written in .NET, but for LINQ this is great stuff.
 
WM.

What about weapons of mass-construction?

"What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson

AnswerRe: More readable ???memberzvkeber@yahoo.com22 Aug '07 - 7:51 
I completely agree.
 
First of all, type inference shouln't be needed since .NET 2.0 introduced generics.
The idea of avoiding usage of system.object was a revolution, and using type parameters
is simple and clear. How does a "var" make the code easier to maintain than "MyClass"?
Why is it simpler to think every time you look at a method "which type did I assign to it first?"
 
Lambda expressions seem useful in some circumstances, but the syntax is a bit awkward.
 
It seems as that most of these "enhancements" are just "tools" to enable LINQ technology.
And then again, LINQ seems as a bad thing. As MS introduced it - it is a tool for
rapid app development, where developers need not to know TSQL or SQL administration.
How are those "rapidly developed" apps expected to scale? How are they maintained in production?
Optimized? DBAs are going to have hell of a time maintaining SQL servers that are accessed by LINQ.
Shouldn't there be a sync between developers and dbas while developing an app?
 
The .NET framework was supposed to be object oriented, and all that the version 3.5 is introducing
seems like going back to JavaScript. Maybe the point was that Silverlight programmers need not to know
much about oop, and still can develop in C# syntax. Silly. Btw, does that mean that Silverlight clients
can access a database using LINQ? I still havent studied Silverlight much.
 

 


AnswerRe: More readable ???mentorKeith Barrow5 Sep '12 - 10:08 
HumanOsc wrote:
What by the heck is that... A hybrid of javascript, sql and c

Turns out, it was the future. Hindsight is 20/20!

Questionnull.IsNull?memberNcTrun10 Jul '06 - 8:20 
Can you really write a IsNull method which says "return this == null;"? I mean, once you have object o = null;, wouldn't o.whatever() throw a System.NullReferenceException?
AnswerRe: null.IsNull?memberAyende @ Rahien10 Jul '06 - 10:41 
No, it won't throw, because that is a compiler magic, and not a method call.
AnswerRe: null.IsNull?memberJudah Himango21 Jul '06 - 5:09 
To further what Ayende said, the compiler is actually generating the following code for you:
 
if(ExternalObjectMethods.IsNull(obj))
{
    Console.WriteLine("it's null");
}
 
Extension methods are, AFAIK, syntax candy, allowing one to extend a type.
 

Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
 
Judah Himango


GeneralRe: null.IsNull?memberNcTrun21 Jul '06 - 7:20 
oh, I hadn't tought about that! Thank you! Smile | :)
 

GeneralRe: null.IsNull?memberD_Guidi22 Mar '07 - 5:06 
So cool Smile | :)
GeneralExpression TreesmemberVladD315 Sep '05 - 8:18 
How convert the Expression Trees to delegate object? Or how generate MSIL from Expression Trees?
GeneralRe: Expression TreessussAnonymous15 Sep '05 - 8:29 
You don't, expression trees are a way to express intention as code.
They are not meant to be a delegate.
GeneralRe: Expression TreesmemberVladD315 Sep '05 - 11:53 
Really no way to make IL by expression trees? Confused | :confused:
Frown | :(
QuestionLambda expressionsmemberdan neely14 Sep '05 - 7:22 
I've never done anything with a functional langauge before, and looking at the code samples I don't have any idea what they're supposed to be doing.
AnswerRe: Lambda expressionsmemberKeith Farmer14 Sep '05 - 7:35 
Lambdas can be stored in variables and passed around. They're very much like anonymous delegates.
 
However, as I recall, lambdas can be manipulated.
 
Best to check with a LISP fan for the history and theory. I note that one thing that hasn't received much press yet are ExpressionTrees, which would be closer to what I think of as a lambda.

AnswerRe: Lambda expressionsmemberAyende @ Rahien14 Sep '05 - 8:30 
Lambda has two purposes:
* a leaner syntax for anonymous delegates
* a way to specify data in code.
 
In practice, you probably won't have to worry about the difference since it will look and behave the same to you.
But the idea is that you can do:
 
from customer in db.Customers
where customer.IsValued==true
select customer;
 
And the where statement will actually get data that is can dissassemble and manipulate. This means that you can write code that is type checked and can be very easily be disassembled to get your meaning.
For instance, DLinq will take the data about customer.IsValued == true and turn it into an SQL fragement, etc.

GeneralRe: Lambda expressionsmemberdan neely14 Sep '05 - 10:01 
MY issue is that when I look at the code examples I've no idea what they're supposed to do.
GeneralRe: Lambda expressionsmemberJudah Himango1 Sep '06 - 5:16 
dan neely wrote:
MY issue is that when I look at the code examples I've no idea what they're supposed to do.


Take the following C# 3 code from Ayende's article:
 
string[] names = GetListOfCustomers().Select( c => c.Name );
 
The interesting part here is the c => c.Name piece. That is equivalent to the following C# 2 code, using standard anonymous delegates:
 
string[] names = GetListOfCustomers().Select(delegate(Customer input)
{
   return input.Name;
});
 
If you didn't want to use anonymous delegates, it would look like this:
 
string[] names = GetListOfCustomers().Select(CustomerToNameConverter);
 
public string CustomerToNameConverter(Customer input)
{
   return input.Name;
}
 
As you can see, the C# 3 syntax is much more concise and far less bloated.
 

Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
 
Judah Himango


GeneralType InferencememberGary Thom14 Sep '05 - 3:01 
Personally this
 
var sum = 0;
 
makes me shudder. It reminds me too much of VB, it must be my C++ background, but I think stronger typing is better than looser typing.
 
Gary
 
Marc Clifton: "In other words, VB is like a bad parent. It can really screw up your childhood."
GeneralRe: Type InferencememberDaniel Grunwald14 Sep '05 - 3:31 
Don't confuse strong/weak typing with static/dynamic typing.
 
In VB, "Dim a" is the same as "Dim a As Variant". That's dynamic typing (and VB is weakly-typed, too).
 
But type inference is different:
The type is still known at compile-time, you just don't have to write it.
Type inference is "implicit static typing".
It's much better than VB's implicit dynamic typing.
 
For example, the code:
var a = 3;
a = "Text";

will cause an compiler error because a has the type int.
GeneralRe: Type InferencememberGary Thom14 Sep '05 - 4:10 
I understand, however int a = 3; is much easier and less confusing to read. I can however see its usefulness in conjunction with writing templates (generics) etc.
 
Gary
 
Marc Clifton: "In other words, VB is like a bad parent. It can really screw up your childhood."
GeneralRe: Type InferencememberAnders Dalvander14 Sep '05 - 4:57 
Which is easier to read:
System.Web.Services.Protocols.SoapHeader a = new System.Web.Services.Protocols.SoapHeader();
or
var a = new System.Web.Services.Protocols.SoapHeader();
 
I would prefer the second one. Now if they only could eradicate the new keyword:
var a = System.Web.Services.Protocols.SoapHeader();
GeneralRe: Type InferencememberGary Thom14 Sep '05 - 6:04 
Actually neither.
 
I much prefer:
 
using System.Web.Services.Protocols;
 
.
.
SoapHeader a = new SoapHeader();
.
.

 
Gary
 
Marc Clifton: "In other words, VB is like a bad parent. It can really screw up your childhood."
GeneralRe: Type InferencememberAnders Dalvander14 Sep '05 - 6:44 
I knew you would misread my post, thank you for doing so. Poke tongue | ;-P
 
InOtherWordsVBIsLikeABadParentItCanReallyScrewUpYourChildhood a = new InOtherWordsVBIsLikeABadParentItCanReallyScrewUpYourChildhood();
- or -
var a = new InOtherWordsVBIsLikeABadParentItCanReallyScrewUpYourChildhood();
- or -
var a = InOtherWordsVBIsLikeABadParentItCanReallyScrewUpYourChildhood();
 
Easy to read, huh?
GeneralRe: Type InferencememberGary Thom14 Sep '05 - 6:52 
Laugh | :laugh:
 
Point taken, though I still don't like the fact that there is no type specified at the point of declaration.
 
How does it deal with:
 
var a;
 
.
.
.
.
a = 1;
a = "xyz";
 
after first use a has always to be int (or is that a double, float, decimal)?
 
Would I be right in thinking that a "var" has to be scoped locally to a method, rather than global to a class?

 
Gary
 
Marc Clifton: "In other words, VB is like a bad parent. It can really screw up your childhood."
GeneralRe: Type Inferencememberdan neely14 Sep '05 - 7:32 
It doesn't. You have to implictly provide the type of a var by assigning it a value at declaration. The type can't change subsequently.
GeneralRe: Type InferencememberGary Thom14 Sep '05 - 8:07 
dan neely wrote:
It doesn't. You have to implictly provide the type of a var by assigning it a value at declaration. The type can't change subsequently
 
Thanks, I assume you have to be careful with number you assign.
 
Gary
 
Marc Clifton: "In other words, VB is like a bad parent. It can really screw up your childhood."
GeneralRe: Type Inferencememberdan neely14 Sep '05 - 9:42 
True. I wonder if 1.2 defaults to float or double.
GeneralRe: Type InferencememberLeslie Sanford14 Sep '05 - 10:06 
dan neely wrote:
True. I wonder if 1.2 defaults to float or double.
 
Double.
 
This code snippet...
 
Console.WriteLine(1.2.GetType().Name);
 
...prints "Double" to the console.
 
If you needed to specify that you wanted float (Single) instead of double, you could do this:
 
Console.WriteLine(1.2f.GetType().Name);
 
Or if you wanted to use double but make it explicit, you would use a 'd' instead of an 'f'.
 

 


GeneralRe: Type InferencememberJoshua Quick14 Sep '05 - 7:09 
This is easy to read too just like your example, and it can be done in VB.Net now:

Dim a As New System.Web.Services.Protocols.SoapHeader

 
But you can't do this in the current version of VB. At least while Option Explicit is on. So, the similarity ends here. But I have to say that "var" does remind me of "Dim".

Dim x = 1

 
I'm just rocking the boat a bit. Smile | :)
GeneralRe: Type InferencememberJudah Himango21 Feb '06 - 7:10 
What you've posted there is totally different. You're telling the compiler to store a SoapHeader object as a System.Object. You lose strong typing and also induce boxing if the type is a value type (such as int, Point, double, etc).
 
C# 3's implementation does not lose strong typing; the compiler infers the type from the usage, meaning less typing for the developer at zero cost of performance.
 
Now, VB9 will include compiler type inference, which means the VB
 
Dim a = ....crazy soap header here()
 
will actually produce strongly-typed code on par with C# 3's var.
GeneralRe: Type InferencememberJoshua Quick21 Feb '06 - 7:55 
Judah Himango wrote:
What you've posted there is totally different. You're telling the compiler to store a SoapHeader object as a System.Object.

 
Actually, you're wrong. It's not being stored into an Object. Notice keyword "As" in the following line. It creates a variable of type SoapHeader and instantiates it all in one shot.
 
Dim a As New System.Web.Services.Protocols.SoapHeader
 
Now if I did the following, then yes, it would be cast to an object. Notice the "=" here.
 
Dim a = New System.Web.Services.Protocols.SoapHeader
GeneralRe: Type InferencememberJudah Himango21 Feb '06 - 8:13 
I stand corrected and humbled. Smile | :)
 

Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango


GeneralRe: Type InferencememberOakman20 Sep '05 - 0:41 
Daniel Grunwald wrote:
It's much better than VB's implicit dynamic typing.
 
Doing research before putting your fingers on the keyboard often makes you look smarter.
 
from VB 9.0:
In an implicitly typed local-variable declaration, the type of the local variable is inferred from the initializer expression on the right-hand side of a local declaration statement. For example, the compiler infers the types of all the following variable declarations:
 
Dim Population = 31719
Dim Name = "Belize"
Dim Area = 1.9
Dim Country = New Country{ .Name = "Palau", ...}

 
Jon
Information doesn't want to be free.
It wants to be sixty-nine cents @ pound.
GeneralRe: Type InferencememberDaniel Grunwald21 Sep '05 - 3:12 
I think Gary was referring to VB's loose/weak typing, so that's clearly VB 7/8. I know VB 9 is a great improvement, I think type inference and the other new features fit much better to VB than C#.
It's nice they still do breaking changes like this, C# designers do not even add new keywords to the language. (yield, partial etc. are not keywords).
GeneralRe: Type InferencememberOakman21 Sep '05 - 12:11 
Loose/Weak typing would be a sacrament if C++ had had it and VB6 didn't.
 
Jon
Information doesn't want to be free.
It wants to be sixty-nine cents @ pound.
GeneralNot another C++memberPaul Selormey13 Sep '05 - 13:45 
Hope the excitement about a new language C# will drive it into creating another C++ monster.
 
Best regards,
Paul.
 
Jesus Christ is LOVE! Please tell somebody.
GeneralRe: Not another C++memberAyende @ Rahien13 Sep '05 - 13:51 
What do you mean?
About the changes to make C++ support the same syntax? (This will indeed be ugly, I think. If they decide to do it.)
Or that they would turn C# to C++ with all the complex rules?
GeneralRe: Not another C++memberleppie13 Sep '05 - 14:10 
C++ is to ugly, and it looks with all these new fancy keywords and 100 ways to do the same thing (in contrast to 1 correct way) C# is heading that way too Frown | :( Maybe the should call it C## or C#++ :p
 
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
GeneralRe: Not another C++memberKeith Farmer13 Sep '05 - 14:33 
Actually, if you take a look at things, they're simplifying the way things are done.
 
How many times have you had to re-create the way you search for objects in a list? How have you done that with a database? With XML? Answer: At least 3.
 
In how many different ways will you do it in C#3? Answer: one.
 
They're unifying APIs, and are taking extra time to do it right. Unfortunately, this means doing it only half-right the first time around (ADO.NET, for example).
 
Also, this is baked into the CLR, so any language can take advantage of it. I can see immediate application to Monad. In fact, much of Monad would be trivial within LINQ.
 
.NET 2.0 set up most of the machinery for doing LINQ -- LINQ is merely where it's been heading for the last few years. And after Orcas comes Hawai`i -- I'm hoping for distributed methods (a la MC#) in that one.
 

GeneralRe: Not another C++memberPaul Selormey13 Sep '05 - 14:53 
Nothing prevents them from adding or extending XML/ADO classes for database and XML related searches. But as part of a language!!!
 
Best regards,
Paul.
 
Jesus Christ is LOVE! Please tell somebody.
GeneralRe: Not another C++memberKeith Farmer13 Sep '05 - 15:12 
"As part of the language" is the problem.
 
If we wanted to just limit new features to C#, we may as well not bother with this whole CLR thing. But that is not the .NET way of things -- if there's a powerful tool, go ahead and play with it in a language, and then figure out how the CLR could best bring that to everyone, regardless of language. That's what they did with C-omega. It's what they avoided when they decided not to go with ObjectSpaces.
 
And it seems to work for the better.
 
They did this with Generics, and behold! Generics are now available, yesterday, in C++, C#, VB, IronPython, and so forth.
 
Today, everyone can experiment with a powerful, strongly-typed, performant means of expressing queries, and we won't have to think about what the persistence mechanism is, if any. We won't have to worry about XML or SQL being made obsolete by the Next Big Thing. The query mechanism has been decoupled from the backing store, and that lends itself to better longevity.
 
I also expect we'll see stuff from Spec# pushed into the runtime in the 3.0 timeframe, as well as Polyphonic C#.
 
I also expect, after .NET has been around for another 5-10 years, that its successor will take a look at what we have, and remove the crufts left over from not-quite-perfect ideas, just as we did with C++, Java, MFC, Win32, and ADO, and just as they've done through the last couple years of working on Whidbey.
 
.NET isn't *about* any particular language (except, perhaps, IL). It's about the CLR, and making it as powerful and as friendly to language developers as possible. There are no performance or sanity gains in trying to work around a missing feature.

GeneralRe: Not another C++memberPaul Selormey13 Sep '05 - 18:56 
Keith Farmer wrote:
They did this with Generics, and behold! Generics are now available, yesterday, in C++, C#, VB, IronPython, and so forth.
 
Sorry, Generics was built into a runtime and then access through C#. They were using Rotor at the UK lab.
 
Keith Farmer wrote:
I also expect we'll see stuff from Spec# pushed into the runtime in the 3.0 timeframe, as well as Polyphonic C#.
 
I hope they stay on the lab table.
 
Best regards,
Paul.
 

 
Jesus Christ is LOVE! Please tell somebody.
GeneralRe: Not another C++membernorm.net14 Sep '05 - 0:22 
I'll second that.

 
Blogless

GeneralRe: Not another C++memberKaveh Shahbazian21 Nov '05 - 20:11 
I am migrating to JAVA. I have fallen in love with C# for 3 years and now after my experiences with It in some big and average projects, I think It is a buzz oriented language. bye the .NET buzzwork! Frown | :( =)
 
Kaveh Shahbazian
GeneralRe: Not another C++memberPaul Selormey13 Sep '05 - 14:23 
Ayende @ Rahien wrote:
What do you mean?
 
Complex language. SQL is there for databases. If the C# creators had nothing more to do, pay them off.
 
Best regards,
Paul.
 
Jesus Christ is LOVE! Please tell somebody.
GeneralRe: Not another C++susskempf13 Sep '05 - 16:33 
Actually, if you look at it objectively, this isn't making C# more complex, but less so. We developers, on a daily basis, right code to iterate over data stores, filtering, sorting and transforming. Each and every data store has a different API. Many of those APIs require using complex syntax in the form of string parameters passed to functions that have to parse and interpret them at runtime. This is slower, less secure and provides no compile time verification. Further, all of these APIs require translations from one domain (the data store) to another (the CLR), and the translations are often not implicit but rather require explicit coding.
 
All of this means that even the simplest of examples using in memory objects represented in the native language still require more lines of code. The more complex the example, the more lines of code are different.
 
Example: We have an Employee object. From somewhere we've populated an array of these employee objects. So, we're going to deal with straight C# objects here. What's needed is to find all the employees who work for Manager X and sort the result by their salary. See how many lines of code this "trivial" task will take you in C# 2.0/1.1/1.0. In C# 3.0 it will require a single statement.
 
And the syntax is the same regardless of the data store used.
 
Not impressive enough? Imagine you have 3 data stores, one a DB, one a web service and a third an XML file. With LINQ you can create a complex join of all three data stores, sorting, filtering and transforming the results, again with a single statement. How complex would it be to do that in the "traditional" manner? Still think they are adding complexity? Well, either you'll have your mind changed over time or you'll be left in the dust by those that "get it", because this is truly what's needed for the future of all languages.
 
BTW, ECMA Script has a concept similar to this for XML data stores today in the form of a language extension called E4X. So others have already "gotten it".
GeneralRe: Not another C++memberPaul Selormey13 Sep '05 - 18:40 
kempf wrote:
Example: We have an Employee object. From somewhere we've populated an array of these employee objects. So, we're going to deal with straight C# objects here. What's needed is to find all the employees who work for Manager X and sort the result by their salary. See how many lines of code this "trivial" task will take you in C# 2.0/1.1/1.0. In C# 3.0 it will require a single statement.
 
Just say this cannot be done unless it is built into a language, then you have a point.
 
I know about E4X, even though I have not used it before. For Javascript, it is nothing different, they are already doing similar thing with HTML, so why not with XML - that is all.
 
Best regards,
Paul.
 
Jesus Christ is LOVE! Please tell somebody.
GeneralRe: Not another C++memberKeith Farmer14 Sep '05 - 7:39 
Of course it could already be done in the language. It could also be done in pure machine code -- and is.
 
So why do we bother with such niceties as frameworks? Why bother with C#?
 
I think you got out-voted there a while back.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 13 Sep 2005
Article Copyright 2005 by Ayende @ Rahien
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid