14

I am a full time C++ developer, and I really like the language. I think it is suited for almost any kind of application. Some people claim Java and C# are better suited for high level programming, but I'm not so sure about this. I have worked with all three languages, and when using C++, it happens only now and then I come across something that might be improved.

I'd like to know which features you'd like to see added to C++. I'm talking about big improvements here, and not about details like typesafe enums.

34

What I really miss is:

  • an easier module system, so it would be less painful to reuse code and plug in components. There are the .lib and .dll libraries, but in my opinion they are not good enough. C# and Java provide a much easier component system.
  • there should be a bigger standard library. I think this is the main advantage of Java and C# over C++. A standard GUI library would be especially handy, as you need it in just about all applications interacting with the user.
  • and to a lesser extent, a macro system more flexible than templates and c macro's. I know, I know, this is easier said than done :-)

Note: with "a more flexible macro system" I mean a better way to write code that generates code. C++ templates generate classes and functions at compile time, but you can only use them only to parameterize types. C macro's can do more, but they are not really integrated into the language.

Note: I know there are some good free C++ GUI libraries around (such as QT and gtkmm), but choosing one is far from easy. I think this deters new users and drives them to Java and C#, which is sad as it seems to be a wrong reason.

13

Better syntax support for namespaces.

C#:

namespace Common.Places.McDonalds
{
    class ParkingLot
    {
    }
}

C++:

namespace Common
{
   namespace Places
   {
      namespace McDonalds
      {
         class ParkingLot;
      }
   }
}
13

I think the premise of the question is mistaken, or there are two questions in there.

Just because you find things in Language X that you don't find in Language Y, that doesn't imply that you want those things in Language Y. Different languages have different emphases. If you copy all of the nice stuff from C# to C++ and vice versa, you will just end up with one bloated language...

12

I don't care. But I suggest that for every new feature that is added to C++ from now on, an existing feature of comparable complexity is removed.

11

Adding pattern matching like the one in Haskell and other functional languages.

example,

int fibonacci(0)
{
    return 0;
}

int fibonacci(1)
{
    return 1;
}

int fibonacci(int number)
{
    return fibonacci(number - 1) + fibonacci(number - 2);
}

some sort of overloading for values not types. Just the same as a switch except the compiler can do the dirty work for you.

Imagine that tiny tool with you when learnign your first WndProc :)

so this ::

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
            WPARAM wParam, LPARAM lParam)
{
    switch(Msg)
    {
    case WM_CREATE:
     break;
    case WM_DESTROY:
        PostQuitMessage(WM_QUIT);
        break;

    default:
        return DefWindowProc(hWnd, Msg, wParam, lParam);
    }

    return 0;
}

becomes this ::

LRESULT CALLBACK WndProcedure(HWND hWnd, WM_CREATE, WPARAM wParam, LPARAM lParam)
{
    return 0;
}

LRESULT CALLBACK WndProcedure(HWND hWnd, WM_DESTROY, WPARAM wParam, LPARAM lParam)
{
    PostQuitMessage(WM_QUIT);

    return 0;
}

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    return DefWindowProc(hWnd, Msg, wParam, lParam);
}
10

Not having to bother with header files, or at least not the order in which I include them. I find that I'm often in a Catch 22 situation where I have to do forward declarations or even implement some "broker" classes just because two or more .h files depends on each other. It is very time consuming. (But I may be too stupid to use C++ in the first place - I work 10 times faster in C# than in C++...)

10

Reflection is the only thing that I really wish C++ had that it lacks.

8

Built-in support for multithreading (although it should be coming in C++0x...whenever the thing is finally released).

A GUI library to design GUI easily (equivalent to Swing for Java or Winforms for C#).

7

C++ where to begin. This could go on for a long time but how about

  • No delegates. Function pointers were not designed for objects.
  • Syntax that is ambiguous to the
    compiler.
6

Garbage collection.

(BTW, this should probably be community wiki)

Edit: I didn't realise this would be so controversial... To expand on this: I don't actually want C++ to get garbage collection as it doesn't fit in with the C++ style of doing only what the code says (that's probably not the best way to say it, but I hope you understand what I mean). Despite that, when I use C++ after having used Java or any other language with GC I certainly miss GC.

Also, garbage collection was invented for LISP where manual memory management is... well, it would be horrible. (And if you need another reason for the utility of GC, imagine Haskell without it.)

5

Automatic reference to outer class in inner class (just like Java), I hate having to store the pointer manually and friend the class manually.

Old style inner classes could still be created using the static keyword.

What bothers me the most is that this can be completely handled by the compiler. This is no impact at all at runtime.


Closures! At least block-style programming Ruby-style, this is possible at compile time too.

Imagine:

    // Display all entries
    entries.each() void yield(Entry e)
    {
     std::cout << e << endl;
    }

    // Format entries
    const std::vector<std::string> entriesFormatted = entries.map() std::string yield(Entry e)
    {
     std::ostringstream stream;
     stream << e;
     return e.str();
    }
5

Compile time reflection (if we want it in runtime it could be made as a library later)
pattern matching for functions
cv qualifiers and concepts as template parameters
No garbage collection! Ever!
pure(side effect free) functions
language support for defining your own const-like propagated constraining qualifiers
compiler checked algoritm complexity annotations
Design by contract supported by language
polymorphic lambas
multimethods

5

Nothing.

I can see why people talk about memory management but this is handled more efficiently (IMO) with smart pointers.

I can see why people talk about larger standard library but in my office we have a huge standard library involving stl, boost, tinyxml (among others) and stuff we've written ourselves sometimes specific to the field we work in. You may say that this isn't transferable to another job but, for instance, I know how to use XML and changing the library isn't going to be a problem (for me).

I like (and use) the .net languages, python etc etc but like the op I just don't think they're better (or worse) than c++.

3

I miss the same functionality as I miss in any programming language, functions that will do my work for me.

3

A cleaner way to separate the interface and implementation than the PImpl idiom.

3

Lambdas and first-class functions would be nice.

3

I do both for my day job, and it's more what I'd take away from C++, than add to it, because anything you added to make up for one thing you still have all the other baggage.

In C# I miss the templates/macro, in C++ I miss simple strings, no header files, faster compiles.

3

Talking about this topic, dont miss the list from Bjarne Stroustrup himself:

Evolution WG issues list

3

For me just about the most awkward thing to do is to convert between enumeration member, its corresponding numeric value and its string representation. Out of the box C# "just works" in that respect.

3

I think C++ is great, but what it needs are faster compile times. I guess this isn't a language "feature" per se, but hey, I can dream, right?

Also, error messages that don't take 5 minutes to figure out. After a while, one gets used to figuring what this means:

error C2664: 'class std::_Tree<class 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> >,struct std::pair<class std::basic_string<
char,struct std::char_traits<char>,class std::allocator<char> > 
const ,int>,struct std::multimap<class std::basic_string<char,
struct std::char_traits<char>,class std::allocator<char> >,int,
struct std::less<class std::basic_string<char,struct std::
char_traits<char>,class std::allocator<char> > >,class std::
allocator<int> >::_Kfn,struct std::less<class std::basic_string<
char,struct std::char_traits<char>,class std::allocator<char> > 
>,class std::allocator<int> >::iterator __thiscall std::
multimap<class std::basic_string<char,struct std::char_traits<
char>,class std::allocator<char> >,int,struct std::less<class 
std::basic_string<char,struct std::char_traits<char>,class std::
allocator<char> > >,class std::allocator<int> >::insert(const 
struct std::pair<class std::basic_string<char,struct std::
char_traits<char>,class std::allocator<char> > const ,int> &)' :
 cannot convert parameter 1 from 'const int' to 'const struct 
std::pair<class std::basic_string<char,struct std::char_traits<
char>,class std::allocator<char> > const ,int> &'
 Reason: cannot convert from 'const int' to 'const struct std::
pair<class std::basic_string<char,struct std::char_traits<char>,
class std::allocator<char> > const ,int>'
 No constructor could take the source type, or constructor
 overload resolution was ambiguous

But, really, it shouldn't take a third-party plugin to make reading those easier.

2

C++ as it is already very complex to learn with a lot of subtile pitfalls. Instead of adding a lot of stuff I would prefer effort was made to make C++ more clean and help compiler vendors detect these subtile errors e.g. a la Pc-Lint.

With libraries, well there are quite a few libraries out there and if you program using C++/CLI you have all the .NET stuff as well.

2

I think C++ is pretty much perfect, except for a couple of things that I run into regularly.

  • Overriding methods is really fickle.

Example:

class A {
public:
  virtual int doSomething(int x) { return x; }
};

class B : public A {
public:
  virtual int doSomething(int x) { return 2 * x; }
};

Obviously B::doSomething overrides A::doSomething here. But as soon as you were to change anything to A::doSomething, say change the type of x to double, or add a new argument, B::doSomething no longer overrides it, but adds a new overloaded function instead. The compiler can't warn about this. Sometimes you need to change the signature of a virtual function, and only a project-wide search will help you to update all overrides as well. This could be improved by adding an 'override' keyword (replacing virtual) that indicates you intend to override an existing function: the compiler would generate an error if there is no function to override.

  • If you have multiple constructors, you need to duplicate whatever they're doing in each of them. It would be great if you could somehow call one of the other constructors to delegate the work.

Also, if you descend from an object with multiple constructors, you usually need to repeat all of them. It would be useful if the compiler would define constructors that call to the base object destructor automatically.

Example:

class A {
public:
  A() : _x(0) {}
  A(int x) _x(x) {}
private:
  int _x;
};

class B {
public:
  B() : A() {}
  B(int x) : A(x) {}   // need to repeat all constructors here
  void do() {}   // just to be able to add a function
};
1

I'd like C++ to know that operator + () and operator += () are related to each other, and that if I only supply one it can work out the other for itself.

I'd like auto-generated assignment operators to be strongly exception-safe.

C++ has this to refer to the current object. I'd like there to be a keyword to refer to the current class.

1
try
{}
catch()
{}
finally
{}

Working as in Java. Would have saved some ugly mess in my current project.

1

One other thing that I'd like is an 'inherited' or 'super' keyword like Delphi has. Often when overriding a function you need to call the inherited function. In C++, you need to spell out the name of the ancestor class:

int B::do()
{
  return 2 * A::do();
}

If now, you decide to refactor and introduce a third class C that descends from A, and you let B descend from C, the only way to fix all references to the ancestor is with a project-wide search, replacing e.g. A::do() by C::do(). Instead, you should have been able to do this:

int B::do()
{
  return 2 * super::do();
}

where super automatically refers to B's superclass.

(Of course, I realize that adding keywords is impossible if you want to maintain full compatibility with existing source code.)

1

I want somthing to make maintainability easier.

Scott Myers was working on a templatised version of adding user specified qualifiers to methods (Like const but arbitory user defined qualifiers). Somthing like this added to the language level.

Example:

class X
{
    void doWork() const multiThreadSafe version5 secure;
};

So here the doWork() method is const, multiThreadSafe, version5 and secure qualified. It would be allowed to call other methods that are at least as qualified as itself but not a method that is missing a qualifer without the engineer explicitly casting away a qualifier (like we have const_cast<> now).

It does not add any new features to the language but allows us to add compiler checked invarient qualifers to the code. I think this could make maintainability easier (thoug it would take some getting used too).

1

Most of the things that are in D (http://www.digitalmars.com/d/)

1
  • Keyword arguments.
  • Unify pointers and references.
  • Standard garbage collector.

[Edit]

  • An idiomatic way of creating namespaces, like packages in Python and Java.
1

I'd like a more complete standard library for using synchronous and asynchronous networking/multithreading. There are a pletora of such a libraries (boost, QT, glib) but they are heterogeneous and not so immediately usable. It would be very nice if the core of such libraries will be standardized and built-in in the language.

1
  • Removal of all undefined behaviors.

  • A regular, clean and unambiguous syntax allowing us to:

    • write C++ parsers easily.
    • have proper code analysis and refactoring tools.
    • better compilation times.
  • Allow compilation of templates in an intermediate form so that:

    • they can be delivered within binary libraries.
    • compilation goes faster (C++ is probably the slowest language to compile in the world... err.. universe).
  • Removal of dead features:

    • exception declarations other than throw ()
  • Some ML features such as:

    • sum types: enums on steroids.
    • pattern matching: switch case on steroids.
    • phantom types: const on steroids.
0

A query mechanism for our data structures, like LINQ, would be neat.

0

Proper man pages.

0

Things I would like to see removed:

  • the header / source separation
  • multiple inheritance
  • protected and private inheritance
  • inner functions

Things I would like to see added:

  • have the compiler deduce a class' interface from its object file
  • delegates
  • interfaces instead of multiple inheritance
  • inner classes (Java style, not the current)
  • anonymous inner classes
  • proper exceptions with stack trace
  • mandatory declaration of exceptions
  • a modernized version of stl without all its quirks
0

I'd like a "final" keyword like Java has. There are a few times when I'd like to seal a class so that nobody can come along and do something foolish with it. An example might be preventing an encryption class from being wrapped by a logging superclass.

And reflection would be nice just to make unit test frameworks easier to implement. I wouldn't really have much use for it in production code, though.

Header files could certainly be made obsolete, as they have been in Java and C#. It bugs me to violate the Don't Repeat Yourself principle just to write code. "using" or "#import" or any of the other tricks of the language could solve the problem. Microsoft has achieved something like this with the #import statement to support COM objects. Why not for POCppOs too?

0

A way to specify adapters between classes.
So when huge lib1 has defined a 3dpoint class and huge lib2 has defined a point3d class I don't have to waste time and memory copying a million points from an array of one type to the other before passing them to a function.
Especially when they are actually laid out the same in memory and I could just do a pointer cast in C.

-1

One of the few key features I would really like is the Java capability of taking a piece of code, transport it over the network to a different system and run it there. This is a feature that is almost essential to built systems that are massively scalable (like Hadoop and Gridgain) that support systems entering and leaving the 'Grid' dynamically.