Linked by David Adams on Sat 11th Oct 2008 16:48 UTC, submitted by IndigoJo
General Development Eric Raymond is working on an essay, putatively titled "Why C++ Is Not My Favorite Programming Language". In his announcement, he calls it "an overcomplexity generator", "bloated, obfuscated, unwieldy, rigid, and brittle", and alleges that these characteristics appear in C++ applications also. I contend that many of the complaints about C++ are petty or are aimed at specific libraries or poor documentation and that many of the features commonly regarded as unnecessary (and excluded from intended replacements) are, in fact, highly useful. C++: the Ugly Useful Programming Language
Thread beginning with comment 333423
To view parent comment, click here.
To read all comments associated with this story, please click here.
pcunite
Member since:
2008-08-26

C++ is a systems language that you can pretty much build anything. It allows for both object orientated programming as well as the needed procedural style programming. It's beauty (if used properly but not always done however) is to procedurally use objects.

Consider the code sample below and tell me this is not very simple:






********************************
class Paper
{
private:
std::string Color;
std::string Text;

public:
Paper();
~Paper();

// Getters
std::string GetColor(void);
std::string GetText(void);

// Setters
void SetColor(std::string Color);
void SetText(std::string Text);
};

// Create some blank paper. Everthing is free inside the computer!
Paper1 Paper;
Paper2 Paper;

// Set some info about each piece
Paper1.SetColor("White");
Paper1.SetText("Buy some eggs and Milk\nDon't forget the cheese!\n");

Paper2.SetColor("Green");
Paper2.SetText("You may have already won one Million Dollars!\n");

// Create a container to hold paper and put some paper in it.
std::vector<Paper> MyTrashCan;
MyTrashCan.push_back(Paper1);
MyTrashCan.push_back(Paper2);

// See what is in the Trash can. Thus:
for (size_t i = 0; i < MyTrashCan.size(); i++)
{
//Print out to the screen or over a TCP connection
std::cout << MyTrashCan[i].GetColor();
std::cout << MyTrashCan[i].GetText();
}

********************************

Reply Parent Score: 2

sergio Member since:
2005-07-06


// Create some blank paper. Everthing is free inside the computer!
Paper1 Paper;
Paper2 Paper;


Mmmm... compile time error. The right way would be:

Paper Paper1;
Paper Paper2;

BTW, I don't like C++ syntax at all... It's verbose like Java and ugly like Perl. The worst of two worlds. ;)

Reply Parent Score: 2

luzr Member since:
2005-11-20

Problems will start if there is anything else than single Color and Text attributes. What about:


class Paper
{
private:
std::vector<std::string> Text;
};


and the existing code will still work, but will be much slower than Java.

But that is not a problem of C++ core language, but STL...

Reply Parent Score: 1

pcunite Member since:
2008-08-26

What about:
std::vector<std::string> Text;


Yes that would allow for multiple Text types quite simply. Gains in STL will help performance. Of course one could use their own custom vector class. I show this to illustrate how easy C++ is. I use a similar class design to handle a complex object that has many forms of recursiveness in it. Using SQLite, and Borland's VCL has made programming the windows platform child's play. I plan to replace the VCL with QT or wxWidgets at a later date if needed.

Reply Parent Score: 2

StaubSaugerNZ Member since:
2007-07-13


//Print out to the screen or over a TCP connection


Your line above shows the flaw in C++. How do you get the TCP connection? While one could argue the the C++ language is ok what it's missing out on are standardised cross-platform libraries for things outside of data structures.

Libraries is the strength of Java (and .NET somewhat, if all you care about is the desktop on x86 architectures).

Ok, so maybe you don't need sockets, so where are the standardised cross-platform C++ guis (that don't need precompilers or macro magic). Or how about threading? When multiple threads own your Paper class who is responsible for cleaning it up? Where is the standard way of documenting the class for maintenance programmers new to the system? (sure doxygen is great, but it ain't standard on C++ projects).

Despite the power of C++ as a language it is weak in areas such as legibility, cross-platform standard libraries, and thread-safe programs that can be maintained by mortals (not just the 'elite' that visit sites like this). This is why C++ has been marginalised by Java and the much-simpler C (still used for systems programming).

Here are the statistics:
http://www.langpop.com/
http://www.tiobe.com/index.php/content/paperinfo/tpci/

Sure C++ and C# are used (and admittedly are the right fit for some projects), but not as heavily as many fanboi would like you to think.

Reply Parent Score: 3

pcunite Member since:
2008-08-26

Despite the power of C++ as a language it is weak in areas such as legibility, cross-platform standard libraries, and thread-safe programs that can be maintained by mortals (not just the 'elite' that visit sites like this). This is why C++ has been marginalized by Java and the much-simpler C (still used for systems programming).


You raise valid concerns for someone who is not using C++ day in and day out. So let me shortly address them.

* Legibility: Use only the STL and the below libraries in a procedural style way interacting with your objects/classes.

* Cross-platform standard libraries: Poco C++, Boost, SQLite, wxWidgets are very free and very commercial quality. QT is very solid as well.

* Thread-safe programs that can be maintained by mortals: This is hard in any language. The latest version of Boost is moving toward making this easier. The early years of getting our heads around Object Design was hard. Until we fully understand threading it will be hard. Don't fret because C++ will be the first to fully utilize and set the pattern for other languages in this area.

I understand the mental handicap of learning something new or just plain not liking something. But modern C++ programming from scratch (avoiding any C style thinking) is very easy to read, maintain, develop, and obtain performance to create simple or demanding applications with.

I don't wish to convert anyone only to say that it is very nice sipping the cool glass of lemonade that is C++ nowadays so don't feel sorry for us. 10 years ago... yes... maintaining someone else poor C++ style... yes that is a lot of work but not anymore with modern styles.

Edited 2008-10-13 02:30 UTC

Reply Parent Score: 2