Homework 2: grade report
·
Annoyance:!!
o
Debug folder: -5%!!!
o
Cannot
compile: sln and vcproj in
the same folder, why? -2%
·
Testing: in general
worked REALLY WELL!
o
Runs
the entire hw with an
invalid file name! -2%
o
100x1
significant difference: -2%
§
Process
left/right pixels before swap
§
If
only one column same pixel gets processed twice
o
Significant
difference for simple test image: between 5 to 10%
o
Efficiency:
§
Flip
image by creating a new image: flip in place!
§
Re-reading
the original image multiple times instead of passing it around as a parameter
o
Memory
leak:
§
Forget
to Deallocate after WriteImage,
before ReadImage again
·
Coding Style:
o
INDENTATION!!
Come on!!
o
Use
of const:
§
const int kRedModify = 17; // naming convention
o
Use
of function:
§
Two
purposes:
·
Code-ReUse: notice when you are doing cut/paste
·
Readability:
when code looks messy or too long (e.g., > 30 lines without a function)
§
Function
should do one thing:
·
FlipImage(image &theImage, int flat);
o
If
int = 0, flip horizontally, 1-flip vertically, 2-flip
diagonally … BAD IDEA!
·
byte
ComputeColorChannel(const
pixel &p, int flat);
o
if int
=0, compute red, 1-compute green, 2-compute blue … BAD IDEA!
o
OK
to assign a pixel to another
§
All
primitive data types!
o
Syntax:
§
const image &;
§
image
const &; ß never seen this
before, don't do this
o
Use
variables when you are using an expression in more than one place!!
§
if
(r + (p.r % kRed) < MAX)
t.r = r + (p.r % kRed)
§
for
(int i = 0; i<col; i++)
image[col-i-1] = AnotherImage[col-i-1];
§
BAD
BAD BAD
o
Use
of {} in main():
main() {
{ my code … }
}
§
I
did this to illustrate a point! DO NOT do this in general!
o
Convention
for instance variable!
§
Decide
on one and follow!!
o
Awkward
coding:
if (a > 0)
continue;
else
total++;
§
Instead
do this:
if (a <= 0)
total++;
o
Passing int by value:
§
const int& parm
§
int parm