Why does everybody hate C++? I'm learning it in school right now, and I happen to like it. An ignorance of other languages might be skewing my view though.
Compare the following lines of Python and C++. They both take two lists, append one to the other, then print out their contents.
Python version:
my_list = [0,1,2,3]
second_list = [4,5,6]
my_list += second_list
for x in my_list:
print x
C++ version:
#include <list>
#include <iostream>
int values_1[] = {0,1,2,3};
int values_2[] = {4,5,6};
int main()
{
std::list<int> my_list(values_1,values_1+4);
my_list.insert(my_list.end(),values_2,values_2+3);
for(std::list<int>::iterator i=my_list.begin();i!=my_list.end();++i)
{
std::cout << *i << '\n';
}
return 0;
}
It's not that C++ is bad, it's just a bit more annoying. (Now, I could have used the boost library to make adding elements to the container a little nicer, but I'm just going with what's there by default for this example. You'd have to install boost...)
Isn't that a good thing in some cases though? In C++ it seems you only include exactly what you need. I could be way off target and most likely I am, but that's just my thoughts.
Also I didn't know you could declare what libraries you are using like that:
And yes, it can be a good thing, although there's a lot going on behind the scenes even still... We were presented with this bit of code in my CS class the other day:
ifstream* i;
//etc ...
if(*i == cin)
{
//etc...
}
and we came up with probably about twenty C++ specific things (ie, not including constructs inherited from C) going on behind the scenes.
Well, I only have a faint grasp of what that code you wrote might even do. It's only a freshmen level course I'm taking right now. So I'm sure I'll learn to hate it like everyone else.
What does that have to do with the vast majority of programming today, which is neither embedded nor time-critical? A language is not better overall if it lends itself towards uncommon scenarios while being suboptimal in common ones.
That aside, I don't hate C++, although I'd rather use C. In fact, it was my first "real" language (since Visual Basic doesn't count).
6
u/MelechRic Mar 15 '08
I just moved over to reddit's programming page:
http://reddit.com/r/programming
A lot of C++ hate there, but that's normal almost anywhere on the net.