Why are popping a value off the list before you push one on? Your list will never fill. Also, you are pushing a value twice. You're pushing the entered number, then the number 1, why?
Think of a vector like an array that grows as you add elements (the internal implementation is different, but just think of it this way).
e:
Also, this 'vector<int> eaters(1)' creates a vector with one pre-allocated entry. Why are you doing this?
vector<int> eaters(1) is so that it asks "how many pancakes did eater 1 eat" from eater.size. Without it, it'll say 0.
The only method I have of adding in an element is push_back. Im popping off the back which is there just to keep the size right, adding in the pancake number, and then adding in a new one that can be popped off at the end.
The size would be right if you just added 1 to it. You're basically trying to force vector to act as an index 1 array (VB-style), rather than just adjusting your output to say vector.size() + 1. You're using a sledge hammer to fix a hang nail.
Does the "foo::bar" syntax in c++ mean "bar, which can be found in the library foo"?
I saw it in ruby once and had no idea wtf it was supposed to mean. This was a long time ago, though.
Namespace. In that example, "foo" is the namespace, and "bar" is the variable, class or function declared in that namespace.
See, now, I had to look what you meant by "namespace". But I did.
Basically they're a way to distinguish between things that are called the same name (classes, methods, objects, variables, constants, etc.) without Java's sometimes-ludicrous lengthy names, like Widget.Pineapple.YourMom.France.getX() You would just say France::getX() if you had allready imported it from somewhere and you wanted to differentiate it from, say, Gadget.Kiwi.TuMadre.Canada.getX()
Do I basically understand this correctly?
Also, I take it Java doesn't have namespaces?
Monkey Ball Warrior on
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
What GnomeTank said. You don't want to make your data inconsistent (you should have X entries for X eaters, not X + 1) just so that it "shows" right, you should just adjust the display data if need be.
Infidel on
0
Options
GnomeTankWhat the what?Portland, OregonRegistered Userregular
Does the "foo::bar" syntax in c++ mean "bar, which can be found in the library foo"?
I saw it in ruby once and had no idea wtf it was supposed to mean. This was a long time ago, though.
Namespace. In that example, "foo" is the namespace, and "bar" is the variable, class or function declared in that namespace.
See, now, I had to look what you meant by "namespace". But I did.
Basically they're a way to distinguish between things that are called the same name (classes, methods, objects, variables, constants, etc.) without Java's sometimes-ludicrous lengthy names, like Widget.Pineapple.YourMom.France.getX() You would just say France::getX() if you had allready imported it from somewhere and you wanted to differentiate it from, say, Gadget.Kiwi.TuMadre.Canada.getX()
Do I basically understand this correctly?
C++ namespaces work just like Java packages. You could, if you wanted, create a namespace hierarchy that basically went like:
Widget::Pineapple::YourMom::France, referencing the France class in the Widget::Pineapple::YourMom namespace.
You can 'use' namespaces, aka import them in to your local symbol table, by doing:
using namespace XXX::XXX;
You basically have the point of namespaces correct though, they are meant to identification differentiators and organization tools.
What GnomeTank said. You don't want to make your data inconsistent (you should have X entries for X eaters, not X + 1) just so that it "shows" right, you should just adjust the display data if need be.
...
Hey guys, I just found out I can do this:
cout<<"How many pancakes did contestant "<< eater.size() +1<< " eat?" <<endl;
So has anyone had a problem with a web server + PHP + MySQL crashing without logging an error?
I have Lighttpd + PHP 5.3 + MySQL installed via MacPorts, and lighttpd keeps going down without warning and without logging an error. I am ready to tear my hair out.
And the only reason I'm using lighttpd (though I like it a bit better) is because Apache was even less stable. We're talking massively long hang-ups without explanation, frequently followed by crashing.
What GnomeTank said. You don't want to make your data inconsistent (you should have X entries for X eaters, not X + 1) just so that it "shows" right, you should just adjust the display data if need be.
...
Hey guys, I just found out I can do this:
cout<<"How many pancakes did contestant "<< eater.size() +1<< " eat?" <<endl;
MATH IS AMAZING
:?
Im going to work now
That'll always tell you how many elements are in the array, you're better off using the number of your iteration.
Let's say you want to tell the person you're on eater #3 but there's 200 eaters in the list. It's useful to know, anyways, even if this works for your example. I'd suggest staying away from the STD libraries for now, and learning the basics with arrays at least.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
0
Options
GnomeTankWhat the what?Portland, OregonRegistered Userregular
edited June 2010
Random shot in the dark, but are you running it with correct permissions? I assume you have a user setup to run lighttpd, does that user have the correct group memberships?
Pointers aren't hard. Just because a lot of bad programming has been done with them doesn't mean that you're doomed to do the same. Most of the time, if it's tough to keep track of memory and free it at the appropriate time, that's an indication that you need to take a look at the big picture. Memory management is made easiest not by automation, but by well designed and structured code - especially in C++ where you have destructors vs plain old malloc/free.
As far as code readability, pointers are extremely simple. With regards to memory management, they don't do anything by themselves, and there's a well known set of things that are done with them (new, delete, malloc, free, etc.). Anyone who has written C or derivative languages knows the concept. If you use a smart pointer, it has its own special properties regarding the circumstances under which the pointed object will be destroyed, and anyone who reads your code needs to understand those properties. So I would certainly agree that there's an increase in complexity there.
There are exceptions, but in most cases I opt for the interoperability and simplicity of a normal pointer, and use tools like Valgrind to catch any mistakes that slip through the cracks.
Seriously, you think shared_ptr, auto_ptr, and scoped_ptr add that much complexity to your code? Seriously?
With shared_ptr, I don't even care about my destructors. When I allocate a pointer to it, I know for a fact it's going to be de-allocated when that class is torn down, I don't even have to think about it. How is this adding complexity? The complexity of reading less than 50 lines of documentation on the incredibly simple and basic semantics of shared_ptr?
If a C++ programmer can't figure out the kindergarten simple semantics of the Boost and standard lib smart pointers, I don't want them on my team, or maintaining my code, anyway.
This discussion seems very odd, it looks like RSP was sort of responding to something I said and you are also responding to something I said instead of what he said, which is that smart pointers add complexity to code.
What can I say? I'm not a big fan of operator overloading and all the implicit stuff that goes on in C++. To say nothing of the current syntactical nightmare when making a container of a template type. (whoo std::vector<boost::shared_ptr<MyClass>> = good times)
Random shot in the dark, but are you running it with correct permissions? I assume you have a user setup to run lighttpd, does that user have the correct group memberships?
I've been running it as root. Same with Apache.
LoneIgadzra on
0
Options
GnomeTankWhat the what?Portland, OregonRegistered Userregular
Pointers aren't hard. Just because a lot of bad programming has been done with them doesn't mean that you're doomed to do the same. Most of the time, if it's tough to keep track of memory and free it at the appropriate time, that's an indication that you need to take a look at the big picture. Memory management is made easiest not by automation, but by well designed and structured code - especially in C++ where you have destructors vs plain old malloc/free.
As far as code readability, pointers are extremely simple. With regards to memory management, they don't do anything by themselves, and there's a well known set of things that are done with them (new, delete, malloc, free, etc.). Anyone who has written C or derivative languages knows the concept. If you use a smart pointer, it has its own special properties regarding the circumstances under which the pointed object will be destroyed, and anyone who reads your code needs to understand those properties. So I would certainly agree that there's an increase in complexity there.
There are exceptions, but in most cases I opt for the interoperability and simplicity of a normal pointer, and use tools like Valgrind to catch any mistakes that slip through the cracks.
Seriously, you think shared_ptr, auto_ptr, and scoped_ptr add that much complexity to your code? Seriously?
With shared_ptr, I don't even care about my destructors. When I allocate a pointer to it, I know for a fact it's going to be de-allocated when that class is torn down, I don't even have to think about it. How is this adding complexity? The complexity of reading less than 50 lines of documentation on the incredibly simple and basic semantics of shared_ptr?
If a C++ programmer can't figure out the kindergarten simple semantics of the Boost and standard lib smart pointers, I don't want them on my team, or maintaining my code, anyway.
This discussion seems very odd, it looks like RSP was sort of responding to something I said and you are also responding to something I said instead of what he said, which is that smart pointers add complexity to code.
What can I say? I'm not a big fan of operator overloading and all the implicit stuff that goes on in C++. To say nothing of the current syntactical nightmare when making a container of a template type. (whoo std::vector<boost::shared_ptr<MyClass>> = good times)
I guess I can appreciate that, it's just not how I use C++. I like to use all the shortcuts and advanced features, I think when used correctly they create incredibly elegant pieces of software. I don't think the requisite fore-knowledge required by the developer is anymore than we require of C# or Java programmers, in terms of learning the frameworks available with those languages. To me, the standard library and Boost are the ".NET framework" of C++, to use a blunt and terrible analogy/term. Knowing them is not a nicety, it's a necessity.
Also, to get around the syntactic grossness of template nesting, use typedefs. I don't write std::vector<boost::shared_ptr<MyClass>> all over my code, I write:
Random shot in the dark, but are you running it with correct permissions? I assume you have a user setup to run lighttpd, does that user have the correct group memberships?
I've been running it as root. Same with Apache.
Is it leaving a core dump behind? Another completely random shot in the dark.
What GnomeTank said. You don't want to make your data inconsistent (you should have X entries for X eaters, not X + 1) just so that it "shows" right, you should just adjust the display data if need be.
...
Hey guys, I just found out I can do this:
cout<<"How many pancakes did contestant "<< eater.size() +1<< " eat?" <<endl;
MATH IS AMAZING
:?
Im going to work now
That'll always tell you how many elements are in the array, you're better off using the number of your iteration.
Let's say you want to tell the person you're on eater #3 but there's 200 eaters in the list. It's useful to know, anyways, even if this works for your example. I'd suggest staying away from the STD libraries for now, and learning the basics with arrays at least.
Why would you be asking for #3 if you've already asked #1 through #200? :?
So has anyone had a problem with a web server + PHP + MySQL crashing without logging an error?
I have Lighttpd + PHP 5.3 + MySQL installed via MacPorts, and lighttpd keeps going down without warning and without logging an error. I am ready to tear my hair out.
And the only reason I'm using lighttpd (though I like it a bit better) is because Apache was even less stable. We're talking massively long hang-ups without explanation, frequently followed by crashing.
Are you running PHP through FastCGI? or what? Last I knew lighttpd doesn't run PHP in process like apache does, so I can't see how php would be causing any issues outside of timeout errors if it can't reach the FastCGI/SCGI/whatever server.
End on
I wish that someway, somehow, that I could save every one of us
Random shot in the dark, but are you running it with correct permissions? I assume you have a user setup to run lighttpd, does that user have the correct group memberships?
I've been running it as root. Same with Apache.
Is it leaving a core dump behind? Another completely random shot in the dark.
So has anyone had a problem with a web server + PHP + MySQL crashing without logging an error?
I have Lighttpd + PHP 5.3 + MySQL installed via MacPorts, and lighttpd keeps going down without warning and without logging an error. I am ready to tear my hair out.
And the only reason I'm using lighttpd (though I like it a bit better) is because Apache was even less stable. We're talking massively long hang-ups without explanation, frequently followed by crashing.
Are you running PHP through FastCGI? or what? Last I knew lighttpd doesn't run PHP in process like apache does, so I can't see how php would be causing any issues outside of timeout errors if it can't reach the FastCGI/SCGI/whatever server.
Yeah. I'd like to emphasize that the whole reason I switched to lighttpd was that Apache was fucked too. So I think the problem most likely has to do with the PHP install (because I've never had a single problem with MySQL), only trouble is there are no logs showing anything, unless PHP or lighty have some secret logs I don't know about.
This all happened after I accidentally wiped my macports directory and had to reinstall everything. The built-in Apache and PHP have no issues, but I was forced to move to MacPorts because I needed a couple extra PHP features that required a re-compile (e.g. a more recent MySQL module, as well as a PostgreSQL module).
Edit: Well, I got the system Apache to work again, so I guess that's something. Now I can work on my main project again without killing something. Hasn't crashed yet.
What GnomeTank said. You don't want to make your data inconsistent (you should have X entries for X eaters, not X + 1) just so that it "shows" right, you should just adjust the display data if need be.
...
Hey guys, I just found out I can do this:
cout<<"How many pancakes did contestant "<< eater.size() +1<< " eat?" <<endl;
MATH IS AMAZING
:?
Im going to work now
That'll always tell you how many elements are in the array, you're better off using the number of your iteration.
Let's say you want to tell the person you're on eater #3 but there's 200 eaters in the list. It's useful to know, anyways, even if this works for your example. I'd suggest staying away from the STD libraries for now, and learning the basics with arrays at least.
Why would you be asking for #3 if you've already asked #1 through #200? :?
Like I said, it works for this example, but it didn't seem like he grasped the concept of why using .size() was probably a bad idea. If his data-structure isn't fixed from the get go, it should work fine. I just don't want him to come back here a day or two later asking why when he outputs his data for the eater who ate the most pancakes, why it always shows the last person's number.
I've seen it too many times, and I was preempting it, because I've seen this happen on a similar example not too long ago.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Ive been looking at the pancake exercise for a while, and I have no idea how to even begin with sorting the inputs. Is there some vector command im not aware of that would help here? Or is this a case of me trying something I havent gotten to yet in my studying?
Yeah, i was attempting the regular/1star. I cant think of any way to make it work other than a super convulted A>B tests, which I know is a poor choice. Any tips?
edit:
"Once the data has been entered the program must analyze the data and output which person ate the most pancakes for breakfast.
★ Modify the program so that it also outputs which person ate the least number of pancakes for breakfast.
"
Well, you're already getting input right? Why not check input to see if it's the largest right at the beginning, assuming that position 0 (the first eater) is always the largest at the start of the program?
The other option is to check after the fact. Which is the same basic thing, just adding another step to it.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
So I finally got this, I think. It doesnt take into account what happens if 2 people ate the same ammount of pancakes, but that doesnt matter because im official the best coder ever.
edit: redid it with the 1star challenge as well
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int leasteaten;
int skinniest;
int contestants;
int pancake;
int fattest;
int mosteaten;
vector <int> eater(0);
cout<<"How many pancake eaters were there? " <<endl;
cin>>contestants;
while (eater.size() +1 <=contestants)
{
cout<<"How many pancakes did contestant "<< eater.size() +1<< " eat?" <<endl;
cin>>pancake;
if( (pancake>eater.back()) && (pancake>mosteaten))
{
mosteaten = pancake;
fattest = eater.size() +1;
}
else if( (pancake<eater.back()) && (pancake<leasteaten))
{
leasteaten = pancake;
skinniest = eater.size() +1;
}
eater.push_back(pancake);
}
cout<<"Contestant "<<fattest <<" ate the most pancakes. What a tubbo!" <<endl;
cout<<"Contestant "<<skinniest <<" ate the least pancakes. MAN UP!"<<endl;
return 0;
}
I also keep forgetting that = doesnt mean equal, it means assign to. So uh, the order kinda matters when changing values.
Today I made the goosiest mistake in Python. Kind of a goosey mistake in general.
I had a program I wrote several months ago that did some data manipulation for a project at work. I added a thing that let it split that manipulated data into a few files depending on certain factors. However, I was having trouble with there not being as much data in the end as there was in the beginning. It looked like one of the lines of data was truncated. But only that one.
I spent about 2 hours going through my old, poorly documented code making sure everything did what I thought it did, doing all kinds of tests. Finally I had an epiphany, copied all the stuff that split the data into it's own .py file and ran it again and it worked.
The problem? In the program I was writing the results out to a file, then to do the split, reading it back from that file. Only I hadn't closed the file when I was done writing to it, so when it was reading it caught up to the buffer or whatever and just stopped.
Re-posting this. If there is anyone in the market for a full time contract doing Objetive-C development for iPhone/iPad and has decent experience in either Rails or Python/Django, I know someone who is looking to hire 1 or 2 full time contract positions. Experience with dynamic PDF stuff is a huge plus. As is OpenGL experience.
If you are in or near Tampa, FL, great, but telecommute will be considered.
PM me a resume and some code samples and I may forward you on.
Re-posting this. If there is anyone in the market for a full time contract doing Objetive-C development for iPhone/iPad and has decent experience in either Rails or Python/Django, I know someone who is looking to hire 1 or 2 full time contract positions. Experience with dynamic PDF stuff is a huge plus. As is OpenGL experience.
If you are in or near Tampa, FL, great, but telecommute will be considered.
PM me a resume and some code samples and I may forward you on.
Its times like this I wish I knew Objective-C and played around with rails and python.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Posts
The size would be right if you just added 1 to it. You're basically trying to force vector to act as an index 1 array (VB-style), rather than just adjusting your output to say vector.size() + 1. You're using a sledge hammer to fix a hang nail.
See, now, I had to look what you meant by "namespace". But I did.
Basically they're a way to distinguish between things that are called the same name (classes, methods, objects, variables, constants, etc.) without Java's sometimes-ludicrous lengthy names, like Widget.Pineapple.YourMom.France.getX() You would just say France::getX() if you had allready imported it from somewhere and you wanted to differentiate it from, say, Gadget.Kiwi.TuMadre.Canada.getX()
Do I basically understand this correctly?
Also, I take it Java doesn't have namespaces?
C++ namespaces work just like Java packages. You could, if you wanted, create a namespace hierarchy that basically went like:
Widget::Pineapple::YourMom::France, referencing the France class in the Widget::Pineapple::YourMom namespace.
You can 'use' namespaces, aka import them in to your local symbol table, by doing:
using namespace XXX::XXX;
You basically have the point of namespaces correct though, they are meant to identification differentiators and organization tools.
...
Hey guys, I just found out I can do this:
cout<<"How many pancakes did contestant "<< eater.size() +1<< " eat?" <<endl;
MATH IS AMAZING
:?
Im going to work now
I have Lighttpd + PHP 5.3 + MySQL installed via MacPorts, and lighttpd keeps going down without warning and without logging an error. I am ready to tear my hair out.
And the only reason I'm using lighttpd (though I like it a bit better) is because Apache was even less stable. We're talking massively long hang-ups without explanation, frequently followed by crashing.
That'll always tell you how many elements are in the array, you're better off using the number of your iteration.
Let's say you want to tell the person you're on eater #3 but there's 200 eaters in the list. It's useful to know, anyways, even if this works for your example. I'd suggest staying away from the STD libraries for now, and learning the basics with arrays at least.
This discussion seems very odd, it looks like RSP was sort of responding to something I said and you are also responding to something I said instead of what he said, which is that smart pointers add complexity to code.
What can I say? I'm not a big fan of operator overloading and all the implicit stuff that goes on in C++. To say nothing of the current syntactical nightmare when making a container of a template type. (whoo std::vector<boost::shared_ptr<MyClass>> = good times)
I've been running it as root. Same with Apache.
I guess I can appreciate that, it's just not how I use C++. I like to use all the shortcuts and advanced features, I think when used correctly they create incredibly elegant pieces of software. I don't think the requisite fore-knowledge required by the developer is anymore than we require of C# or Java programmers, in terms of learning the frameworks available with those languages. To me, the standard library and Boost are the ".NET framework" of C++, to use a blunt and terrible analogy/term. Knowing them is not a nicety, it's a necessity.
Also, to get around the syntactic grossness of template nesting, use typedefs. I don't write std::vector<boost::shared_ptr<MyClass>> all over my code, I write:
Is it leaving a core dump behind? Another completely random shot in the dark.
Why would you be asking for #3 if you've already asked #1 through #200? :?
Are you running PHP through FastCGI? or what? Last I knew lighttpd doesn't run PHP in process like apache does, so I can't see how php would be causing any issues outside of timeout errors if it can't reach the FastCGI/SCGI/whatever server.
Not sure what that is, will google I guess.
Yeah. I'd like to emphasize that the whole reason I switched to lighttpd was that Apache was fucked too. So I think the problem most likely has to do with the PHP install (because I've never had a single problem with MySQL), only trouble is there are no logs showing anything, unless PHP or lighty have some secret logs I don't know about.
This all happened after I accidentally wiped my macports directory and had to reinstall everything. The built-in Apache and PHP have no issues, but I was forced to move to MacPorts because I needed a couple extra PHP features that required a re-compile (e.g. a more recent MySQL module, as well as a PostgreSQL module).
Edit: Well, I got the system Apache to work again, so I guess that's something. Now I can work on my main project again without killing something. Hasn't crashed yet.
Like I said, it works for this example, but it didn't seem like he grasped the concept of why using .size() was probably a bad idea. If his data-structure isn't fixed from the get go, it should work fine. I just don't want him to come back here a day or two later asking why when he outputs his data for the eater who ate the most pancakes, why it always shows the last person's number.
I've seen it too many times, and I was preempting it, because I've seen this happen on a similar example not too long ago.
edit:
"Once the data has been entered the program must analyze the data and output which person ate the most pancakes for breakfast.
★ Modify the program so that it also outputs which person ate the least number of pancakes for breakfast.
"
That part^
I have to do a convulted tree of if A>B tests? I.. I think im missing something here.
All I have at the moment is
The other option is to check after the fact. Which is the same basic thing, just adding another step to it.
Oh, it was glorious, on multiple levels.
So I finally got this, I think. It doesnt take into account what happens if 2 people ate the same ammount of pancakes, but that doesnt matter because im official the best coder ever.
edit: redid it with the 1star challenge as well
I also keep forgetting that = doesnt mean equal, it means assign to. So uh, the order kinda matters when changing values.
I had a program I wrote several months ago that did some data manipulation for a project at work. I added a thing that let it split that manipulated data into a few files depending on certain factors. However, I was having trouble with there not being as much data in the end as there was in the beginning. It looked like one of the lines of data was truncated. But only that one.
I spent about 2 hours going through my old, poorly documented code making sure everything did what I thought it did, doing all kinds of tests. Finally I had an epiphany, copied all the stuff that split the data into it's own .py file and ran it again and it worked.
The problem? In the program I was writing the results out to a file, then to do the split, reading it back from that file. Only I hadn't closed the file when I was done writing to it, so when it was reading it caught up to the buffer or whatever and just stopped.
/faceplam
If you are in or near Tampa, FL, great, but telecommute will be considered.
PM me a resume and some code samples and I may forward you on.
OK maybe 20 years.
Its times like this I wish I knew Objective-C and played around with rails and python.