Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 22nd, 2006, 11:39 AM   #1
JimmyJim
Programmer
 
JimmyJim's Avatar
 
Join Date: Jul 2006
Location: England
Posts: 43
Rep Power: 0 JimmyJim is on a distinguished road
Whats C# 3.0 all about?

I was looking at C# 3.0(not .net 3.0) today and its quite interesting what they have lined up for the language in the future. Lambda expression, extension methods, type inferencing and LINQ.

Lambda expressions look interesting, but i dont have much knowledge of what they are about and what you would use them for. I think they are based of lambda calculus, which to generalise grately is just another way of expressing a mathamatical function.

Extension methods are ways of extending a class which you dont have the source code for and dont want to make a new class inheriting the one you want to extend. Kind of usefull for adding one or two methods to a class. Maybe this would be confusing, for example in a program someone could add a method to string(or whatever) and then you have to go hunt it down to see what it does.

Type inferencing looks like it could be abused. As you can say:
         var i = 90;
         var s = "Hello World";
This is not dynamically typed like python, but the variable declared takes the type of the expression on the right hand side. I think its to get around the need to type alot, e.g.
       //C# now
       List<string> s = new List<string>();
       //C# 3.0
       var s = new List<string>();
This would mean you dont have to type List<string> twice, but what about this.
      var s = new List<string>();
      s.Add("Hello");
      s.Add("World");
      ...
      var t = s; 
      //now you have to go find out what type s is to know what type t is.
So you can see where it could get anoying and be abused alot.

LINQ is Language Integrated Query. Its a way of accessing data in an object oriented and typed checked way. It looks like a very good idea but to make it work it requires all the other features described to be added.

I know this is quite brief and not very technical. I was wondering what other people thought about these proposed new features and if they are really needed or just add bloat to a very good language. Is this the future in programming getting more declaritive(put simply, you say what you want and the compiler goes and figures out how to do it) and the c# design team are just following the trend(if there is one).

Language design is one of my interests, i find it interesting how different languages work and why some features work well and some dont. If you think im slightly insane then i agree with you lol.
JimmyJim is offline   Reply With Quote
Old Jul 22nd, 2006, 12:10 PM   #2
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
I see your point, and I don't like it either. Seems sloppy. That's why I left VB6 and came to C#. Now I come to C#, and it gets sloppy? Come on people...
I guess as long as we can still do it the old way, it will be alright. I'll probably look into C# 3.0 later and post back.
Booooze is offline   Reply With Quote
Old Jul 22nd, 2006, 1:27 PM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by JimmyJim
Lambda expressions look interesting, but i dont have much knowledge of what they are about and what you would use them for.
In terms of C#, they're essentially a quick way of writing anonymous delegates that return a single expression.

In C# 2.0:
csharp Syntax (Toggle Plain Text)
  1. Func<int, int> double = delegate(int x) { return x * 2; };
In C# 3.0:
csharp Syntax (Toggle Plain Text)
  1. Func<int, int> double = x => x * 2;
Quote:
Originally Posted by JimmyJim
Type inferencing looks like it could be abused.
I think you're quite right about this, but I think the benefits outweigh the disadvantages. So long as the people you're programming with are competant (and if they're not, then the var keyword is the least of your worries), then var will be used sparingly.

Quote:
Originally Posted by JimmyJim
I know this is quite brief and not very technical. I was wondering what other people thought about these proposed new features and if they are really needed or just add bloat to a very good language. Is this the future in programming getting more declaritive(put simply, you say what you want and the compiler goes and figures out how to do it) and the c# design team are just following the trend(if there is one).
I recently found myself watching a Python screencast, and in it the author said something which I think is rather relevant to the question you asked: "Code is read more than it is written."

This is a phrase that is so basic as to be almost self evident. You will only write a particular line of code once, whilst that line of code may be read many times, by many different people.

This reminded me of another phrase that has stuck in my mind: "Code is more easily written than it is read." This far from self evident, and I'm not sure I agree with it entirely, but it does make a lot of sense. Reading another person's code is hard. If it wasn't, then we wouldn't have to comment our code. Whether reading is harder than writing is debatable, but understanding what a piece of code does is clearly not a trivial matter.

Given all this, one comes to the conclusion that readability is rather important. A factor that affects readability is how much unnecessary information there is in the code. For example, compare C# 2.0:
csharp Syntax (Toggle Plain Text)
  1. MyContainer<Person> people = new MyContainer<Person>();
  2. MyContainer<Person> children = people.Where(
  3. delegate (Person person) { return person.age < 18 }
  4. );
To C# 3.0:
csharp Syntax (Toggle Plain Text)
  1. var people = new MyContainer<Person>();
  2. var children = people.Where(person => person.age < 18);
To my mind, the C# 3.0 code is the more readable, because it reduces the amount of unnecessary information.

On the other side of the coin, sometimes code doesn't give enough necessary information. Compare C# 2.0:
csharp Syntax (Toggle Plain Text)
  1. Person person = new Person("Fred", 31, 8);
To C# 3.0:
csharp Syntax (Toggle Plain Text)
  1. var person = new Person {name = "Fred", age = 31, shoeSize = 8};
Again, 3.0 wins over 2.0. With 3.0, we can see that the '8' value refers to the person's shoesize, and that '31' refers to his age. In C# 2.0, the answer isn't immediately obvious (especially as Fred's shoe size might be in European measurements).

Quote:
Originally Posted by JimmyJim
Language design is one of my interests, i find it interesting how different languages work and why some features work well and some dont. If you think im slightly insane then i agree with you lol.
One of my interests as well, funnily enough
Arevos is offline   Reply With Quote
Old Jul 22nd, 2006, 1:33 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
The type inferencing can certainly be abused...like other constructs, it will just have to have some style guidlines. Such as only using it when the type is actually in the rhand, rather than another variable.

LINQ should be wildly useful. It should eliminate a lot of loops and conditions for processing data, such as finding an item in a list that meets certain criteria.

The type inferencing with lamdba expressions looks like a nightmare...
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270

Last edited by Dameon; Jul 22nd, 2006 at 1:53 PM.
Dameon is offline   Reply With Quote
Old Jul 22nd, 2006, 1:35 PM   #5
JimmyJim
Programmer
 
JimmyJim's Avatar
 
Join Date: Jul 2006
Location: England
Posts: 43
Rep Power: 0 JimmyJim is on a distinguished road
Thanks Arevos, i always like to see what other people think and you have explained alot of the stuff i was not completely sure about.

I can see that lambda expressions are quite a nice feature now and im sure i will use them if they ended up in the final specification for c# 3.0. Though im still unsure that type inferencing is worth the hastle that it could create if it is badly used.

I agree that writing code is easier than reading it, but i enjoy looking at how other poeple solve a problem especially if it is different from the way i solved it.
JimmyJim is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC