|
Thanks for the guidance.
My reply was really intended to challenge Mr. Graus to substantiate some of those statements since, in my humble opinion, he's been throwing some pretty big statements around (lately) about STL but backing them with weak generalizations that amount to nothing useful. Just because STL is "great" does not diminish the proven potential of other technologies in their respective arenas.
The question was in regards to CList and CArray which would suggest the use of MFC in the application. Dropping STL containers into an MFC application defeats the purpose of using MFC in the first place in my opinion and it almost seems irresponsible for someone to suggest it. MFC was built with many presumptions about the application and almost requires the program be written the "MFC way" in order to save anybody any reasonable amount of effort. If you deviate from this course, then you really need to ask yourself why your even using MFC. (You in general, not you)
It sure sounds like STL is the way to go IF you've left MFC behind but I beg to differ when MFC is core to the programmer's code. However, I'm open to reasonable debate (if the claims are substantiated) to enlighten me.
|
|
|
|
|
bob16972 wrote: Dropping STL containers into an MFC application defeats the purpose of using MFC in the first place in my opinion and it almost seems irresponsible for someone to suggest it.
I disagree. MFC is not just about containers is it? I tend to take a "choose an appropriate tool for the job" approach to these things. So I would say use the MFC containers if they're good enough but if you find that a particular problem lends itself well to an STL solution then use it. There's no resaon why if you're using MFC you must use only MFC classes.
Kevin
|
|
|
|
|
Would you suggest using STL over the MFC container classes before you knew which was the best for the job? Would you suggest one over the other if you had no clue what the problem context was? Would you dog one over the other blindly evertime I used the words "CArray" or "CList"?
I would surely hope not. Mr. Graus did just that and I find it irresponsible to blindly slap a library on top of an arbitrary problem potentially misguiding people who are asking for solutions in certain contexts. The thread initiator did not ask about STL. He asked about comparing two MFC classes. We don't even know what problem that person is trying to solve yet. How is that choosing an appropriate tool for the job?
User: "I have a question about CArra..."
Mr. Graus: "You should be using STL. It's great! It's what you should be using anyway because it's *standard*. I have no clue what your code is about but MFC is so yesterday so use STL."
Give me a friggin' break. That's just silly!
-- modified at 15:27 Sunday 6th August, 2006
|
|
|
|
|
bob16972 wrote: Would you suggest using STL over the MFC container classes before you knew which was the best for the job? Would you suggest one over the other if you had no clue what the problem context was?
Now, I probably would tend to go for STL first. However, when I was last doing C++ it would also depend on whether I was writing new code or maintaining existing code. With the latter I tend to adapt to the context of the source code. Even when using STL extensively in an MFC app. I would still use CString because it is (a) more convenient and better adapted for use with MFC and (b) has better functionality than STL string. I think it may also be more efficient.
bob16972 wrote: Would you dog one over the other blindly evertime I used the words "CArray" or "CList"?
No.
bob16972 wrote: I find it irresponsible to blindly slap a library on top of an arbitrary problem potentially misguiding people who are asking for solutions in certain contexts.
Yes, I agree with that. Even if STL containers are superior we don't know what the context is. Is the user maintaining legacy code? Does it already contain a bunch of CArray and CList data structures, etc.?
Kevin
|
|
|
|
|
bob16972 wrote: Would you suggest using STL over the MFC container classes before you knew which was the best for the job?
As a general rule, I would suggest STL all the time, yes. If you're getting some serialisation support from the MFC containers, and if you're confident that you'd rather write code to move items between container types in MFC (if you need to), and to do things like sort and search in your MFC containers, and if you're confident that every C++ program you ever write will use MFC, and you feel that writing a function object for use by 'for each' for serialisation is more work than all of the above, then you should stick with MFC.
bob16972 wrote: Would you dog one over the other blindly evertime I used the words "CArray" or "CList"?
*sigh* As has been said, STL is more powerful than MFC containers, and is *standard*. If you were in an automotive forum, would you suggest a car that ran on gas whenever someone asked for help with their steam driven car ? I reckon you would.
bob16972 wrote: The thread initiator did not ask about STL. He asked about comparing two MFC classes.
Yes, and had that question not already been answered, I would have answered it. Especially given that the question was very beginner in nature, I presumed that on top of wanting to know about the different between a dynamic array and a linked list, it was worthwhile for the person who asked the question to be aware that the MFC containers are obsolete, and lacking in many features that are present in C++ containers.
bob16972 wrote: Give me a friggin' break. That's just silly!
No, what's silly is that so many people use containers that they are going to outgrow, because they don't know any better.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: and you feel that writing a function object for use by 'for each' for serialisation is more work than all of the above, then you should stick with MFC.
You do, of course, realize that many of the MFC containers can be used in almost all of the STL algorithms? In fact, many of the STL algorithms can even operate on something so "archaic" as a C-style array.
Christian Graus wrote: As has been said, STL is more powerful than MFC containers
*ehem* You should clarify: As has been stated by you.
Christian Graus wrote: aware that the MFC containers are obsolete, and lacking in many features that are present in C++ containers.
And what features, exactly, are the MFC containers "missing" that STL containers have. Besides the little used ability to change memory allocators or container traits, that is.
Christian Graus wrote: No, what's silly is that so many people use containers that they are going to outgrow, because they don't know any better.
You use a hammer when you need a hammer; a screwdriver when you need a screwdriver; and the proper collection type for the data you are operating on when you need that.
I'm a big fan of STL, and routinely remind programmers that 90% of the time they shouldn't be writing loops when using STL; however, STL is not superior to MFC in the area of collections, it is different. They were designed for different purposes and each should be used appropriately for those purposes.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
bob16972 wrote: (lately)
I've been advocating the use of STL for a long time now, not just lately. Ask some char * questions, and it's likely that as well as answer you, I'll point out that in C++ we have string classes. IMO, answering questions sometimes means more than answering what is asked, it also means pointing out where there are better alternatives.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
bob16972 wrote: Dropping STL containers into an MFC application defeats the purpose of using MFC in the first place in my opinion and it almost seems irresponsible for someone to suggest it.
I wouldn't go quite that far. I've found myself using STL containers in MFC apps quite frequently. Particularly, when the data I'm storing will need to have algorithms sorting, searching, etc. it. That said, you should try to code consistently. If you start using MFC containers in a class, you should continue to do so unless there is a strong reason not to and vice versa.
STL and MFC do not have to be mutually exclusive, and can work together very well if used together properly (e.g. MFC for GUI code and STL for data operations).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
bob16972 wrote: How exactly does STL integrate better into MFC application than it's own CObject aware containers?
It plainly does not. You'd need to write one or two function objects to replace this part of the MFC containers.
bob16972 wrote: As a novice to STL, I'd love to learn.
While I slept, it became clear that you're trying to bait me, but I'll answer anyhow.
1 - MFC containers are convoluted to access compared to STL.
2 - MFC containers all use different iterators, so to move objects from one type of container to another is a pain
3 - MFC containers do not come with any algorithms such as search, sort, binary_search and random_shuffle
4 - I don't believe that MFC containers have a for_each mechanism that allows to easily write small functions that plug into the containers for reuse of code for common operations
5 - MFC containers were written before STL containers, and were intended to be a stopgap until an STL implimentation became available.
6 - MFC containers are not standard, so if you ever find you're writing a program without MFC, you will be forced to learn STL anyhow.
So, it is better IMO to learn the more powerful and more widely available library, although there's nothing wrong with using MFC containers in the knowledge that you've compared the two options and there are reasons for the choice. In my experience, many people don't even know about STL, and certainly people who ask 'what's the difference between an array and a list' are likely to fall into that category. I use CString all the time, but I would use std::string as a first port of call on my own code, unless I knew that CString did something better.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: So, it is better IMO to learn the more powerful and more widely available library, although there's nothing wrong with using MFC containers in the knowledge that you've compared the two options
I think this is a key factor in software development. Too many people stick with a certain technology on the grounds that they've always done it that way. We should always be prepared to at least consider newer alternatives, even if we decide that in a certain situation we'll stick with legacy technology.
18 months ago I had some of my STL code rejected by my boss on the gorunds that "we don't use STL here." (Which wasn't true, in fact.) Needless to say I was less than impressed. He also wouldn't even use the templated MFC collections.
When STL was fairly new 10 years ago it was reasonable to shy away from its use just for the sake of your fellow developers who may have been unfamiliar with it. But today there's no good reason why it should be rejected. However, I would not object to MFC code using CArray and CList. I would if they were using the older non-templated versions though or if they were using raw arrays over collection classes.
Kevin
|
|
|
|
|
Kevin McFarlane wrote: I would if they were using the older non-templated versions though
I didn't know that such a nightmare even existed....
Yeah, the core problem is people using what they've always used, instead of moving forward.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: They are in every way inferior to STL containers list and vector.
This is a gross mistatement. The MFC containers are FAR from inferior to STL containers. They are different, and designed to serve a different purpose, but that does not make them inferior. In fact, in many ways (e.g. iterating though a collection) they are actually superior to STL containers (although, granted, if you code STL properly, you should be doing very little iterating, but that is another topic altogether).
My point is, do not compare apples to oranges and state that apples are superior. MFC containers were designed to fill the need for flexible containers in Windows (specifically MFC) applications. STL containers were designed to be portable across many platforms.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I did post a lengthy reply, the site lost it. In brief
1 - My understanding has always been that the MFC containers existed because there was no STL at the time, MFC containers do not have any special purpose beyond that. They naturally integrate somewhat with MFC, they are part of it.
2 - MFC containers are in my opinion a real pain to iterate over compared to STL, not least because they follow no standard or pattern. This is worse if you need to copy items between containers.
3 - Yes, even a pointer is a random access iterator. This is one way in which the STL shows sign of intelligent design and the MFC containers do not.
4 - Most people who use MFC containers don't even know the STL exists, or assume they need to use the MFC ones because they were written by MS. That is the sort of ignorance that leads me to tell people to look into the STL.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: My understanding has always been that the MFC containers existed because there was no STL at the time, MFC containers do not have any special purpose beyond that. They naturally integrate somewhat with MFC, they are part of it.
STL "existed" when the MFC containers were designed, but the S part was missing (that is, there wasn't a formalized standard yet (which is why many systems still have the .h versions of the standard header files). They were not designedas a gap filler until STL was formalized; they were designed to provide convinient containers to make MFC programming easier. Hence the reason they have built-in serialization support.
Christian Graus wrote: MFC containers are in my opinion a real pain to iterate over compared to STL, not least because they follow no standard or pattern. This is worse if you need to copy items between containers.
MFC containers use iteration techniques tha follow a logical pattern for the type of a given container. It can be confusing (and a grave, and all to common, mistake) to assume that you can just change the type of a STL container in a "drop-in" fashion. MFC at least makes you think, "Do I really want to change this array container to a list?" I view that as more of a feature than a pain; especially when dealing with newer programmers.
Christian Graus wrote: Yes, even a pointer is a random access iterator. This is one way in which the STL shows sign of intelligent design and the MFC containers do not.
While this is a nice feature for STL, it also makes it more complicated to teach to newer programmers (try explaining why you should use iterators to someone who has been programming for 3 weeks after you just got them to understand pointers).
Christian Graus wrote: Most people who use MFC containers don't even know the STL exists, or assume they need to use the MFC ones because they were written by MS. That is the sort of ignorance that leads me to tell people to look into the STL.
While I don't disagree with that statement (not completely anyway), that is a bold jump from the original question. And the fact remains, use the correct datatype (and correct library) for the task at hand.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
|
-Mohan- wrote: Please briefly explin the difference between the CList and CArray.
The biggest difference is that items in a CArray collection can be accessed directly. For example, to get to the fourth item, there's no need to iterate items 1-3 first.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
hello friends,
I am working with dialog based application,I have created a menu bar for that,Now i want by clicking a menu option like "quote" it will open a another window and from that window function I want to call other function so taht it start display what in that window.How is that possible.
By which function i will do this.
thanks
|
|
|
|
|
if you can catche handle of a window , then you can do any thing
|
|
|
|
|
Thanks for your reply,
How to catche handle of a window so taht i can call all other function from there.So taht window will start display which i am getting from server.
|
|
|
|
|
All you need is have one more modal dialog and then do a DoModal dialog in the menu command handler.
|
|
|
|
|
Thanks for your reply,
Can you pls explain me more.As i am new to CV++ ,so all the concept are not clear to me.
If you need more information then pls.
|
|
|
|
|
See CWnd::GetParent
if Main is Main class you can use this code ion another class
CMain* m_Main=(CMain*)GetParent();
m_Main->functiron or data
|
|
|
|
|
Thanks for reply,
I need to ask my project is dialog based wil these work with that.
If yes what should all other thing/class should i include to make these function work
|
|
|
|
|
Priyanka... Let me know whether you want to create another dialog box from this dialog box?
If yes
Just place this code in the hanlder of that menu item
<br />
CSecondDlg secDlg;<br />
secDlg.Domodal();
if this isn't enough come with your next question.
KIRAN PINJARLA
|
|
|
|
|
no kiran i dont want to create second dialog,
let me expalin you....
I have function which i am calling through dialog box.now i want that by clicking a button it will open a window(which will open untill click to exit) and from that window i will b able to call all other function so that it will start display the data getting from server.
Hope i am clear if not pls remind me
Thanks for your reply
priyanka
-- modified at 1:27 Monday 7th August, 2006
|
|
|
|
|