154 points · by mhp · 15y ago · 104 comments
I'll be the first to point out the numerous flaws C++ has but it just feels like folly to make fun of the ugly chick at the party without realizing everyone at the party is covered in warts... (The is a metaphor for all programming languages having problems)
C++ has problems unique to C++: a deceptive illusion of abstraction (what Spolsky would call "leaky" abstractions) makes a bunch of idioms in the language dangerous, including virtually all "smart" pointers, iterators, exceptions, allocators, and arrays. It is uniquely difficult to write reliable code in C++.
Add to that the superficial but more practical and common complaints against C++: the ghastly compile times, the header file dependency hell that forces every class into a kabuki dance of "pImpls" and nested classes, the error messages rendered in ancient Sumerian... you know I could go on, but you get the idea.
C++ is just not a very good language. C is a fine language. If you are building a system for which C's abstractions are inadequate --- and I'll stipulate that such systems exist --- you're better off with C and a very good glue language (Lisp and Lua are two good, popular choices) than you are with a uniform C++ implementation.
This is the attitude that I really, truly do not get.
If I want a linked list or any other common data structure in C++, I include the appropriate STL header and declare an object with the template syntax. It's two easy lines of code. If I want a data structure in C, I have to write it myself. From scratch. Every time.
C++ is a powerful high-level language. C is a low-level language where everything is explicit; I know this is "elegant" to many programmers, but really, I'm just trying to get things done, and C++ has served me far better in that practical role than C ever could.
I don't love C++; it has tons of flaws (many of which disappear if you use shared_ptr for everything). But I loathe the tedium of working in C.
If I want a linked list in Python, I do:
frobs = ['foo', 'bar', 'baz'].
The equivalent C++ is: vector<string> frobs;
frobs.push_back("foo");
frobs.push_back("bar");
frobs.push_back("baz");
The reason people like these multi-language solutions is that Python or Lua is much, much more productive than C++ (as in, many times more productive), and yet the most programs have only a very small core that needs to run fast. You can write that small core in heavily-optimized C, making it quite a bit faster than kludged-together C++, and then write everything else in Python. And the total complexity of the system is still much less than if you'd just used C++ to start.The fact that C is not great for GUI apps does not diminish C's quality for what it is, it's just not designed for that level of abstraction.
C++ on the other hand, attempts to be designed for that level of abstraction, and so in fact you are better off writing most types of modern apps in C++ than C in absolute terms, but when compared against other languages designed for the same paradigm it falls down due to complexity overload. That doesn't mean you can't do great work in C++, but you have to really know what you're doing, which parts to avoid, etc. C++'s strength is being both fast and powerful, but most of the time you don't really need both those qualities. Game programming is a notable exception.
It is flat-out not true that you need to write data structures in C each time you use them. The programmers that do this are, in my limited experience, uniformly bad. I wouldn't even write a linked-list for fear of screwing up a corner case on deletion. There are libraries for everything, and they're plenty fast. They're just less pretty looking.
http://library.gnome.org/devel/glib/2.28/ makes C development much more pleasant. You could make the same argument against C++ if you didn't have STL.
Almost every type of operation in C is predisposed to HUMAN error (the worst kind of error) - I/O, strings, creating a data structure, declaring a variable, calling a function even basic maths can fail in unintuitive ways. [1]
No matter how many glue languages you use, C is not going to become safer or easier to use. Furthermore, C's abstractions are inadequate for most things, even the things that it's traditionally known for,such as the Linux kernel. Take a look and see how many wheels have had to be reinvented for the kernel or any large C project.
But... you probably already know all of this. It's just that you're so comfortable with it that you're willing to forgive all of its sins.
[1] https://www.securecoding.cert.org/confluence/display/seccode...
http://yosefk.com/c++fqa/faq.html
Subjectively I don't feel HN as particularly anti-C++, it's more that people are younger and started programming in languages like Python and Ruby so they don't have a pro-C++ bias. If anything I feel that many people on HN are anti-Java. Personally I'm thankful for Java's existence because it managed to replace C++ in a lot of places.
I wrote a web server in C from first principles back in 2001* for many of the same reasons that OKCupid seem to have done - and with a team of one good programmer that worked out really well.
* http://web.archive.org/web/20070705191513/http://www.annexia...
It takes way to long to learn (probably 2 years for a developer working with it 8 hours a day), and the grown ups don't like it either: http://www.amazon.com/Coders-Work-Reflections-Craft-Programm...
This isn't even an ugly chick.
If you are an expert in the intricacies of C++, please
consider this knowledge a kind of martial art - something
a real master never uses.
http://yosefk.com/c++fqa/why.htmlThis is why I read HN.
Rather than "Microsoft ruined everything", nearly the entire commercial software industry standardized on C++, and entry-level "coderbots" was who they wanted to hire out of school.
C++ lost its sex-appeal because its simply more interesting to do web startup things than to be a junior coder at Big Software Inc.
And the answer highlights why you should never retrospectively "judge" design choices several years after the fact.
But, these guys are really fucking brilliant and productive. Immensely... I feel like a chump in comparison.
There are a variety of reasons why startup founders may want to bend the truth with their public statements.
See the two responses for details.
Even though all sites have bugs, broken links, what have you, I don't know any other site that's given me such an expectation that it will be unresponsive for a significant number of page views for any given session over a long term period. Even the sites that started development circa 2003.
With landline connections OKC works very well :-)
I don't think I've ever seen OkCupid down completely, not that I use it nearly as often as reddit. But I've never seen reddit have the behavior that while it's up, I can expect one of every 5-20 page views or posts to time out or fail on the first load/submit but succeed on the second or third. And this is consistent enough with OKCupid that I think about a usage session as something I'll have to be in the mood to fight with.
I know people who have used OKC before. OKC users in my social class (male, white, educated) ignore the match percentages, because the SNR is really low. They just plow through all the search results of people to find good pictures and interesting profiles.
So, I'd speculate that match-percentages are a marketing thing, and that they know they made a weak business decision which required lots of computation and now they're stuck with it.
I'm probably wrong. Maybe the long-tale users pay attention to match-percentage.
We're still together, five years later.
I'm probably an outlier, but hey--match percentage works some of the time!
(I wrote some C++ webapps myself)
A) You still have to worry about it when interfacing with libraries that use plain pointers
B) Shared pointers incur runtime penalties (larger data pushes things off the cache, spurious inc/dec-refs messing said cache. If you don't care about that, why do you use a language like C++ in the first place?
C) Reference counting is a poor form of automatic memory management, you still have to worry about cycles, and use weak references or such to break the cycles.
(Disclaimer: I interviewed @ OKCupid in 2007)
OKWS is less a web server than it is an architecture of servers. It's the difference between sendmail and qmail/postfix.
It has nice security and performance properties because each service is run as a separate user, with a separate process. Logging is handled by an independent daemon. Request demultiplexing is handled by a simple daemon that binds to port 80. Actual HTTP parsing is handled by a shared library that services link to.
[1] http://www.reddit.com/r/programming/comments/exkk3/ok_webser... [2] http://pdos.csail.mit.edu/~max/docs/okws.pdf
One of the biggest problem C++ has is the fact that core language has too many stuff but still lacking things that people really want to use. It's certainly workable, and the results are fast since it is compiled very well. However 'workable' does not mean 'a pleasure to work'.
[1]: http://www.okws.org/doku.php?id=sfslite:tame2:tutorial , http://www.okws.org/doku.php?id=sfslite
Hiring and training is also probably more difficult, though that has got be a huge boon to OKCupid engineers since Match cannot afford to lose them.