Jump to content
  • Advertisement
Sign in to follow this  
doho

STL and newbies

This topic is 4775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If you come to this thread from the Lounge, be warned that this is a For Beginners thread (the fact that it is stickied in the Lounge is, in my eyes, a bug). As such the For Beginner forum rules apply, not the Lounge's. -- Fruny
I have seen a lot of threads on these forums where STL is suggested for newbies to use. Nothing wrong with that but I sometimes see threads where a newbie is trying to implement a linked list with responses in the line of: "use std::vector, it will solve all your problems...". But hey, that kind of response wasn't even what the newbie was asking for. Of course it could be nice to point out the STL alternative, but the newbie probably just wanted some help with his linked list implementation. My personal view is that newbies only should start using STL when they are familiar enough with standard C. Otherwise they will be trapped later when they are forced to deal with the advanced C++ parts of STL. And if they just want to learn to program more high-level, I think they would be much better off choosing another language than C/C++. I once started using STL without a good understanding of C, and it didn't take long before I was stuck in the corner with some difficult to read (probably template related) compiler error. Am I the only one with this experience or did someone actually manage to start using STL before having a firm understanding of C? Does anyone agree/disagree when I say that STL is being too easily suggested for newbies in these forums? Let your opinions flow. [Edited by - Washu on March 27, 2005 12:36:41 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by doho
My personal view is that newbies only should start using STL when they are familiar enough with standard C. Otherwise they will be trapped later when they are forced to deal with the advanced C++ parts of STL. And if they just want to learn to program more high-level, I think they would be much better off choosing another language than C/C++.
I strongly disagree.

I've articulated my thoughts on the way computer science is taught in universities, and unfortunately many opinions on the internet are direct products of what I see as a flawed system. What is at core here is that you are provided with a standard (ie, consistently available for all users of your language) set of data structures that have been continually optimized over the past seven years. If you know what a data structure is and what its invariants are, you should have no problem using it. Reimplementation of common data structures should only be done as an exercise in a Data Structures course (or the equivalent hobbyist/independent experience), not as a necessary part of developing a larger system.

The problems you had were not due to the data structures in the standard library, but due to incomplete understanding of the language, specifically the template system in C++. Skirting that and writing your own data structures is not addressing your core problem, and is, again, symptomatic of my analysis of the flaws in the prevalent learning approaches. (You can read my journal entry for more detail on the subject.)

Consider this, though: stream I/O is implemented in C++ via templates, so if you're going to be consistent about avoiding templates as a beginner, you won't be able to do anything. I think we need a greater emphasis on use and reuse of existing code, including language standard libraries.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by doho
My personal view is that newbies only should start using STL when they are familiar enough with standard C. Otherwise they will be trapped later when they are forced to deal with the advanced C++ parts of STL. And if they just want to learn to program more high-level, I think they would be much better off choosing another language than C/C++.


Reimplementation of common data structures should only be done as an exercise in a Data Structures course (or the equivalent hobbyist/independent experience), not as a necessary part of developing a larger system.
I completely agree, but what I was trying to say is that most of the cases when STL is mentioned here has to do with just the hobbyist/independent experience.

Quote:
Original post by Oluseyi
The problems you had were not due to the data structures in the standard library, but due to incomplete understanding of the language, specifically the template system in C++. Skirting that and writing your own data structures is not addressing your core problem, and is, again, symptomatic of my analysis of the flaws in the prevalent learning approaches. (You can read my journal entry for more detail on the subject.)

I agree that when learning something complicated, one is usually better of looking at the big picture first instead of digging deep into details and that software reuse defenitely is a good thing. It is just that I had the experience of STL shooting me in the foot as soon as I wanted to do something more advanced.

Share this post


Link to post
Share on other sites
C++ is not a beginner language. That is, it is not targeted at beginners, nor does it have features that make it particularly well-suited to beginners, so when used by a beginner there are a lot of risks that come with it. But that is all beside the point.

The point is that you had the problems you did because you were learning about process rather than architecture. Process tells you how to do something; architecture tells you how to take a bunch of processes and put them together to do something much bigger, to do a gestaltian combination of things. If you had had access to a resource on "How to Use the Standard C++ Library Effectively for Beginners," you wouldn't have had the problem. Such a resource would have given sample scenarios that require integrating multiple components from the library, complete problem specifications and algorithmic solutions, descriptions of each component's properties and how they come together to effect the solutions, and illustrative code excerpts that the reader needs to complete on his/her own to run.

The problem is not the Standard C++ Library ("STL" is a deprecated name). The problem is not beginners. The problem is "experts" (because most who create beginner resources are actually only intermediate and of middling competence, otherwise they would be imparting their knowledge to advanced users) and the ways in which they seek to impart their knowledge to beginners.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
C++ is not a beginner language. That is, it is not targeted at beginners, nor does it have features that make it particularly well-suited to beginners, so when used by a beginner there are a lot of risks that come with it. But that is all beside the point.

This is actually exactly the point I was trying to make! When a question is asked about copying a string or something other in the line of this, it is safe to assume that questioner is a beginner. And as you say, C++ is not a beginner language and as such I don't see why the "experts" are calling advanced C++ features out loud as some cure to everything.

I am just trying to fight the right for the pitty beginner that is having great difficulties with his/her first tictactoe game when they have just been suggested to use tons of advanced C++ features.

Share this post


Link to post
Share on other sites
Quote:
Original post by doho
This is actually exactly the point I was trying to make! When a question is asked about copying a string or something other in the line of this, it is safe to assume that questioner is a beginner.


Only a beginner with the Standard C++ Library. I'll admit, I don't know it at all. I am just learning. But by no means am I a beginner in regards to programming. Heck, I thought it was called STL - thanks Oluseyi for pointing that out. I will not remmeber that, but it's ok [wink]. I did not know the Stander C++ Lib was in existance until like December 2004!

As for what they should use, I stil perfer sprintf over sstream. I never cared for using cout when I could easily do more with printf, so I do see what you are saying about beginners. It just depends on the sitaution really and what needs to be done. However, though, the person asking the questions is responsible in terms of what they choose to and no to follow. I mean if someone told me something, I would investiage before taking it as the truth.

Share this post


Link to post
Share on other sites
Whether stl should be considered advanced knowledge or not is somewhat debatable. Especially when the alternative is manual memory management. The *implementation* of stl is certainly advanced from a beginners viewpoint but so is pretty much everything.

The near constant stream of threads about memory issues (calling new crashes, calling delete crashes, how do I find memory leaks, do I have to use "delete []", can I mix new/delete with malloc/free, why does removing some random line fix memory problems, what is this error about buffer overflows, etc, etc) is testament to the difficulty of hand-rolling even simple data structures.

Another thing to consider is that newbies often don't know what they want. Nor are they typically good at asking questions. Therefore pointing them at alternate solutions that are more likely to end up with a working solution (if not precisely what they originally had in mind) seems reasonable.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
... the person asking the questions is responsible in terms of what they choose to and no to follow. I mean if someone told me something, I would investiage before taking it as the truth.

One shouldn't count on that a 12 year old newbie would investigate a highrated user posting about C++ features. I think that all kinds of not-related or missleading information should be avoided as far as possible.

Share this post


Link to post
Share on other sites
Quote:
Original post by doho
One shouldn't count on that a 12 year old newbie would investigate a highrated user posting about C++ features. I think that all kinds of not-related or missleading information should be avoided as far as possible.


True, but then if you say that, if the programmer is unable to see for themselves what is the best way, does it matter what way is suggested then? I mean by you saying that "all kinds of not-related or missleading information should be avoided as far as possible" goes against the point of asking for help.

I mean, yea, you may want to figure out how to do X, but if it can be done by Y, and you had no idea that it could be done, then that person woh you would regard as not answering the question has made life a lot easier. I mean I've done things like that before. There was some simpler way to do something than I was trying it - so I appreciated people made the efforts to respond with something other than "just do this".

Of course when you want to do X and all you rae getting help for is Y, then yea, that is frustrating, but then again, this site is free and you are under no obligation to come here to get advice and help [wink].

Just my thoughts on this though. [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by doho
And as you say, C++ is not a beginner language and as such I don't see why the "experts" are calling advanced C++ features out loud as some cure to everything.
There is nothing "advanced" about using the Standard C++ Library. There is plenty advanced about writing a robust map implementation, let alone a hash map or sparse matrix. Even a robust and efficient linked list takes care, and unless it is templated - which introduces a whole new set of concerns - it will have to be reimplemented for each node type, or elaborate metatype systems will have to be constructed, neither of which is trivial or smart.

Quote:
I am just trying to fight the right for the pitty beginner that is having great difficulties with his/her first tictactoe game when they have just been suggested to use tons of advanced C++ features.
Stop whining. Use the standard library and get over your failures. We all have them, and that's why we encourage you to avoid them by using battle-tested components. That doesn't mean you don't need to learn how to use them properly, which is why documentation exists.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!