Code Review Comments

Started by
16 comments, last by Alpha_ProgDes 11 years, 1 month ago

We have a process where every commit gets code reviewed and graded. I've had some good ones come my way and these were all rated as 'F' in the American grading scale. These are all real, so I hope someone gets a chuckle out of this. Keep in mind that we are a purely C++ shop.


   void SetX(int iNewX) { iX = iNewX; }

Comment: int iNewX needs to be const.


float fMinDistance = 1.0e10f;  // Some arbitrary large distance

Comment: This value is too large for a float. Use a double.


char szFilename[STR_LENGTH];

Comment: szFilename needs to be szFileName!!!!! (note: !!!!! is not exaggerated)


glPushMatrix();
...
glPopMatrix();

Comment: I don't know anything about OpenGL, but even I can see this is stupid!


// Foo is a POD type
struct Foo {
  Foo() : x(0), y(0) {}
  ...

Comment: POD types can't be structs.

Comment: What does this even mean?

OK, I have paraphrased some of the comments, but they are real. Feel free to troll this thread for your own code review horrors.

Advertisement

I'm not sure which fails worse. The code or the comments......

Beginner in Game Development?  Read here. And read here.

 

I'm not sure which fails worse. The code or the comments......

As far as code goes, in case your referring to the char* szFilename part, I fixed that.

Well I usually define floating-point infinity as 1e20 in prototype code if the actual value is too difficult to reach (e.g. no INFINITY macro, and you have to type a complicated templated expression that you usually get wrong the first time.. thank you type abstraction!). 1e10 is a bit low though.. depending on uses.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Doesn't (1.0f/0.0f) do the trick?

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

Doesn't (1.0f/0.0f) do the trick?

Not if floating point exceptions are enabled...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Comment: szFilename needs to be szFileName!!!!! (note: !!!!! is not exaggerated)

Filename can be a single world, both variants are widely used.

Comment: I don't know anything about OpenGL, but even I can see this is stupid!

Based on those two lines?


// Foo is a POD type
struct Foo {
  Foo() : x(0), y(0) {}
  ...
Comment: POD types can't be structs.
Comment: What does this even mean?

Foo is not a POD type, but not for the reasons you mentioned.

Foo is not a POD type, but not for the reasons you mentioned.

Huh? It has neither a user-defined copy constructor nor destructor.

A default constructor does not prevent a class/struct from being a POD type.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

A default constructor does not prevent a class/struct from being a POD type.

Frankly I'm not sure anymore. Quoting from wikipedia: 'Moreover, a POD class must be an aggregate, meaning it has no user-declared constructors', I'm not sure if declaring a defualt constructor falls under user-declared constructors.

Frankly I'm not sure anymore. Quoting from wikipedia: 'Moreover, a POD class must be an aggregate, meaning it has no user-declared constructors', I'm not sure if declaring a defualt constructor falls under user-declared constructors.

Hmm. Now I'm confused too. Did this behaviour change in C++11?
struct MyPOD {
	int x, y;

	MyPOD() : x(0), y(0) {}
};

union MyUnion {
	int a;
	MyPOD pod;
};

int main() {
}
Clang with -std=c++11 compiles this just fine, but without -std=c++11 it gives me an error.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement