Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 03-16-2004, 01:23 AM   #1
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
C++: Why is my function being bypassed?

Code:
#include #include int menu(); void operation(int, double&, double&, double&, double&, double&, double&); double vector_verify(double, double, double); int main() { int selection; double lambdaAx, lambdaAy, lambdaAz, lambdaBx, lambdaBy, lambdaBz; selection = menu(); operation(selection, lambdaAx, lambdaAy, lambdaAz, lambdaBx, lambdaBy, lambdaBz); return 0; } void operation(int choice, double& Ax, double& Ay, double& Az, double& Bx, double& By, double& Bz) { switch (choice) { case 1: double dx1, dy1, dz1, dx2, dy2, dz2; double lambda1x, lambda1y, lambda1z, lambda2x, lambda2y, lambda2z; double distance1, distance2, vector1, vector2; while (vector1 <= 0.8945 | vector1 >= 1.1055) { cout << endl << "FOR THE FIRST VECTOR" << endl; cout << "Enter the distance in the x-direction: "; cin >> dx1; cout << "Enter the distance in the y-direction: "; cin >> dy1; cout << "Enter the distance in the z-direction: "; cin >> dz1; distance1 = dx1*dx1 + dy1*dy1 + dz1*dz1; lambda1x = dx1/(sqrt(distance1)); lambda1y = dy1/(sqrt(distance1)); lambda1z = dz1/(sqrt(distance1)); vector1 = vector_verify(lambda1x, lambda1y, lambda1z); } while (vector2 <= 0.8945 | vector2 >= 1.1055) { cout << endl << "FOR THE SECOND VECTOR" << endl; cout << "Enter the distance in the x-direction: "; cin >> dx2; cout << "Enter the distance in the y-direction: "; cin >> dy2; cout << "Enter the distance in the z-direction: "; cin >> dz2; distance2 = dx2*dx2 + dy2*dy2 + dz2*dz2; lambda2x = dx2/(sqrt(distance2)); lambda2y = dy2/(sqrt(distance2)); lambda2z = dz2/(sqrt(distance2)); vector2 = vector_verify(lambda2x, lambda2y, lambda2z); } Ax = lambda1x; Ay = lambda1y; Az = lambda1z; Bx = lambda2x; By = lambda2y; Bz = lambda2z; //ignoring cases 2, 3 and 4 as I haven't gotten to them yet break; return; } double vector_verify(double x, double y, double z) { double check; check = (x*x + y*y + z*z); if (check <= 0.8945 | check >= 1.1055) { cout << endl << "Your input does not correspond to a vector."; cout << endl << "Please try again..." << endl; } return check; }


vector_verify() was working well until I tried to implement pass by reference in operation(). The reason I wanted to do this is because I wanted the 6 components of the vectors to end up in main() so I could then pass them onto another function to do some calculations rather than have everything build up in operation().

The six components are correctly being returned to main as I wanted but now it seems vector_verify is never called in the while loop. Everything else in the loop works fine.

I'm not sure what is going on. Any help would be greatly appreciated.


Last edited by Karim : 03-16-2004 at 01:24 AM.
Karim is offline   Reply With Quote
Old 03-16-2004, 01:34 AM   #2
Solecismic
Solecismic Software
 
Join Date: Oct 2000
Location: Canton, OH
Hard to say, not knowing the exact syntax of the compiler. All that jumps out at me is the use of | instead of || for the "or" clauses.
Solecismic is offline   Reply With Quote
Old 03-16-2004, 03:35 AM   #3
Marc Vaughan
SI Games
 
Join Date: Oct 2000
Location: Melbourne, FL
I notice that:

<<
double dx1, dy1, dz1, dx2, dy2, dz2;
double lambda1x, lambda1y, lambda1z, lambda2x, lambda2y, lambda2z;
double distance1, distance2, vector1, vector2;
>>

Doesn't initialise any variable values, I haven't put the code into a compiler but at first glance it doesn't appear that the values used in the while loop are initialised - potentially with unusual consequences? ...

I'm also somewhat dubious about the | instead of a || in various parts of the code (but it might just be that you're cleverer than me and meant to do that) ...
Marc Vaughan is offline   Reply With Quote
Old 03-16-2004, 04:32 AM   #4
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
Right. Using | instead of || was just a mistake on my part but it still compiled. I'm using G++.

As far as not initialising, if I initialised all the variables to lets say 0, I can no longer compile; I get the following error:

In function `void operation (int, double &, double &,
double &, double &, double &, double &)':
vectors.cpp:104: jump to case label
vectors.cpp:61: crosses initialization of `double vector2'
vectors.cpp:61: crosses initialization of `double vector1'
vectors.cpp:61: crosses initialization of `double distance2'
vectors.cpp:61: crosses initialization of `double distance1'
vectors.cpp:60: crosses initialization of `double lambda2z'
vectors.cpp:60: crosses initialization of `double lambda2y'
vectors.cpp:60: crosses initialization of `double lambda2x'
vectors.cpp:60: crosses initialization of `double lambda1z'
vectors.cpp:60: crosses initialization of `double lambda1y'
vectors.cpp:60: crosses initialization of `double lambda1x'
vectors.cpp:59: crosses initialization of `double dz2'
vectors.cpp:59: crosses initialization of `double dy2'
vectors.cpp:59: crosses initialization of `double dx2'
vectors.cpp:59: crosses initialization of `double dz1'
vectors.cpp:59: crosses initialization of `double dy1'
vectors.cpp:59: crosses initialization of `double dx1'

The values are being stored properly inside the loop and being returned properly to main(). However, even if I enter crazy values, vector_verify() doesn't engage to let me know that I need to re-enter the data.

If all else fails, I suppose I could forget about passing the values back to main and just call another function after the loops are done. I wanted to avoid that because operation() just becomes too messy.

Quote:
but it might just be that you're cleverer than me and meant to do that) ...

Not at all. I'm a complete newbie here. But in January my skill set was limited to "Hello world" so I think I'm making progress.


Thanks for your help.
Karim is offline   Reply With Quote
Old 03-16-2004, 04:53 AM   #5
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
Well, I figured out the error although I don't really understand why...

It turns out that I cannot include the calculations:

distance1 = dx1*dx1 + dy1*dy1 + dz1*dz1;
distance2 = dx2*dx2 + dy2*dy2 + dz2*dz2;

inside the while loop.


If anyone can explain why it wouldn't work the other way, it would be greatly appreciated.
Karim is offline   Reply With Quote
Old 03-16-2004, 05:57 AM   #6
Marc Vaughan
SI Games
 
Join Date: Oct 2000
Location: Melbourne, FL
I had five minutes while waiting for FM to build so I chucked your code snippet into the compiler and made it compile cleanly under VC++ - couldn't run it without the rest of your code, but thought it might help ...

Code:
// ---------------------- // // Standard Include Files // // ---------------------- // #include #include // ------------------- // // Function Prototypes // // ------------------- // int menu( void ); void operation( int choice, double& Ax, double& Ay, double& Az, double& Bx, double& By, double& Bz); double vector_verify(double x, double y, double z); // ----------------------------------------------------------------------- // Function: main() // Purpose: Main function for the vector program. // ----------------------------------------------------------------------- int main( void ) { int selection; double lambdaAx, lambdaAy, lambdaAz, lambdaBx, lambdaBy, lambdaBz; selection = menu(); operation(selection, lambdaAx, lambdaAy, lambdaAz, lambdaBx, lambdaBy, lambdaBz); return 0; } // main() // ----------------------------------------------------------------------- // Function: operation() // Purpose: Performs the vector operation // ----------------------------------------------------------------------- void operation( int choice, double& Ax, double& Ay, double& Az, double& Bx, double& By, double& Bz ) { double dx1 = 0.0; double dy1 = 0.0; double dz1 = 0.0; double dx2 = 0.0; double dy2 = 0.0; double dz2 = 0.0; double lambda1x = 0.0; double lambda1y = 0.0; double lambda1z = 0.0; double lambda2x = 0.0; double lambda2y = 0.0; double lambda2z = 0.0; double distance1 = 0.0; double distance2 = 0.0; double vector1 = 0.0; double vector2 = 0.0; switch( choice ) { case 1: while (vector1 <= 0.8945 || vector1 >= 1.1055) { cout << endl << "FOR THE FIRST VECTOR" << endl; cout << "Enter the distance in the x-direction: "; cin >> dx1; cout << "Enter the distance in the y-direction: "; cin >> dy1; cout << "Enter the distance in the z-direction: "; cin >> dz1; distance1 = ( dx1 * dx1 ) + ( dy1 * dy1 ) + ( dz1 * dz1 ); lambda1x = dx1 / ( sqrt( distance1 ) ); lambda1y = dy1 / ( sqrt( distance1 ) ); lambda1z = dz1 / ( sqrt( distance1 ) ); vector1 = vector_verify( lambda1x, lambda1y, lambda1z ); } while (vector2 <= 0.8945 || vector2 >= 1.1055) { cout << endl << "FOR THE SECOND VECTOR" << endl; cout << "Enter the distance in the x-direction: "; cin >> dx2; cout << "Enter the distance in the y-direction: "; cin >> dy2; cout << "Enter the distance in the z-direction: "; cin >> dz2; distance2 = ( dx2 * dx2 ) + ( dy2 * dy2 ) + ( dz2 * dz2 ); lambda2x = dx2 /( sqrt( distance2 ) ); lambda2y = dy2 /( sqrt( distance2 ) ); lambda2z = dz2 /( sqrt( distance2 ) ); vector2 = vector_verify(lambda2x, lambda2y, lambda2z); } Ax = lambda1x; Ay = lambda1y; Az = lambda1z; Bx = lambda2x; By = lambda2y; Bz = lambda2z; break; default: break; } } // operation() // ----------------------------------------------------------------------- // Function: vector_verify() // Purpose: Validates that the vectors input were sensible and indicates // a warning if not. // ----------------------------------------------------------------------- double vector_verify( double x, double y, double z ) { double check; check = ( ( x * x ) + ( y * y ) + ( z * z ) ); if (check <= 0.8945 || check >= 1.1055) { cout << endl << "Your input does not correspond to a vector."; cout << endl << "Please try again..." << endl; } return check; } // vector_verify()
Marc Vaughan is offline   Reply With Quote
Old 03-16-2004, 05:58 AM   #7
Marc Vaughan
SI Games
 
Join Date: Oct 2000
Location: Melbourne, FL
PS. Sorry for the anal reformatting & headers etc., force of habit .... just makes it easier for me to look at code.
Marc Vaughan is offline   Reply With Quote
Old 03-16-2004, 07:19 AM   #8
3ric
College Starter
 
Join Date: Dec 2000
Location: Sweden
Memo to self: If any bugs are found in Marc's code for SI Games' Football Manager, blame Karim.


...



/Just kidding)
__________________
San Diego Chargers (HFL) - Lappland Reindeers (WOOF) - Gothenburg Giants (IHOF)
Indiana: A TCY VC - year 2044 - the longest running dynasty ever on FOFC!
3ric is offline   Reply With Quote
Old 03-16-2004, 08:28 AM   #9
hukarez
College Starter
 
Join Date: Dec 2003
Location: Chula Vista, CA
@Woo! Nice headers!

Very pretty.
__________________
...what we have here is a man who looks like Tarzan, but fights like Jane!
My VG collection | Xbox 360 Gamertag: ManThol | PS3 Network ID: hukarez
Doce Pares International - San Diego Council
Filipino Martial Arts Digest
tweet tweet twitter
hukarez is offline   Reply With Quote
Old 03-16-2004, 12:24 PM   #10
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Turn on all warnings, and it should complain to you about using vector1 before it is initialized. Marc's VC version fixes the problem by initializing it to 0.0.

You should declare your variables outside the switch statement, or wrap the case block in a pair of braces, in order to avoid the error it was giving when you tried to inialize on declaration. Keep in mind that a case statement is basically just a target label for a goto statement (implicit in the "switch"), it doesn't create a "real" block of code.
Mr. Wednesday is offline   Reply With Quote
Old 03-16-2004, 12:28 PM   #11
primelord
Pro Rookie
 
Join Date: Oct 2000
Quote:
Originally Posted by Marc Vaughan
PS. Sorry for the anal reformatting & headers etc., force of habit .... just makes it easier for me to look at code.

I wish everyone made a habit of that.
primelord is offline   Reply With Quote
Old 03-16-2004, 12:54 PM   #12
Raven
College Prospect
 
Join Date: Oct 2000
Location: Baltimore, MD
some things I noticed...


I don't think you can declare variables inside of a switch statement. That's probably where you are getting all those cross initialization errors. Use mark's code and declare the variables before the switch. Instead of using all those lines of code for initialization, you could just put them on the same line like this....

double dx1 (0.0), dy1 (0.0), dz1 (0.0); // etc...
or
double dx1 = 0, dy1 = 0, dz1 = 0; // same as above, but slightly diff. syntax

Your project is kind of ambiguous, so it's tough for me to actually try and debug. The best thing you can probably do is put in priming reads every time you calculate something new. That way you can check what your variables are every time they change. If you know what you are looking for, you can track down your error(s) this way.

distance1 = ( dx1 * dx1 ) + ( dy1 * dy1 ) + ( dz1 * dz1);
cout << "in first while loop distance1 is " << distance1 << endl;

vector1 = vector_verify( lambda1x, lambda1y, lambda1z );
cout << "vector 1 is " << vector1 << " after vector_verify" << endl;

Also use a priming read in vector_verify() if you don't think it is being called.
Simply putting cout << "hi" << endl; inside the function, you will see whether it is called or not.

ps....this seems to be a pretty tough program for an absolute newbie. Is this for a class, or are you getting this from a book and doing it on your own?
Raven is offline   Reply With Quote
Old 03-16-2004, 02:24 PM   #13
Coffee Warlord
Head Coach
 
Join Date: Oct 2002
Location: Colorado Springs
Quote:
Originally Posted by Marc Vaughan
PS. Sorry for the anal reformatting & headers etc., force of habit .... just makes it easier for me to look at code.

I officially love you Marc. Someone who formats/indents {}'s properly.
Coffee Warlord is offline   Reply With Quote
Old 03-16-2004, 03:13 PM   #14
MacroGuru
Coordinator
 
Join Date: May 2003
Location: Utah
Im still sitting here, with a tear in my eye, looking at the beauty...MV is a true artist!
__________________
"forgetting what is in the past, I strive for the future"
MacroGuru is offline   Reply With Quote
Old 03-16-2004, 03:24 PM   #15
sabotai
General Manager
 
Join Date: Oct 2000
Location: The Satellite of Love
Quote:
Originally Posted by primelord
I wish everyone made a habit of that.

Why do you think they call it code?
sabotai is offline   Reply With Quote
Old 03-16-2004, 03:32 PM   #16
Buzzbee
College Starter
 
Join Date: Jun 2002
Oh, by the way, Karim thanks you all for doing his homework for him.
__________________
Ability is what you're capable of doing. Motivation determines what you do. Attitude determines how well you do it. - Lou Holtz

Last edited by Buzzbee : 03-16-2004 at 03:32 PM.
Buzzbee is offline   Reply With Quote
Old 03-16-2004, 08:38 PM   #17
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
Quote:
Originally Posted by Marc Vaughan
PS. Sorry for the anal reformatting & headers etc., force of habit .... just makes it easier for me to look at code.

Thanks for this MV. If you don't mind, I think I'm going to adopt this style as I think it will make things easier as I progress onto more difficult things.


Quote:
Originally Posted by Mr. Wednesday
You should declare your variables outside the switch statement, or wrap the case block in a pair of braces, in order to avoid the error it was giving when you tried to inialize on declaration.

I know I can rely on you to track down my errors. Thanks for your help again.


Quote:
Originally Posted by Raven
ps....this seems to be a pretty tough program for an absolute newbie. Is this for a class, or are you getting this from a book and doing it on your own?

The class is supposed to be an introduction to C++ for engineers and scientists. The actual program is meant to calculate the angle between a pair of vectors depending upon whether the input data are distances, direction angles or direction cosines.


Quote:
Originally Posted by Buzzbee
Oh, by the way, Karim thanks you all for doing his homework for him.
Shhhhhhhh.............
Karim is offline   Reply With Quote
Old 03-16-2004, 09:02 PM   #18
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by Buzzbee
Oh, by the way, Karim thanks you all for doing his homework for him.
For my part, it certainly wasn't doing his homework for him. It was imparting wisdom that he will hopefully use again down the road.


Oh, and something else it appears you missed -- You're using cout, cin, and endl without a namespace qualifier and without either using them or using the std namespace. You didn't say which compiler you were using, but any self-respecting C++ compiler ought to squawk about not knowing what cin, cout, or endl are.

Edit: Or else maybe you're including <iostream.h>? If so, I recommend using <iostream> (note the lack of extension) (the biggest reason for this is that it supports strings natively, as opposed to classical iostreams that only support char* strings), but until you do so, disregard the rest of this message since the classical iostreams came about before namespaces and thus dump everything into the global namespace.

This is easily fixed -- just add the following line at the top of your file, after the includes and before any of the code:
using namespace std;

As a matter of personal style, I rarely "use" a namespace, particularly not globally, but it won't hurt anything as long as you don't do it in a header file (don't ever do it in a header file). Usually, I just use the qualifier in my code, on occasion I'll "use" frequently-used symbols, on rare occasions I'll use a full namespace within a function or block scope.

Last edited by Mr. Wednesday : 03-16-2004 at 09:06 PM.
Mr. Wednesday is offline   Reply With Quote
Old 03-16-2004, 09:25 PM   #19
sabotai
General Manager
 
Join Date: Oct 2000
Location: The Satellite of Love
Taking this one off topic kind of (since the original question has been answered it would seem).

Quote:
You're using cout, cin, and endl without a namespace qualifier and without either using them or using the std namespace.

I've seen this brought up before but never really paid attention to it. Why should people use namespace? What are the advantages? I always just included the file with the extension and went on from there...
sabotai is offline   Reply With Quote
Old 03-17-2004, 03:21 AM   #20
Marc Vaughan
SI Games
 
Join Date: Oct 2000
Location: Melbourne, FL
Quote:
Originally Posted by primelord
I wish everyone made a habit of that.
Heh - its part of the coding standard at SI, looking at unformatted code drives me mad ... not clever enough to work it out in my head automatically
Marc Vaughan is offline   Reply With Quote
Old 03-17-2004, 03:26 AM   #21
Marc Vaughan
SI Games
 
Join Date: Oct 2000
Location: Melbourne, FL
Quote:
Originally Posted by Karim
Thanks for this MV. If you don't mind, I think I'm going to adopt this style as I think it will make things easier as I progress onto more difficult things.
Cool by me

As with many things there is no 'right' way to format code, over time you've find a layout which works for you and which you find easiest to read.

Indenting is the most important thing imho as this allows you to easily visually tell which parts of a function are related to particular if/switch/while statements.

I also advocate headers, decent commenting (I didn't add comments to your functions because they're relatively straight forward) and function/file headers. I've also got into the habit of putting the function name on the closing brace for a function as I find this helps when rummaging around in large code file.

In case you're interested I'd be happy to email you the coding standard I use, you can see a lot of it from the reformatting of your program - but some things aren't visible from a simple code snippet - your call entirely, as I indicated earlier htere is no 'right' way to code.
Marc Vaughan is offline   Reply With Quote
Old 03-17-2004, 03:54 AM   #22
Yossarian
High School Varsity
 
Join Date: Jul 2003
Quote:
Originally Posted by primelord
I wish everyone made a habit of that.

See... I have mixed opinions on this. Nothing pisses me off more (well some things do) than crappy unformatted, uncommented code.

But one thing that DOES piss me off more is when everybody on a project (most notably open source projects with no coding standards) adopts their own style and everytime they work on a file, they reformat it to suit themseleves.
Yossarian is offline   Reply With Quote
Old 03-17-2004, 01:05 PM   #23
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by sabotai
I've seen this brought up before but never really paid attention to it. Why should people use namespace? What are the advantages? I always just included the file with the extension and went on from there...
The advantage of namespaces is that it eliminates problems with name collisions. This is particularly at issue when you consider pre-standard third-party libraries for stuff like vectors and lists -- with the the standard versions going into the std namespace, there are no issues there with name collisions.

With the iostreams, there are a couple of big reasons to use standard rather than classical iostreams. The first is standard C++ string support in the standard iostreams (rather than char* strings, which are kludgy and error-prone). The second is that support for classical iostreams is waning -- I believe Microsoft no longer provides the classical iostream library as of VC 7.1, and if they still do supply it, I would not be surprised if they pulled it from VC 8 (aka VC 2005, aka Whidbey).
Mr. Wednesday is offline   Reply With Quote
Old 03-17-2004, 02:54 PM   #24
sabotai
General Manager
 
Join Date: Oct 2000
Location: The Satellite of Love
So, to be clear on this I guess...

if I use:

#include (iostream.h) (replace with proper notation)

I will be including the classical versions? (BTW, I'm using VC++ 6).

But if I use:

#include (iostream)
using namespace std

I will be using the standard?

(Sometimes it takes me awhile to 'get it'. )
sabotai is offline   Reply With Quote
Old 03-17-2004, 03:21 PM   #25
Raven
College Prospect
 
Join Date: Oct 2000
Location: Baltimore, MD
#include iostream (surrounded by greater than and less than signs) is the new ANSI compliant standard, and requires "using namespace std;" to be declared globally.

#include iostream.h is an older un-revised library, and doesn't require the using namespace std;

You can create your own namespaces and use them. std is just one that is written for you. I believe it just uses operator overloading to define cin, cout, endl etc..

If you wrote a namespace called Space1 you could declare it using "using namespace Space1;" - this would only be used within it's scope if you declared it within the program, or would be declared globally if you declare it before main.

by declaring using namespace std; before main, anytime you use cin cout or endl (not within the scope of say Space1) you resort back to the global defined namespace (std).

Hope that made sense. The other guys can correct me if I made a mistake somewhere.

Last edited by Raven : 03-17-2004 at 03:25 PM.
Raven is offline   Reply With Quote
Old 03-18-2004, 01:10 AM   #26
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by sabotai
So, to be clear on this I guess...

if I use:

#include (iostream.h) (replace with proper notation)

I will be including the classical versions? (BTW, I'm using VC++ 6).

But if I use:

#include (iostream)
using namespace std

I will be using the standard?

(Sometimes it takes me awhile to 'get it'. )
That's correct. The big win for you using the standard iostreams is that you can extract into a standard string, rather than having to use char*'s. Plus the point that I already mentioned, I think Microsoft will stop supporting the classical iostreams library, if they haven't already done so.

I use VC6 at work. I have both VC6 and VC7.1 at home.

Edit: Raven, I didn't see anything wrong in your explanation.

Last edited by Mr. Wednesday : 03-18-2004 at 01:11 AM.
Mr. Wednesday is offline   Reply With Quote
Old 03-18-2004, 09:19 AM   #27
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
Quote:
Originally Posted by Mr. Wednesday
Oh, and something else it appears you missed -- You're using cout, cin, and endl without a namespace qualifier and without either using them or using the std namespace. You didn't say which compiler you were using, but any self-respecting C++ compiler ought to squawk about not knowing what cin, cout, or endl are.

Edit: Or else maybe you're including ? If so, I recommend using (note the lack of extension) (the biggest reason for this is that it supports strings natively, as opposed to classical iostreams that only support char* strings), but until you do so, disregard the rest of this message since the classical iostreams came about before namespaces and thus dump everything into the global namespace.
Neither our instructor nor our text discusses namespace although cin/cout were among the first things taught. On a C++ forum I visit, namespace is one of the first things in the newbie faq, so the discussion above was very helpful.

I used &it <#iostream>. The compiler is g++ although I don't know what version.

Last edited by Karim : 03-18-2004 at 09:11 PM. Reason: removed html tags
Karim is offline   Reply With Quote
Old 03-18-2004, 10:32 AM   #28
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Don't forget that the board eats stuff between < and > (which I got up using the HTML escapes for them e.g. & lt; [without the space in between]).

Anyway, if you're using g++ and it's letting you use cin and cout without namespace qualification from <iostream>, then I'd guess it's 2.95, maybe? I think the standard library on that version still leaves a bit to be desired.

Last edited by Mr. Wednesday : 03-18-2004 at 10:33 AM.
Mr. Wednesday is offline   Reply With Quote
Old 03-18-2004, 05:57 PM   #29
Glengoyne
Grizzled Veteran
 
Join Date: Sep 2003
Location: Fresno, CA
Quote:
Originally Posted by Coffee Warlord
I officially love you Marc. Someone who formats/indents {}'s properly.

Geeze That was the only thing I didn't like about his reformatting.

I used to code with like that
function x()
{
null;
}
Just because it seemed easier to make sure my braces were matched. Then I discovered this was the grounds for a debate of religious proportions. I looked at it, and decided that if the guys who wrote the book on C. Kernighan and Ritchie were adamant that the starting curly brace belonged on the line declaring the function, that maybe it wouldn't be such a bad thing.
so I started doing it like
function x(){
null;
}

It took a couple of months for me to get used to the switch, but now the way I used to code is clearly wrong.

Regarding Yossarian's bit about everybody reformatting things to their own standards. I require that my team employs a uniform standard. Since a lot of the code they are maintaining was written by yours truly, it only makes sense that that standard be mine.


There are very few things a developer can do that pisses me off more than unindented code.
Glengoyne is offline   Reply With Quote
Old 03-18-2004, 06:44 PM   #30
Coffee Warlord
Head Coach
 
Join Date: Oct 2002
Location: Colorado Springs
Quote:
Originally Posted by Glengoyne
Geeze That was the only thing I didn't like about his reformatting.

Just try reading code with the { on the line of the call, nested about 20 times in. You'll be driven mad.
Coffee Warlord is offline   Reply With Quote
Old 03-18-2004, 10:03 PM   #31
Glengoyne
Grizzled Veteran
 
Join Date: Sep 2003
Location: Fresno, CA
Quote:
Originally Posted by Coffee Warlord
Just try reading code with the { on the line of the call, nested about 20 times in. You'll be driven mad.

Actually, I think the nesting 20 times alone would drive me mad.

I just went back and saw my original post. I am so anal about indenting, that the editor moving my "null" is really driving me nuts.
Quote:

function x()
{
null;
}
Glengoyne is offline   Reply With Quote
Old 03-18-2004, 10:07 PM   #32
Coffee Warlord
Head Coach
 
Join Date: Oct 2002
Location: Colorado Springs
Heh. Remind me to show you my latest application sometime. Last check, there's parts that nest at least 12 levels deep. And I can't do a damned thing about it to simplify it.

On a side note, I feel kinda cool. That particular app, a healthcard admissions thing (which I wrote about 90% of the code), was demoed today at Cedar Sinai Hospital, and was a hit, from what I told.
Coffee Warlord is offline   Reply With Quote
Old 03-18-2004, 10:31 PM   #33
Glengoyne
Grizzled Veteran
 
Join Date: Sep 2003
Location: Fresno, CA
Quote:
Originally Posted by Coffee Warlord
Heh. Remind me to show you my latest application sometime. Last check, there's parts that nest at least 12 levels deep. And I can't do a damned thing about it to simplify it.

On a side note, I feel kinda cool. That particular app, a healthcard admissions thing (which I wrote about 90% of the code), was demoed today at Cedar Sinai Hospital, and was a hit, from what I told.

Very nice about the demo.

Regarding "I can't do a damned thing about it.", I have a story.

About ten years ago I wrote a data loading system, it was an ugly assignment, one of those "we need this yesterday if we are to stay in business" things. Well two weeks later the system was in place. I was reasonably happy with it, but it was obviously lacking because it was very operator intensive. The requirements were rather complex, and I had an "if-else ladder" that nested pretty darned deep. It had 28 distinct outcomes. I tried and tried, but couldn't pare it down. With the time crunch I just pressed on. Over the years the code was in production, I looked with trepidation at maintaining that section of code. It was akin to voodoo.

That company was purchased, and the platform eventually scrapped. Less than a week after it was scrapped, along with my job, I went back to work for the fellow who had originally built up and sold the old company. I actually got the opportunity that all developers dream about. I got to build the whole application a second time. That particular "data loading" module included. This time around, I was given six weeks to do the job. The decision tree that I couldn't pare down below 28 brances now has 7. Talk about embarrassing.


NOTE: I am not telling you this story to say I think you are wrong. Just that it's best never to say never
Glengoyne is offline   Reply With Quote
Old 03-18-2004, 10:36 PM   #34
Coffee Warlord
Head Coach
 
Join Date: Oct 2002
Location: Colorado Springs
Oh I agree, and if I had the time to rewrite it, (and I want to anyway), I could prolly pare it down a bit.

But, it works, it's ugly, yet elegant, and it's my ticket to job security until I flat out quit in a few months. (I despise my job.)

edit: Yes, I know, writing a really complex app that only I understand and planning to jump ship soon is a very assholish thing to do. Believe me, the fuckers deserve it. Worthless hellhole of a job.

Last edited by Coffee Warlord : 03-18-2004 at 10:38 PM.
Coffee Warlord is offline   Reply With Quote
Old 03-18-2004, 10:51 PM   #35
sterlingice
Hall Of Famer
 
Join Date: Apr 2002
Location: Back in Houston!
Quote:
Originally Posted by Coffee Warlord
Heh. Remind me to show you my latest application sometime. Last check, there's parts that nest at least 12 levels deep. And I can't do a damned thing about it to simplify it.

I like to stab people like you if I see code like that.

SI
__________________
Houston Hippopotami, III.3: 20th Anniversary Thread - All former HT players are encouraged to check it out!

Janos: "Only America could produce an imbecile of your caliber!"
Freakazoid: "That's because we make lots of things better than other people!"


sterlingice is offline   Reply With Quote
Old 03-18-2004, 10:57 PM   #36
Coffee Warlord
Head Coach
 
Join Date: Oct 2002
Location: Colorado Springs
Quote:
Originally Posted by sterlingice
I like to stab people like you if I see code like that.

SI

Try building a healthcare admissions application that validates patient information, has approximatly 1200 dynamically controlled fields that store various bits of patient records, that one can alter what fields can be entered where, when, how, in what format, etc, etc, etc...without entering Recursion From Hell.
Coffee Warlord is offline   Reply With Quote
Old 03-19-2004, 12:07 AM   #37
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
Quote:
Originally Posted by Coffee Warlord
Try building a healthcare admissions application that validates patient information, has approximatly 1200 dynamically controlled fields that store various bits of patient records, that one can alter what fields can be entered where, when, how, in what format, etc, etc, etc...without entering Recursion From Hell.

At this point in my life, I eventually hope to be given the opportunity to try...
Karim is offline   Reply With Quote
Old 03-21-2004, 05:16 PM   #38
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
My personal preferance is to put function opening braces on the next line, and block statement opening braces on the same line EXCEPT WHEN the initial statement takes multiple lines, in which case I will also put the opening brace on the next line.

e.g.

void foo()
{
// ...
if (bar) {
// ...
}

if ( bar
|| baz)
{
// ...
}
}

Last edited by Mr. Wednesday : 03-21-2004 at 05:18 PM.
Mr. Wednesday is offline   Reply With Quote
Old 03-22-2004, 04:12 AM   #39
Yossarian
High School Varsity
 
Join Date: Jul 2003
do y'all use anything like Hungarian Notation?

I feel like its something I SHOULD use but I don't.... like it.
Yossarian is offline   Reply With Quote
Old 03-22-2004, 02:59 PM   #40
sabotai
General Manager
 
Join Date: Oct 2000
Location: The Satellite of Love
Not really. I use "common sense" names for my variables. Generally I don't have to look at a variable and say "I wonder if that is a float or an integer". I give it a name like StadiumAttendance. You can't have a float, so I know it's an int.

Now, if I ever work in a group, I would probably like it if there was some standard we used in naming variables. But for my personal projects, I don't bother unless I think I'm going to need an indication of what it is.
sabotai is offline   Reply With Quote
Old 03-22-2004, 03:51 PM   #41
Glengoyne
Grizzled Veteran
 
Join Date: Sep 2003
Location: Fresno, CA
I do actually use a trimmed down version of hungarian notation. I selectively use the first two letters of a variable name to indicate the datatype. Selective because I only do it if it seems questionable. I always identify variables I have passed into a function or procedure using similar notation.
Glengoyne is offline   Reply With Quote
Old 03-22-2004, 03:53 PM   #42
sterlingice
Hall Of Famer
 
Join Date: Apr 2002
Location: Back in Houston!
Quote:
Originally Posted by Glengoyne
I do actually use a trimmed down version of hungarian notation. I selectively use the first two letters of a variable name to indicate the datatype. Selective because I only do it if it seems questionable. I always identify variables I have passed into a function or procedure using similar notation.

Color me ignorant and curious. What's Hungarian notation?

SI
__________________
Houston Hippopotami, III.3: 20th Anniversary Thread - All former HT players are encouraged to check it out!

Janos: "Only America could produce an imbecile of your caliber!"
Freakazoid: "That's because we make lots of things better than other people!"


sterlingice is offline   Reply With Quote
Old 03-22-2004, 03:58 PM   #43
Glengoyne
Grizzled Veteran
 
Join Date: Sep 2003
Location: Fresno, CA
Google is your friend. And mine because it would be really hard to explain, beyond a naming convention that seeks to identify the datatypes of the variable being named. It actually goes well beyond that.

http://web.umr.edu/~cpp/common/hungarian.html
Glengoyne is offline   Reply With Quote
Old 03-22-2004, 06:29 PM   #44
Marc Vaughan
SI Games
 
Join Date: Oct 2000
Location: Melbourne, FL
Quote:
Hungarian notation?
I personally prefer not to use Hungarian notation upon projects where I have a say in the coding standard as I find it long-winded and cumbersome, however I have used it in the past and such things are largely a matter of personal preference.

There is imho no 'right' notation or layout to code, the most important thing imho is to determine a clean style which is applied consistently to a program.
Marc Vaughan is offline   Reply With Quote
Old 03-22-2004, 08:53 PM   #45
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by Yossarian
do y'all use anything like Hungarian Notation?

I feel like its something I SHOULD use but I don't.... like it.
I use it sparingly. The thing that I try to apply most consistently is prefixes to strongly indicate scoping (m_, g_). Beyond that... I'll usually stick a 'p' on pointers (including smart ones), an 'n' on integers, a 'd' on doubles, an 's' on normal strings, a bstr on BSTR-type strings, a 'c' on single characters. I don't generally go farther than that.

Also, I do keep Hungarian out of the public interface as much as I can, since it's excess clutter in Visual Studio's automatic assistance features.
Mr. Wednesday is offline   Reply With Quote
Old 03-23-2004, 12:17 AM   #46
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
Do any of you find advanced calculus to be an aid in algorithm design? Or would this be more limited to scientific and engineering applications?

Just trying to get motivated...
Karim is offline   Reply With Quote
Old 03-23-2004, 11:37 PM   #47
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
I don't know... I've taken advanced calculus, being an engineer by training, but I don't think it's really done anything for my design skills. I may be an exception, though... the only thing I really think has done anything for my design skills is the programming classes I took in school and a lot of experience. Even when I took a class in logic, I generally found that it was all pretty self-evident; I already thought that way.
Mr. Wednesday is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 09:59 AM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.