Isn't it funny:P

It seems like for me most of my mistakes come from the simplest things:P Like i have been fighting a bug and i found it in the line:P ill let you see whats wrong with it

for(x=10;x>=+90;x-=10)

I had a little bit of code and after put

std::cout<<"this is NOT the problem";

everywhere i narrowed it down to this line and it's not like a glaring mistake you have to look at it to see it:P
why so strange a for loop
Last edited on
loop condition is false on first iteration.
i know it was giving really weird results...i would explain what it was for but it would take me a while and im sure yall dont care:P
You need to use the debugger.
A simple step-by-step run would made the mistake obvious.
I thought a debugger just find syntax mistakes?
Holy crap i just google what is a debugger how the crap do you use one ive been programming for 2 years without one!! ive been using code blocks 10.05 with the default compiler and stuff...i recently started useing MSVC++ 2010 and i noticed that kinda stuff but do not know how to use it....
Isn't it funny:P

NO!
lol

I have been programming for 6 years without a debugger, I just use couts or prints. Can anyone say that there is a definite reason I should be using one?
You are using library, you cannot change. A pointer to some object becomes garbage at some point. Program didn't work when specific deta entered, but all variables are fine.
it's not like a glaring mistake

Isn't it? (seeing the 90 and 10, the first thing I did is check the termination condition and increment)

I do think it would have been clearer if it had been written as:

for(x=10; x >= +90; x-=10)

rather than

for(x=10;x>=+90;x-=10)

(A chance to take one of my hobby horses for a ride!? Now, not not everyone would agree, but I believe that...)

Source code should generally use white space in a similar way to prose. Horizontal space to separate the meaningful pieces of a line, similar to words. (There is some scope for different takes on what these pieces are.)

And vertical space to separate groups of lines of code, like paragraphs. (Not just to separate functions.)

I would go one futher and write it as;

for (x = 10; x >= +90; x -= 10)

But there are other variant

1
2
3
for( x=10; x >= +90; x-=10 )
for (x = 10; x >= +90; x -= 10)
// etc 


Everywhere I've worked the coding guidelines have mandated this kind of space to make it easier to see that's going on, esp. around operators.

One popular standard is Google's. I don't agree with all its points, but when you're working with other people, a consistent code layout is beneficial. In the absence of anything else, it is a good starting point.

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Horizontal_Whitespace#Horizontal_Whitespace

And I quite like this guy's take:

Statement Formatting
http://www.oualline.com/style/c04.html

Andy

PS I would be interested to see a coding standard that mandate the use of no space around binary operators, so if you know of one, please paste the link here.
Last edited on
closed account (N36fSL3A)
Andy you sniped what I was gonna type.
Topic archived. No new replies allowed.