Thread: Problem with vector iterator

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Programmer_P, the single biggest mistake you are doing is dumping extremely complicated code on us, asking us to debug it and trying to explain what it does in words. Stop.
    If you have a problem, then show the smallest possible compilable example that demonstrates the problem. We don't care if it's an HTML and CSS generator, a car factory, a game or some animal breeder. It just doesn't matter.

    If you have a problem, then you debug it. Can't find the error? Then start commenting out code until it works.
    After doing all that, and you still don't understand what the problem is, then comment out all the code you can until the symptoms disappear.
    Then re-write that code as simple as you can. You don't need some IAmSomeExtremelyLongAndComplicatedType and IAmAnExtremelyUnhelpfulTupe. A and B is just fine, and easier to read.
    Then post the code here. Good code is self-explainable. You don't need to explain how it works--you shouldn't have to, as much as possible. It is far easier to read the code and find out what it does than read your explanations of what it does.

    And I know this one sucks, and is typically boring, but it's still very good advice. Test everything you write properly before plugging it into your working code. Use test-driven development approaches!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I think most of that is undue criticism.
    If you have a problem, then you debug it. Can't find the error? Then start commenting out code until it works. After doing all that, and you still don't understand what the problem is, then comment out all the code you can until the symptoms disappear.
    No idea why you think he didn't do this. He mentions commenting out a bit and then symptoms disappear in his original post. Evidence exists in the thread that he was addressing the problem independently.
    Then re-write that code as simple as you can. You don't need some IAmSomeExtremelyLongAndComplicatedType and IAmAnExtremelyUnhelpfulTupe. A and B is just fine, and easier to read.
    On type names, I agree, except on A and B perhaps. Even though they are long, they are at least descriptive, so I am happy.

    My biggest problem with this part is your statement that the code he posted wasn't simple. Just because something is hard to read, doesn't mean it's not the simplest code. You also encourage him to completely re-write the problem code. I'm not sure I agree with that any more. The biggest reason I couldn't contribute any more than I did was because I didn't know what a singular iterator was. It never occurred to me that the problem was in the comparison operator either, so when I rewrote the code myself intending to show how to do this sort of thing, I mysteriously fixed the error by writing a comparison operator that worked. I can't very well post code that I can't explain why it works. But you know, people beat me to finding the real symptoms.
    Good code is self-explainable. You don't need to explain how it works--you shouldn't have to, as much as possible. It is far easier to read the code and find out what it does than read your explanations of what it does.
    True, but again, I find the code simple once you get past the ugly. I don't see an issue with providing both code and what you think it does. Both code and the person behind the keyboard need to agree on what something is doing. I've made posts with wrong comments before, I've corrected posts with wrong comments before, it's important to know regardless.
    And I know this one sucks, and is typically boring, but it's still very good advice. Test everything you write properly before plugging it into your working code. Use test-driven development approaches!
    After my own heart, are you?
    Last edited by whiteflags; 01-06-2013 at 04:09 PM.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I didn't post anything because the code and the first post was too intimidating.
    Clearly, it showed that there was a lot that could have been simplified, such as removing operators, and stuff. Instead of having a big complicated hierarchy, a simple one that demonstrated the problem could be used.
    To be fair, I didn't read the code. I didn't do it because it was too intimidating. Especially the whole first post. But I know from previous replies that Programmer_P tends to write extremely complicated code than ask for help in fixing it instead of simplifying it.
    I gave up reading the first post TBH. I made it about half-way, which is pretty generous for me. So yes, while commenting on some code is nice, explaining code with words like Programmer_P did in the first post just usually leads to a dead end. A snippet of code would have explained more than a thousand words.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by whiteflags View Post
    I think most of that is undue criticism.

    No idea why you think he didn't do this. He mentions commenting out a bit and then symptoms disappear in his original post. Evidence exists in the thread that he was addressing the problem independently.
    You are right. If you hadn't posted, I wouldn't have even bothered countering what Elysia wrote, even though it was wrong.
    I did indeed debug it a lot first before even starting this thread, and narrowed it down to where in the code the symptoms appeared. But like mentioned before (I think...), I wasn't able to locate the real cause of the problem until
    kmdv pointed out to fix the < operator of the S_browser struct. I hadn't even thought to look there for the cause.

    On type names, I agree, except on A and B perhaps. Even though they are long, they are at least descriptive, so I am happy.
    We both agree on that one. I do recognize that some of my names were probably longer than they should have been.
    However, like you point out, A and B are not very descriptive now are they, and maybe I wasn't able to think of shorter names for them, and still be descriptive.

    My biggest problem with this part is your statement that the code he posted wasn't simple. Just because something is hard to read, doesn't mean it's not the simplest code.
    Ditto. I agree with that too. I agree things should be kept as simple as possible, but for what I was trying to do, I would say that maybe that WAS as simple as possible...

    You also encourage him to completely re-write the problem code. I'm not sure I agree with that any more. The biggest reason I couldn't contribute any more than I did was because I didn't know what a singular iterator was. It never occurred to me that the problem was in the comparison operator either, so when I rewrote the code myself intending to show how to do this sort of thing, I mysteriously fixed the error by writing a comparison operator that worked. I can't very well post code that I can't explain why it works. But you know, people beat me to finding the real symptoms.

    True, but again, I find the code simple once you get past the ugly. I don't see an issue with providing both code and what you think it does. Both code and the person behind the keyboard need to agree on what something is doing. I've made posts with wrong comments before, I've corrected posts with wrong comments before, it's important to know regardless.

    After my own heart, are you?
    You are right on all accounts. I also think that providing both code and what you think the code does is every bit necessary when getting other people to help solve a problem as efficiently as possible.
    Because sometimes code alone is not clear enough as to what the original intent behind the code is, and that can matter when people are trying to figure out what you're trying to do. It is easier to find a problem
    when you know what someone is trying to accomplish, and so can then spot how they're going about it wrong, then to simply read code without knowing what the original end-goal is.

    As for the Elysia's last point you quoted, I do agree with that as well, and should start doing that more. Its just sometimes I get in a mood to start writing code and accomplish a particular thing, that I tend to write
    quite a lot before beginning to test everything.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  5. #20
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    I didn't post anything because the code and the first post was too intimidating.
    Clearly, it showed that there was a lot that could have been simplified, such as removing operators, and stuff. Instead of having a big complicated hierarchy, a simple one that demonstrated the problem could be used.
    Umm...158 lines is big? I am glad then that I did not show the real code of the project in which the problem first originated...I imagine that would have, like, caused you to have a heart attack, or something.

    To be fair, I didn't read the code. I didn't do it because it was too intimidating. Especially the whole first post. But I know from previous replies that Programmer_P tends to write extremely complicated code than ask for help in fixing it instead of simplifying it.
    I gave up reading the first post TBH. I made it about half-way, which is pretty generous for me. So yes, while commenting on some code is nice, explaining code with words like Programmer_P did in the first post just usually leads to a dead end. A snippet of code would have explained more than a thousand words.
    And because of those "earlier posts" you referred to, to which you basically said the same thing, to simplify the code, I did just that, and STILL you complain??
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  6. #21
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    I didn't post anything because the code and the first post was too intimidating.
    I didn't post anything because grumpy's response and the first google result on the error message were the same which also matched the problem with the code, and I'm sketchy with pointers at best! (need to improve that one)

    Though the code itself opened my mind to programming a browser. Seems like a lot of work having to try and work around all the standards that have existed over time through all the web languages. Seems fun.
    Last edited by Lesshardtofind; 01-06-2013 at 10:03 PM.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  7. #22
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Lesshardtofind View Post
    I didn't post anything because grumpy's response and the first google result on the error message were the same which also matched the problem with the code, and I'm sketchy with pointers at best! (need to improve that one)

    Though the code itself opened my mind to programming a browser. Seems like a lot of work having to try and work around all the standards that have existed over time through all the web languages. Seems fun.
    Just to be clear, I'm not programming a web browser. Rather, I am creating a program for creating websites using a GUI. And of course, in order to do that, it is necessary to have code that will write web languages for you, and that's the part I'm working on right now. My plan is, for the first version of the program, to support Html, CSS, Javascript, and PHP. And by "support", I mean provide a fully functional way to write all of those languages using a GUI instead of writing it by hand. In addition, the end-goal is to also make that whole process as easy, fast, and fun as possible, by providing info on each part of each language (so that in a sense, it would also be kinda of a teaching tool, as well...to help one understand code, and to write it better), and giving helpful examples on how to do common things with those languages. However, you are right in that it is a lot of work, and I am indeed going straight from the standards on this one. However, because I'm also thinking about browsers, and how each of them will differ in certain ways with each language, I'm also trying to code for that as well, and make it clear in my program which browser supports which thing from the specification (and that I'm basically figuring out as I go, by testing each thing in each browser).
    Last edited by Programmer_P; 01-06-2013 at 10:31 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  8. #23
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    also make that whole process as easy
    That worries me

    fun as possible, by providing info on each part of each language (so that in a sense, it would also be kinda of a teaching tool, as well...to help one understand code, and to write it better), and giving helpful examples on how to do common things with those languages.
    That sounds like an awesome idea.

    I may have missed it earlier in the thread but what gooey (gui) are you using?
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  9. #24
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Lesshardtofind View Post
    That worries me
    How come?

    That sounds like an awesome idea.

    I may have missed it earlier in the thread but what gooey (gui) are you using?
    I'm using the Qt framework for creating the GUI.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  10. #25
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    How come?
    Making things easier usually lowers the learning curve, that is the part that worries me.

    When it comes to helping younger people and those with near to none experience with a passion for design and learning I think that is a noble cause.

    My concern probably has no reflection of the average opinion in the web designer market.

    I'm using the Qt framework for creating the GUI.
    That is unfortunate I was hoping I might be able to help contribute to the project for the sake of learning, but even though I have spent a decent amount of time on web design and some script languages I have not yet messed around with QT.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  11. #26
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Lesshardtofind View Post
    Making things easier usually lowers the learning curve, that is the part that worries me.
    Well, that's the idea of course. To lower the learning curve.
    Why force everyone to learn everything in the traditional and conventional way? I mean, let's face it, there are a lot of non-geeks out there that would love to create their own website, but are held back because of the complexity of doing it, and maybe because they have never coded before. I think for such people, my program would allow them to reconsider hiring (to them...) some "geek" to do it, and might interest them to the point in actually trying to do it themselves. Not to mention, even for those who do have considerable experience in writing Html, Javascript, etc. and designing websites, my program would help them do it quicker than doing it by hand, which could help those knowledgable in that area, already, to present an end-product to their customer in less time, thus resulting in more customer satisfaction. That sort of thing...

    Of course, the thought has occurred to me that someone else has probably already had the same idea and created such a program before...forcing me to try to make mine better than any choices already out there.

    When it comes to helping younger people and those with near to none experience with a passion for design and learning I think that is a noble cause.
    Yes, that's sort of the audience or user-base I had in mind, originally, when I first had the idea. Especially, since I am still relatively young myself (21)...and so I'm kinda in that category already.

    My concern probably has no reflection of the average opinion in the web designer market.
    Given that I don't even know the average opinion in the web designer market myself, I can't say with any certainty how that will affect things, once I decide to release my program. However, I am hoping that the general consensus will be to support my idea.

    That is unfortunate I was hoping I might be able to help contribute to the project for the sake of learning, but even though I have spent a decent amount of time on web design and some script languages I have not yet messed around with QT.
    Well, perhaps you could still help out in some way. Note that only
    the GUI will be in Qt. I'm writing the core in standard STL-style code.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  12. #27
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Programmer_P View Post
    Umm...158 lines is big? I am glad then that I did not show the real code of the project in which the problem first originated...I imagine that would have, like, caused you to have a heart attack, or something.

    And because of those "earlier posts" you referred to, to which you basically said the same thing, to simplify the code, I did just that, and STILL you complain??
    158 lines is rather big for asking help, especially when it's not all whitespace.
    Just look at the original code: tons of unnecessary properties and declarations. You could have removed them and simplified the code. Don't tell me that it's as simple as it can get.
    Now, as for the explaining of the code, perhaps these advices may help you reduce the complexity of your posts in the future.

    First, avoid writing a wall of text. It discourages people. Try to write as little as possible, if possible.
    Separate your text into paragraphs. It might even be good to use a blank line between paragraphs to increase readability. Believe me, it helps a ton. Find places to split your text into paragraphs! Force it, if necessary.
    And lastly, try to show what you mean with code and simplify your explanation. Don't write "first I did X, then Y, then Z, and that caused A, and then B, and finally C. Then I tried D because I was bored but realized that E was better because of F...". Show your approach with code instead. Easier to read. Really. Chaining lots of things like that makes it hard to read. Split it. Write code, explain why you did it and what happened. Then do the next, and so on. It may be a little longer but it's easier to read.

    I know, writing on message boards and asking for help is a science in itself, but it never hurts to try these things, even if it might be difficult to understand what exactly they mean.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #28
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    158 lines is rather big for asking help, especially when it's not all whitespace.
    Just look at the original code: tons of unnecessary properties and declarations. You could have removed them and simplified the code. Don't tell me that it's as simple as it can get.
    You are right about that. I could have removed a few of those struct variables that I don't actually use in the example code (though I DO use them in the real code...).
    However, since, as I mentioned before..., I simply copied them over from the original code, and pasted them into codepad.org.
    I didn't really see a good reason to go to the trouble of removing those unused variables in the struct, since its like not it would interfere with how the rest of the code works.

    And don't act like its "tons"...

    If you actually read my example code (instead of merely glancing at it and saying "OH! I can't read it. AHH!!!")...which I highly doubt you did, you would see it only takes a couple of seconds to read.

    In addition, everyone knows a program begins at int main(), so you could have scrolled down, and started to read there, instead of reading the structs first, just because they were at the top of the code...
    And if you had only done that, you would have soon discovered how simple my code really was, and not difficult to understand at all, when you are familiar with std::vectors and std::maps.

    Now, as for the explaining of the code, perhaps these advices may help you reduce the complexity of your posts in the future.

    First, avoid writing a wall of text. It discourages people. Try to write as little as possible, if possible.
    Separate your text into paragraphs. It might even be good to use a blank line between paragraphs to increase readability. Believe me, it helps a ton. Find places to split your text into paragraphs! Force it, if necessary.
    And lastly, try to show what you mean with code and simplify your explanation. Don't write "first I did X, then Y, then Z, and that caused A, and then B, and finally C. Then I tried D because I was bored but realized that E was better because of F...". Show your approach with code instead. Easier to read. Really. Chaining lots of things like that makes it hard to read. Split it. Write code, explain why you did it and what happened. Then do the next, and so on. It may be a little longer but it's easier to read.
    Again, these comments make it sound like you did not actually even read my first post the first time you looked at it. You merely glanced at it, and immediately judged it as "difficult to read". And...uh, I DID separate the text of the first post into paragraphs. It is not a "wall of text", as you put it. The first paragraph was long, I'll admit to that, and could have probably been split up into more paragraphs, but it was not a "wall of text"... 7 lines can not be described as that. I chained those lines together since they were connected, and part of the same thought process or "train of thought". And what's wrong at stating what I was trying to do, and how I had decided to go about doing it?? I could have done worse, and made the post really long and extremely detailed about everything I had done, and tried, and all of that...but I figured a shorter post (one to the point...) would be better and cause more people to actually want to read it, that's why I wrote it like that. I think you're just nitpicking now...

    I know, writing on message boards and asking for help is a science in itself, but it never hurts to try these things, even if it might be difficult to understand what exactly they mean.
    Bah...as if I didn't understand what you wrote and what you meant by it. It doesn't take a rocket scientist.

    I only disagree with them.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  14. #29
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    If your code is so easy to read and understand, Programmer_P, why did you need to ask for help? After all, you are assuming that other people can easily digest code and find problems, when you cannot.

    The basic facts are that you;

    1) Posted an unclearly worded question, describing your problem.
    2) Just copied and pasted offending code, without bothering to remove aspects that are unrelated to your problem.
    3) Expect other people to sift through that muddle of information to identify your problem.
    4) Openly admit that your own laziness is a reason for the above.

    From these I infer that you expect other people to expend the effort to do work that you are too lazy to do yourself. Yeah, okay, you investigated other aspects, but - in this thread - you still expect others to do work that you can't be bothered to do for yourself.

    Frankly, given all this (which I have gleaned from reading your posts in this thread) I consider you are very fortunate that you received any reply at all, let alone any reply with a useful answer.

    It doesn't take a rocket scientist to deduce what your approach is.

    How would you like it if other people expected of you what you expect of others?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  15. #30
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by grumpy View Post
    If your code is so easy to read and understand, Programmer_P, why did you need to ask for help? After all, you are assuming that other people can easily digest code and find problems, when you cannot.
    Well, I asked for help because I had looked over the code where the symptoms first appeared (EDIT: and I might add...elsewhere, since I looked in other places too), and had not found the cause, since it was not to be found in the code where the problem appeared.
    And yes, I made an assumption that other (more experienced) people might be able to locate the real cause of the problem where I had failed at that. And that assumption was not wrong, now was it...seeing as my problem is now resolved
    thanks to poster 'kdmv'.

    The basic facts are that you;

    1) Posted an unclearly worded question, describing your problem.
    2) Just copied and pasted offending code, without bothering to remove aspects that are unrelated to your problem.
    3) Expect other people to sift through that muddle of information to identify your problem.
    4) Openly admit that your own laziness is a reason for the above.
    And yet, if I had done what you seem to think I hadn't, and "removed aspects unrelated to my problem", no one would have been able to discover the real cause of the problem, now would they have?
    Seeing as the real problem was to be found in struct 'S_browser'...not in the code that was producing the symptoms of the problem (i.e. in int main() ).

    It seems now that maybe...perhaps (or as you would say...perhaps not)...the ability to actually discern what aspects are RELATED and UNRELATED are not present in every human. Especially one who has not written the original code...such as yourself.

    From these I infer that you expect other people to expend the effort to do work that you are too lazy to do yourself. Yeah, okay, you investigated other aspects, but - in this thread - you still expect others to do work that you can't be bothered to do for yourself.
    Ok, that's wrong. Just plain wrong. You make it sound like I created the thread simply because I was too lazy to do the actual work at debugging it myself.
    Are these forums not here for helping people with programming issues? Is it WRONG to ask for help when you have looked for, but cannot find the problem yourself.

    You act like I have not gone to any effort to fix the problem...yet it is you who have demonstrated more of that behavior in this thread. Yes, ok, maybe I should have liked...umm...Googled the compile error or something.
    But maybe I just prefer to deal with a real human being to fix my problems instead...instead of just using some soulless computer tool to help myself instead. Maybe I enjoy interacting with real people more than Googling my problem all of the time.

    Frankly, given all this (which I have gleaned from reading your posts in this thread) I consider you are very fortunate that you received any reply at all, let alone any reply with a useful answer.
    And yet, you can't help yourself responding to my posts, now can you...?

    It doesn't take a rocket scientist to deduce what your approach is.

    How would you like it if other people expected of you what you expect of others?
    Well, frankly I would not mind at all. I do not think of myself as demanding so much from anyone else...especially not here.
    And if you see it as such, then by all means, don't respond and don't even bother to read any of this. That's always an option.

    These forums exist for the purpose of helping people. Why else would they be here? Thus, why am I wrong to use it as such?
    Your logic is faulty...sorry, but I just can't help pointing that out.
    Last edited by Programmer_P; 01-07-2013 at 09:55 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem using a vector iterator in a loop.
    By M.Richard Tober in forum C++ Programming
    Replies: 6
    Last Post: 10-29-2011, 01:53 PM
  2. vector and iterator problem
    By BeBu in forum C++ Programming
    Replies: 10
    Last Post: 03-11-2009, 07:38 AM
  3. Vector Iterator Help
    By (TNT) in forum C++ Programming
    Replies: 5
    Last Post: 11-04-2007, 02:53 PM
  4. vector<object>::iterator Help
    By The Brain in forum C++ Programming
    Replies: 16
    Last Post: 03-26-2006, 07:22 PM
  5. Iterator _ erasing from a vector help
    By Hexxx in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2006, 07:43 PM