Live data from Hacker News

The Dark Side of C++ [pdf]

miek.nl

21–30 of 33 posts

Re: The Dark Side of C++ [pdf]

#21
I like C++ but I think this article is helpful. Having come up the curve in the last few years, I notice a lot of things I stumbled on are listed... If this were titled "things to watch out for in C++" it could be a useful guide for people. Now, though, I just think "yes, that's right" for many of his points - but it won't stop me from using C++.

Re: The Dark Side of C++ [pdf]

#22

The author points out that auto_ptr is useless. shared_ptr is broken too. What do you think this program does? #include #include #include using namespace std; using namespace std::tr1; class Node; typedef shared_ptr NodePtr; class Node { public: int data; NodePtr next; Node(int data, NodePtr next) : data(data), next(next) {} ~Node(); }; Node::~Node() { /* cout

I don't see the problem. The nodes of the list are freed from beginning to end, and then "Done" is printed. What's supposed to be wrong here?

Stack overflow for large n.

Re: The Dark Side of C++ [pdf]

#23

Earlier quoted context omitted.

I don't see the problem. The nodes of the list are freed from beginning to end, and then "Done" is printed. What's supposed to be wrong here?

Stack overflow for large n.

Ah, I didn't consider that. A decent optimizing compiler should be able to remove all the tail calls (G++ did this with your code and -O2), so this shouldn't be a problem in practice, except maybe for debugging.

Re: The Dark Side of C++ [pdf]

#24
post #11

Earlier quoted context omitted.

"encouraged coding styles of modern and real OOP C++" Where do I go to learn those given that I work in an all C shop? One of the problems of learning C++ is the sheer profusion of material that's available, much of it written when the technology looked a lot shinier than it does now. Would you care to recommend some books or articles on C++ style that have stood the test of more than one fashion-epoch? I'm especiall…

I really do recommend the C++ FAQ book. There is a lite version online: http://www.parashift.com/c++-faq-lite/ Since I've read both the lite online version and the book I strongly encourage you to obtain the book version! rgds, René

In addition I'd recommend the C++ FQA lite (http://yosefk.com/c++fqa/) which dissects the FAQ and provides additional, a lot of times quite useful, information.

Re: The Dark Side of C++ [pdf]

#25
post #11

Most of the problems mentioned there don't apply to the regular C++ coder in his daily life, many of the mentioned problems are even non-existant if you stick to the encouraged coding styles of modern and real OOP C++. In practice just the template error messages suck as hell. I'd really like something nicer there, but in practice you actually survive those messages without too much wasting of time. You just ignore t…

"encouraged coding styles of modern and real OOP C++" Where do I go to learn those given that I work in an all C shop? One of the problems of learning C++ is the sheer profusion of material that's available, much of it written when the technology looked a lot shinier than it does now. Would you care to recommend some books or articles on C++ style that have stood the test of more than one fashion-epoch? I'm especiall…

Are you talking about learning OO to apply in C? Learning modern C++ OO won't help much. A little, but not much. A quick google on "object oriented c" produced a boatload of good-looking sources.

Remember, object orientation is an attribute of a program, not a programming language. A given language may encourage or even force a certain paradigm, but it's still a property of the resulting program. An "object oriented" language is simply a language in which it is difficult or impossible to produce a program that does not have that property. Object-oriented programming in C is perfectly possible, and often quite desirable. It isn't quite as slick but it's not terribly hard.

(That said, NewSoftzzz's suggestion of the C++ FAQ Lite is still a good one. I think it's just plain required reading, personally. Even if you don't program in C++, it will step you through a lot of scenarios in one very popular OO paradigm and simply by understanding one paradigm perfectly, it is easier to understand and use the next. If this seems contradictory to my first paragraph, blame English. This is theoretically helpful, learning C++ won't practically help you much in C.)

Re: The Dark Side of C++ [pdf]

#26
post #24

Earlier quoted context omitted.

I really do recommend the C++ FAQ book. There is a lite version online: http://www.parashift.com/c++-faq-lite/ Since I've read both the lite online version and the book I strongly encourage you to obtain the book version! rgds, René

In addition I'd recommend the C++ FQA lite ( http://yosefk.com/c++fqa/ ) which dissects the FAQ and provides additional, a lot of times quite useful, information.

The C++ FQA is quite the same stuff as the .pdf linked in this topic. So the same stuff about mostly not being practically relevant applies here.

rgds, René

Re: The Dark Side of C++ [pdf]

#27
If you ever write code like template struct Loop { Loop operator->(); }; Loop i, j = i->hooray; at work you are shown by the language that you have probably failed to think before you code. A plus in C++, rather than a downsinde.

If you begin to realize that you need garbage collection you probably failed while choosing the appropriate language for your project or subproblem.

Same thing here: struct a{typedef int foo;};struct a1:a{};struct a2:a{}; #define X(b,a) struct a##1:b##1,b##2{};struct a##2:b##1,b##2{}; X(a,b)X(b,c)X(c,d)X(d,e)X(e,f)X(f,g)X(g,h)X(h,i)X(i,j)X(j,k)X(k,l) X(l,m)X(m,n) n1::foo main(){}

Wich sane person would consider writing this a good idea?

Re: The Dark Side of C++ [pdf]

#28
post #25
post #11

Earlier quoted context omitted.

"encouraged coding styles of modern and real OOP C++" Where do I go to learn those given that I work in an all C shop? One of the problems of learning C++ is the sheer profusion of material that's available, much of it written when the technology looked a lot shinier than it does now. Would you care to recommend some books or articles on C++ style that have stood the test of more than one fashion-epoch? I'm especiall…

Are you talking about learning OO to apply in C ? Learning modern C++ OO won't help much. A little, but not much. A quick google on "object oriented c" produced a boatload of good-looking sources. Remember, object orientation is an attribute of a program , not a programming language . A given language may encourage or even force a certain paradigm, but it's still a property of the resulting program. An "object orient…

No. I've spent far more of my working life puzzling through OO in C to want to inflict it on others. But I've also become a fair to middling C programmer, and the strength I bring to that task has a much to do with knowing how to build large systems in a comprehensible way from the elements the language exposes, as it does to a basic knowledge of those elements. I.e. knowing how to code a case statement isn't the same as building a 50x400 state machine that's efficient, robust and debuggable.

I suspect the same is true of the skills and knowledge held by an experienced C++ hacker.

So I suspect that the C++ FAQ, and the Sutter book are just the ticket.

thanks

c

Re: The Dark Side of C++ [pdf]

#29
post #11

Most of the problems mentioned there don't apply to the regular C++ coder in his daily life, many of the mentioned problems are even non-existant if you stick to the encouraged coding styles of modern and real OOP C++. In practice just the template error messages suck as hell. I'd really like something nicer there, but in practice you actually survive those messages without too much wasting of time. You just ignore t…

"encouraged coding styles of modern and real OOP C++" Where do I go to learn those given that I work in an all C shop? One of the problems of learning C++ is the sheer profusion of material that's available, much of it written when the technology looked a lot shinier than it does now. Would you care to recommend some books or articles on C++ style that have stood the test of more than one fashion-epoch? I'm especiall…

There's no substitute for reading good C++ code, especially larger projects that still manage to be usable, maintainable and somewhat consistent.

For example, the code of LLVM, Ogre, Box2D, bullet and the Second Life viewer, even though they're not always perfect, have all taught me useful things and all look far better than any of the large commercial C++ code bases I cut my teeth on.

Re: The Dark Side of C++ [pdf]

#30
post #15

it's hard to take an article like this seriously - i just want to make 2 highlights. he started using C++ when the STL didn't exist yet. This is ancient IMO, so his section on ever-changing standard is moot to me. if he didn't want to maintain the code base, then he should have kept using an older compiler. second highlight, errors messages - Debugging is the first skill programmers (re)learn, so IMO it's a pretty im…

> To close this, everything he said in his "hard to read" could be applied to any languages with mutability.

Really? I dare you to make Python code as hard to read. It has mutability, too.

Hell, does C code have that same amount of overloading? The worst things C offers are function pointers and preprocessor hijinks* , while C++ proudly adds whole new categories of ways to make code hard to parse or reason about. (To say nothing of compile times.)

I learned C++ before the STL, too. For what the STL accomplishes, I'd rather just use OCaml. C + Lua is also nice - the division emphasizes their strong points, and each seems to keep each others' complexities in check.

* http://www.reddit.com/r/programming/comments/b507c/ask_reddi...

Post reply on HN