STL and newbies

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 on other sites
Quote:
 Original post by dohoMy 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 on other sites
Quote:
Original post by Oluseyi
Quote:
 Original post by dohoMy 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 OluseyiThe 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 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 on other sites
Quote:
 Original post by OluseyiC++ 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 on other sites
Quote:
 Original post by dohoThis 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 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 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 on other sites
Quote:
 Original post by dohoOne 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 on other sites
Quote:
 Original post by dohoAnd 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 on other sites
Quote:
 Original post by Drew_BentonTrue, 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?

Yea I kinda think it does. The programmer might be able to understand the concepts presented in the one solution and apply them later to solve some other problem where as the other solution not might be so usable except for this very special case.

Quote:
 Original post by Drew_Benton 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 was just trying to say that missleading information is far worse than none. "The only bad comments are incorrent comments." Sorry if I was beeing unclear.

Share on other sites
Quote:
 Original post by dohoOne 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.
You're talking about incomplete problem specification. Software development is problem solving, period. If you say you are trying to solve a problem and someone gives you the most efficient solution, you should be done unless you have a specific reason to prefer an alternative solution. And unless you share that constraint, or at least state that you have that constraint, the other individual has no reason to encourage you to learn inefficient methods of solving problems.

And before you argue that learning all the methods is good for general knowledge, the truth is that you will learn all the methods over time as you try to solve various problems with a variety of constraints. So, no.

Share on other sites
Quote:
Original post by Oluseyi
Quote:
 Original post by dohoI 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.

I simply started this thread because I was curious if many beginners had the same problems as I had. It has nothing to do with "getting over my failures".

Quote:
 Original post by OluseyiAnd before you argue that learning all the methods is good for general knowledge, the truth is that you will learn all the methods over time as you try to solve various problems with a variety of constraints. So, no.

That's a good point.

Share on other sites
Quote:
Original post by doho
Quote:
 Original post by Drew_Benton 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.

You have an excellent point, but I am going to counter once again. If no misleading information was ever presented, then no one would bother to check out alternatives to what they have been told. Misinformation is the key to becoming a better thinker. If someone tells me that I can do something one way, and it is the easiest way, and it turns out that I thought it was quite hard, then someone else says there is an easier way by doing this and it turns out a lot easier, I am going to think twice before I take the first word for something again.

Sadly, most people do not do this, but ideally, it is what gets people to start 'thinking' about a problem rather than just accpeting what is told. A lot of beginners like being spoon fed, so it is a big hump to get over, but once they can get over that, then they are on the path of becoming a better programmer.

It should also ideally get to the point where a programmer can just try out the options rather than even ask about them. I mean each person is different and no one knows what someone else likes/dislikes. I mean it is always convient to have other people give you assistance on a problem, but you have to understand tha fact that these responses are biased and potentially incorrect. We are all human.

Anyways, Doho, I think you have a great thread as it raises a lot of good questions to what approaches should be taken when giving help. These are just my opinions, so I am by no means disagreeing with what you have said, I just like adding some other 'possibilities' to the frey for discussion [wink]. And ot go back to your first post:

Quote:
 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.

I am at that point right now! I started trying out STL and I have missed some very curcual pointscrucial points to where I am doing a lot of revising. Luckily though there are a lot of people on this forum with more Standard C++ Library experience that can help me out. [smile]

- Drew

 Don't know how I butchered that word [lol] [/edit]

[Edited by - Drew_Benton on March 26, 2005 6:57:13 PM]

Share on other sites
Quote:
 Original post by Drew_BentonAnyways, Doho, I think you have a great thread as it raises a lot of good questions to what approaches should be taken when giving help.

Thanks Drew, I'm happy you also find these questions interesting.

Quote:

And ot go back to your first post:
Quote:
 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.

I am at that point right now! I started trying out STL and I have missed some very curcual points to where I am doing a lot of revising. Luckily though there are a lot of people on this forum with more Standard C++ Library experience that can help me out. [smile]

Yey :) I'm not the only one.

Share on other sites
I think learning about some basic STL containers is doable. You don't have to become an expert on C++ to use them. If you need to modify them then that might be bit more involved and probably not suited for newbie. However I strongly recommend you buy a STL book in any case. One that shows you how to use STL by providing you with examples and clear explanations. If there was a need for only one book, then it would be for STL because there is so little about usage/modification of STL on the net or in docs. I think in the end you would want your own containers to be templated to be reusable across projects. I think STL is the best thing that has happened to C++ and it's just amazing in what short time it was implemented into the lang. The best thing is that STL abstracts pointers and memory manipulations and that is where lot of bugs happen if you write your own containers in C. Severely reduces memory leaks in my experience. You still have lots of opportunities to write your own data structures that STL doesn't provide and STL just takes some work from you and saves you time.

Share on other sites
As many here might be aware, I am fundamentally against C++ as a language for beginners. It was never intended for beginners. It was intended for C programmers who wanted to make use of some aspects of object orientation. As it wasn't designed for beginners, why would anyone use it as such? A bit like using a screwdriver on a nail, if you ask me.

If you're having difficulties with data structures or algorithms, I suggest the following:
Learn Scheme (It was designed for beginners).
Read this book (The price is high, but the content per page is very high. Based on the net content, it's actually very cheap)

gl hf

(This should probably be in For Beginners)

Share on other sites
Quote:
 Original post by flangazor(This should probably be in For Beginners)
My thoughts exactly.

Share on other sites
I'm not sure if I'm a beginner still or not.

Anyways, I think that beginners should be brought up exclusively on the STL. I certainly wish I'd been. Maybe I'd've been working on games for a while now instead of working for years learning how to properly build lists, and how to properly handle strings just so I could sort of get to game making. Only then to realise that the lists were not generic enough, or buggy, or designed with a flaw because I was too inexperienced to know I needed something...

That said, I also think the STL is too often suggested. Oddly it's usually suggested by non-experts, simply because that seems to be the thing to say. "Only n00bs write their own linked lists" seems to be the tone more often than not when the suggestion is made.

Still. Learning the STL from the start is a "good thing"(tm). It allows beginners to focus their time on learning, rather than infrastructure debugging or data structure design. It gets beginners thinking in more of a proper computer science mode rather than the usual procedural mode everyone is used to. It gets beginners better help, because experts don't have to read through [possibly buggy]linked list code to get to the meat of things.

Share on other sites
Quote:
Original post by doho
Quote:
 Original post by OluseyiC++ 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.

That would be because using those features is easier and results in working code.

char * c = strcat(a, b);// Oops, that didn't make a new "string" in c, it caused c to point at a, and// added the b stuff to the end of a. Even if the beginner knew "how to use"// strcat, he still has to remember which order to put the parameters in -// dest-first isn't necessarily obvious.// Oops, who knows if there was enough memory allocated for that concatenation?// And who's going to clean that memory up anyway? Who even knows whether a and// b point at local buffers or at heap allocations?// Oh, and what kind of weird magical incantation is "strcat" anyway? And what// if I want a \0 in the middle of my string data? Oh, and let's not// forget possible performance issues due to not having a length-counted string.std::string c = a + b;// Readable, intuitive and does exactly what you would expect it to on both// a high level ("c is now the string representing the concatenation of a and// b, which are unchanged") and a low level (memory is allocated as needed, and// will be automatically cleaned up when the strings go out of scope; allows// storage of \0; maintains a length count).

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.

They only seem advanced because you know something about C and/or because of C++'s bend-over-backwards-compatibility.

Share on other sites
Just a question - does the lack of regard for the Standard Library arise because it's not seen as an integral part of the C++ language?

Jim.

Share on other sites
Quote:
 Original post by JimPriceJust a question - does the lack of regard for the Standard Library arise because it's not seen as an integral part of the C++ language? Jim.

To be honest, I just think a lot of people have no idea it's there, so they don't use it. I'm just saying this because I had NO idea it existed until someone had said something on GameDev to me about using it.

Share on other sites
Quote:
Original post by Zahlman
Quote:
Original post by doho
Quote:
 Original post by OluseyiC++ 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.

That would be because using those features is easier and results in working code.

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.

They only seem advanced because you know something about C and/or because of C++'s bend-over-backwards-compatibility.

In all fairness, the STL -is- advanced, if only for the reason doho describes above: template compiler errors are more... arcane than those that are not. The majority of a beginner's time is spent debugging, not coding. But perhaps I am not understanding you correctly?

Share on other sites
Stickied. Keep the good stuff coming.

I pretty much agree with Drew and Oluseyi. Using the C++ Standard Library isn't and advanced topic (even though its implementation is). There are a couple things you've got to learn (instanciating containers with the desired element type, iterating, using the standard algorithms), but it is much simpler than 'pointers' and 'strings' - as beginners tend to approach them (the C way).

Before even bothering to learn how to implement any given data structure, a programmer should learn how to use it. I see too many people struggling to create a linked-list class and then slap an (inefficient!) indexing operator onto it. This only shows that not only they don't understand the data structure they've implemented (countering the "learning experience" argument), but then, they use it in production code (their "game engine") and end up with a slow, often buggy program. Then, what's the point?

Share on other sites
Quote:
 Original post by TelastynIn all fairness, the STL -is- advanced, if only for the reason doho describes above: template compiler errors are more... arcane than those that are not.

Beginners often don't even *read* error messages, much less try to understand them. Most 'template' errors involving the STL, as opposed to templates you roll out yourself, are just plain type mismatch (which generally pop up as "can't convert FOO to BAR"), or unavailable operations (when you've got the wrong kind of iterator). Granted, they're often more verbose, due to the sheer length of STL type names, but they're not arcane. (Use the boost::mpl and you'll see arcane errors).

Create an account

Register a new account

• Forum Statistics

• Total Topics
628400
• Total Posts
2982447

• 10
• 9
• 19
• 24
• 10