Jaa


Stroustrup talks on V-Next of C++. Do they apply to C#?

For a long time I am out of touch with the C++ world. Amit pointed me to the paper A Brief Look at C++0x which talks about C++0x scheduled to be released in 2009. I loved some of the new features. Some of the changes proposed in C++ brings it closer to C#. Here is a run down with some comparisons with how the new C++ features match up with C#

  • You can now use something like template<class T> using Vec = vector<T,My_alloc<T>>;
    So aliasing is now supported using the keyword using :). I always had some doubt regarding the benefits of having typedef in C# and now we see C++ extending on it as well. I think I'll post later on why C# does not support typedefs and weird things people do to get around it....
  • In the same snippet as above there is a subtle change. I had blogged about it before. You no longer need to have an extra space in between the two >> in nested template definitions as was required before. As I said C++ is getting closer to C#
  • The next one is cool. You can now do Vec<double> v = { 2.3, 1.2, 6.7, 4.5 };
    So you have collection initializers in C++ as well. C# has this too in its next version (3.0). I blogged about this some time back. Combined with object initializers C# is going to be much more powerfull in this.
  • Introduction of Concepts. Concept is the type of a type. Using this you can specify what properties a type should have. It is something similar to the generics where clause in C#. The difference is that concepts in C++ is much more powerful than C# since it is not class hierarchy based. However, both use the where clause. Currently Boost libraries have an implementation for this. Read more about it here.
  • And you have the dreaded implicit type. In C# you call it var and in C++ auto. In a expression like
    for (auto p = v.begin(); p!=v.end(); ++p)
    cout << *p << endl;
    The type of p is inferred from the return type of v.begin().

Interestingly as Stroustroupe himself says all the new features are targeted for generics development. This is very close to the C#2.0 release which had a huge number of changes targetted for generics.

Comments

  • Anonymous
    January 03, 2006
    While I think the new C++ features are pretty nice, they are also coming too slow, too late.

    By 2009, Microsoft will have at least two more revisions of C# out, looking at the history. In all that same time, C++ stands still. C++ is going to go the way of the dinosaur if it continues to evolve this slowly.

    Disclaimer: I'm not an MS employee, nor do I have any information about C# direction. These are just my estimations based on what has been done to-date.
  • Anonymous
    January 03, 2006
    This is absolutely true. C++ being an ISO standard moves very slowly. There are just too many parties to convince to include anything in the standard.

    C# on the otherhand is much faster to evolve. 2.0 was a generics targeted release. 3.0 will be Data-driven (LINQ) programming. Even before 2.0 was formally released (RTMed) there was a CTP release of 3.0. Folks are even working on versions beyond that.

    Another interesting thing is that there are always those new languages like COmega, X# where people experiment on new features and successful ones get ported over to C#.

  • Anonymous
    January 04, 2006
    The comment has been removed
  • Anonymous
    January 04, 2006
    Rosyna, some compilers may implement what is being considered. But there are two cathes.
    o Would you use them? After standardization they may change significantly and the compiler sooner or later aligns to it. So to achieve cross-compiler support you will have to re-write your code. So most commercial or serious software will wait for the standard to come out before adopting the changes irrespective of whether some compiler already support them

    o Even if compiler implements them before hand and you use them how long into the future can you see. For example you'll have to wait for C++09 to come out, then discussions will start for the version after that. So till 2009 you are stuck with what is being considered and no forsight beyond that. Think about C#. You right now know what is coming in C#3.0 in VS Orcas. Even before that comes out you'll know what is after that. Short cycles are always better in this kind of scenario..