|
|
| [C++] I'm Famous! |
|
ImLeftFooted
Member #3,935
October 2003
|
Or at least, I posted in the same thread as Bjarne Stroustrup*! The thread is about an addition to C++ named "move semantics." Its wonderful to hear someone so intelligent defend silly dogmatic attacks on the language. Here is the thread. Has anyone else heard of move semantics and / or have an opinion on them? * For those unfamiliar, Stroustrup is the father of C++ |
|
axilmar
Member #1,204
April 2001
|
If you think you are famous, then what can I say? I'm the guy with the silly dogmatic attacks, as you call it, which are neither silly nor dogmatic. I am a professional C++ programmer for 10 years now. I can't tell you how much time is spent in dealing with memory management in C++. Writing big and complex applications in C++ is a very difficult, time-consuming, mind-boggling, temper-stretching tasks in the programming field. If you ask why don't I move to another language, I'll answer that it's not my choice. I program in whatever tools I am given. It's not my decision. If you want a debate on C++, then please use informed and educated arguments, not 'people don't like it' replies like Stroustrup. The only reason the C++ committee has not made garbage collection the top priority item in their list is because they are dogmatic. They think that memory should be managed manually, without ever giving any persuasive argument on why it should be so. They say that C++ is used in embedded systems that can't have GC. Ok, I say 'make it optional'. There are plenty of ways to do that. They say that C++ is a system's programming language. Fine, I don't see anything that prevents C++ from having a garbage collection. Boehm's collector works, it just need some type information help to make it efficient, and it's only the compilers that can do that. I really don't see any argument that can hold against having optional garbage collection in C++. What I see is a big list of very big and complex applications that have great problems with wild pointers and buffer overflows and occasionally crash, and they all have been made with C++. This rant should not be thought of as inflammatory or anything like that. It's just an informed post about the state of programming and the C++ programming language. I see many flaws in it, and I would like to see them corrected. It affects my everyday life, and of course the lives of many other people, since a memory error can have multiple consequences in many levels, including people being fired for not managing complex projects adequately (yeap, I've seen that in my career as well). |
|
le_y_mistar
Member #8,251
January 2007
|
Quote: April 2001 I am a professional C++ programmer for 10 years now blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah you need to go outside more often ----------------- |
|
Thomas Harte
Member #33
April 2000
|
Quote: you need to go outside more often Yeah — if you're inside for long enough to come up with one full paragraph of opinions every 365 days, then obviously there's something wrong with you. Sadly I'm completely clueless as to anything higher level than classes in C++ and really just use it as C with more flexible scope. So I have no opinion as to the real substance of this conversation. But, ummmm... didn't you think you were famous whenever you last appeared in a thread here with Matt Smith? There's an entire school of platform games that probably wouldn't have existed but for him. [My site] [Tetrominoes] |
|
james_lohr
Member #1,947
February 2002
|
Didn't we just recently have a gc in C++ thread? Based on what you've said so far in this thread, I'm inclined to agree with Stroustrup before even reading what he has to say.
|
|
Slartibartfast
Member #8,789
June 2007
|
I'm with Thomas Harte :S ---- |
|
spellcaster
Member #1,493
September 2001
|
Ând I am having some kind of deja vu. -- |
|
axilmar
Member #1,204
April 2001
|
le_y_mistar said: you need to go outside more often Do you think that I care too much about C++ and I should care less? is that what you mean by saying that? Well, C++ has give me and many other people enough headaches. Unlike others, I care, and I want to see the situation improved. James Lohr said: Based on what you've said so far in this thread, I'm inclined to agree with Stroustrup before even reading what he has to say I understand that. Everyone says that, actually. No one examines the actual arguments. I am mr Nobody, while Stroustrup is famous, has appeared numerous times in famous web sites and other media and has written books on the subject. So I must be wrong. Well, somebody really famous said: Quote: All truth goes through three steps: First, it is ridiculed. Second, it is violently opposed. Finally, it is accepted as self-evident. My opinion that C++ should have garbage collection has already been ridiculed in numerous sites. Right now it is violently opposed. But I don't give up. The 3rd step is close! :-) |
|
ixilom
Member #7,167
April 2006
|
And I'm having a coca cola. What are we talking about here? Pushing for a gc to be built into the C++ language or letting it be an (external, like boehm's) option, as it is today? Trying to argue why C++ should be forced a gc is just plain stupid. Personally, I don't want a GC built in or as an option, I don't need one. ___________________________________________ |
|
axilmar
Member #1,204
April 2001
|
ixilom said: What are we talking about here? We are talking about C++ having optional garbage collection. ixilom said: letting it be an (external, like boehm's) option, as it is today? It's very difficult to use Boehm's gc with C++. It requires many hacks. There are STL issues, linking issues, DLL issues, initialization issues etc. I've tried it, that's why I know. ixilom said:
Trying to argue why C++ should be forced a gc is just plain stupid. But that's why I say it should be optional. ixilom said: Personally, I don't want a GC built in or as an option, I don't need one. I respect that, but I need it. I hope you can understand that different people may have different needs. |
|
Slartibartfast
Member #8,789
June 2007
|
From the thread you linked: Bjarne Stroustrup said: C++ will get GC.
So what is the argument about? ---- |
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote:
So what is the argument about? I'm not sure anyone really knows, as the original thread is about rvalue and move semantics, not Garbage collection. -- |
|
Indeterminatus
Member #737
November 2000
|
Stop the vanity, please. _______________________________ |
|
ixilom
Member #7,167
April 2006
|
axilmar said: But that's why I say it should be optional. Agreed. But you are still advocating that the C++ committee should take this as their priority task and I can't understand why. axilmar said: I respect that, but I need it. I hope you can understand that different people may have different needs. I appreciate that. And of course I understand that different people have different needs. [edit] ___________________________________________ |
|
axilmar
Member #1,204
April 2001
|
Quote:
From the thread you linked: The argument is that "C++ needs garbage collection vs C++ does not need garbage collection". Until the C++ standards committee announces a C++ version and a release date with GC, I will not believe it. Stroustrup did not convince me that he wants GC in C++. He just says that so as that he does not look very outdated. If he really wanted GC, he would have pushed to it, and he would have strong arguments that would have persuaded the rest of the committee by now. Quote: I'm not sure anyone really knows, as the original thread is about rvalue and move semantics, not Garbage collection. Move semantics and rvalues exist solely because C++ lacks garbage collection. Let me explain with easy steps on how the need for move semantics and rvalues was created: 1) C++ is a value-based language. 2) returning a value from a function creates a copy of the returned value. 3) copying is cheap when data can be held in registers. 4) copying is expensive when data can be not held in registers. 5) a solution for the problem of the expensive copying is to move the data. Moving is much cheaper than copying. 6) In order to statically recognize a copy operation from a move operation, the language needs new syntax. RValues are born. So the whole problem, right from the start, is the excessive copying. And the perfect solution is garbage collection! with GC, two value instances can share the same heap block without any special tricks. With move semantics, you get: 1) new syntax for rvalues. Programmers need to update their knowledge. 2) a whole series of tools need to be updated (compilers, IDEs, etc). 3) responsibility transfer: the fiasco of auto_ptr. It's no coincidence that nobody uses it. 4) reduntant memory accesses: move semantics means to swap pointers or copy and set pointers. With GC, you get: 1) no changes in syntax, even if the GC is optional. The compiler could use a special template wrapper class to wrap GC'd types, for example gc<T>, gc<T *>. 2) changes in the compiler, but no changes for the tools. 3) no auto_ptr fiasco. With GC, data sharing is as easy as copying a pointer. 4) no extra memory accesses: moving a memory block is no longer required, since sharing (i.e. copying a pointer) is more than enough. GC also eliminates the need for shared pointers and reference counting, with many advantages: 1) no need to write shared_ptr<T> all the time. 2) no need to include <shared_ptr>. 3) no danger from unwrapping a shared ptr (by calling shared_ptr.get()) and then wrapping it up in another shared ptr, creating two reference counts. 4) avoiding atomically incrementing/decrementing a reference count, which is an expensive operation. 5) avoiding reference count allocations. In TR1::shared_ptr (which is boost::shared_ptr), ref counts are allocated on the heap (that's how it is possible to share the reference counts between shared ptrs). Garbage collection has numerous advantages over manual memory management. It simplifies the language, it simplifies coding, and you don't have to bang your head against the wall with wild pointers or illegal delete operations on already deleted objects. EDIT: Quote: As if this was the first time on a.cc threads go nutty? Why is it nutty to discuss a change in something? I don't get it. |
|
ixilom
Member #7,167
April 2006
|
axilmar said: Why is it nutty to discuss a change in something? I don't get it.
I guess it depends on how you interpret the OP. Although with the rant and links, I guess GC is right on topic, in a way ___________________________________________ |
|
nonnus29
Member #2,606
August 2002
|
OMG!!!! Spellcaster!!! Deja vu? Hey, you didn't have to read this particular thread! I think axilmar has a much different experience and perspective than any of us do. How many of us have worked on really large C++ applications? I haven't. So on that basis alone I think his opinions should be heard. He also knows what he's talking about and I learn a lot from reading his posts, so be nice. |
|
ixilom
Member #7,167
April 2006
|
I don't doubt axilmar's experience and/or knowledge, but I still think that those who want to use CG with C++ should make one themselves or use whatever is available and not try to push it into a standard. Better yet, use C#, Java or whatever has a GC to begin with. Size of project IMHO doesn't matter when it comes to handling memory. It's basically the same all the way anyway. Unless of course you need to do some dynamic magic because of heavy usage of RAM memory. ps. I am being nice, always ___________________________________________ |
|
james_lohr
Member #1,947
February 2002
|
Quote: How many of us have worked on really large C++ applications? I haven't. So on that basis alone I think his opinions should be heard. That's true, and all of what he says makes sense. It's just that I don't agree with giving C++ gc. I'm not qualified to say much on the subject, but I don't see how GC can ever be implemented without a performance hit (although you've spoken about optimal GC so maybe I'm wrong). My personal experience of C++ was that it's total cack for general purpose programming compared to modern languages like C#, and if I really cared so much about performance, I'd just do it in C. For a large project that really needs performance for some bits, it would be safer to do most of it in C# and then interface a C dll for the performance parts than trying to do it all in C++. In the cases where there is a choice, I think it'd almost always be beneficial to avoid the monster that is C++. But I suppose for some people who have known nothing but C++, such additions as rvalues are like exciting new trinkets to fiddle with.
|
|
Matthew Leverton
Supreme Loser
January 1999
|
If C++ were the only programming language available to me, I'd be off playing golf somewhere. It seems to me that C++ is more and more becoming a language for elite language nerds. From the article: template <class T, class A1> std::shared_ptr<T> factory(A1&& a1) { return std::shared_ptr<T>(new T(std::forward<A1>(a1))); } I'm sure to a veteran the above code makes sense, but I look at it and think "Is this really what programming has come to?" Why two ampersands? Because one was already taken. So the next semi-related feature gets 3. Brilliant. I don't care enough to be as nearly informed on the topic as, say axilmar, so my opinion really isn't worth anything from a technical perspective, but it appears that he wants to address the root of the problem as opposed to addressing a symptom with some more obscure syntax. (Which is good.) It's the classic programmer's excuse. When asked why something doesn't work well or is too complicated, you get some technical excuse instead of "it's not designed properly." Give me a circle, and I'll shove this square through. The thing that perplexes me is how anybody can defend the C++ language. At a surface level, it would appear that something like D provides basically the same features at a fraction of the syntax. Then you have "VM" languages like C# that are almost beautiful to work with. What can you do in C++ that you cannot in the others? I'm talking about results; not nerdy little coding tricks. The more features that C++ gets, the fewer people that will understand it, and the fewer people who will use it. It means you'll be able to make a lot of money in 10 years supporting legacy C++ applications, but all new development will be in other languages. |
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Optional garbage collection sounds just fine to me as long as I can continue using new and delete without some strange new convention. It's really never bothered me to allocate my own memory when necessary or appropriate as it's fairly easy to put new in constructors and copy constructors or initializers , delete in cleanup or destructors , and both in assignment operators. Of course I forget here and there but that's what testing is for. Personally I've never had the need for garbage collection. Perhaps someone can clarify this for me , but when do most garbage collectors actually free memory? When there are no more pointers to it? Also , if this rvalue debate is about minimizing unnecessary object creation then why not just use plain object references? No need to copy an object when you have a reference to it. Also , what would an rvalue reference be doing that it would need to be qualified with two ampersands instead of just allowing rvalues to be referenced in the first place? Currently you can't use an rvalue as a reference :
I'm also somewhat confused by what they mean when they say move and forward operations. Are they talking about assignment operations or transferral of pointer ownership or what? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|
Carrus85
Member #2,633
August 2002
|
Quote: when do most garbage collectors actually free memory? When there are no more pointers to it? Depends on the garbage collector. Some will free it immediately when no one else is using it, some periodically, some progressively in the background, some all at once only when memory is exhausted, etc. It is completely dependent on implementation (which can be argued as a potential downside, since you now have more nondeterministic run times than usual; of course, if it is configurable, or well documented, it usually isn't a problem.) Quote: It's really never bothered me to allocate my own memory when necessary or appropriate as it's fairly easy to put new in constructors and copy constructors or initializers , delete in cleanup or destructors , and both in assignment operators. The major benefit of garbage collectors is that you can have lazy destruction of objects (both memory and anything else; which is both an advantage and a disadvantage for different resources). You don't have to keep track of everyone holding on to the pointer of an object; the garbage collector does this for you. This removes the need for shared pointers, for example. While it's true GC's do promote some degree of laziness (e.g. data structures that simply let objects fall to the GC instead of explicitly cleaning up after itself), it makes life much, much easier. And if the GC is good enough to not be completely obnoxious about when/how/why it frees memory, it is essentially a non-issue for all but the most performance critical sections. Of course, depending on the garbage collection scheme, RAII is kinda b0rked when you have a non-deterministic destruction time. Garbage collectors fix problems with memory resource leaks, but cause problems elsewhere. It's all fine and dandy that you can't leak memory, but if you can still leak open file handles, network sockets, locks, etc. the problem becomes somewhat more complicated. But provided both are possible (RAII to perform automatic cleanups, and a really nice GC), it can make a lot of programs much, much easier to code.
|
|
BAF
Member #2,981
December 2002
|
C++ sucks and so does Bjarne. That doesn't make you famous. |
|
ImLeftFooted
Member #3,935
October 2003
|
axilmar said: Move semantics and rvalues exist solely because C++ lacks garbage collection. Move semantics are great whether you're using a GC or not. axilmar said: I can't tell you how much time is spent in dealing with memory management in C++. Writing big and complex applications in C++ is a very difficult, time-consuming, mind-boggling, temper-stretching tasks in the programming field. This blanket statement is false. What you should say is: axilmar, adjusted, said: I can't tell you how much time I spend dealing with memory management in C++. When I write big and complex applications in C++ I find it very difficult, time-consuming, mind-boggling, and temper-stretching. To say the industry shares your stance is silly. It only takes 1 person in the industry to disagree with you and the statement is false. Not only do I disagree with you, the vast majority of #C++ on freenode also disagree. axilmar said: So the whole problem, right from the start, is the excessive copying. And the perfect solution is garbage collection! with GC, two value instances can share the same heap block without any special tricks. Let me get this straight... Your solution to the same problem is to double your memory footprint? I fail to see this as a solution... are you sure you understand what move semantics really fixes? Matthew said: I'm sure to a veteran the above code makes sense, but I look at it and think "Is this really what programming has come to?" Bjarne himself said the code was not meant for the publics' eyes. The code you referenced is designed to illustrate the need in a way veteran C++ coders could easily see. These code chunks are needed to convince the committee to approve changes. It was not designed as a model of C++ to non-C++ coders... Try to give it the benefit of the doubt. Matthew said: Why two ampersands? It's the most logical syntax I can think of... its fitting given its similarity to references. axilmar said: If he really wanted GC, he would have pushed to it, and he would have strong arguments that would have persuaded the rest of the committee by now. Bjarne is not the kind of man to pick an agenda and make up strong arguments for it. He is the kind of man who finds strong arguments and creates an agenda around them. Thats what makes and keeps C++ so great. |
|
Paul whoknows
Member #5,081
September 2004
|
[off topic] Am I the only insane one who enjoys programming in C/C++ ? C/C++ programming languages are an almost perfect combination. You can use them almost in every plataform: from PCs to microcontrollers, almost every hardware has its own C/C++ compiler. So trying to improve this(C++) wonderful language makes a lot of sense to me. I won't talk about performance, portability, or syntax. And yes! as we already know, C++ is not an easy subject to master, just like calculus, algebra, physics or any other stuff. Paul Whoknows. A happy user(and humble defender:-*) of the C/C++ languages. [/off topic] ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
|
|
|