Tuesday, December 6, 2016

HackerRank - Matrix Rotation (Series 5 of 5)

Dec. 6, 2016

Introduction:
Julia has more talent now after she attended her new school - stackexchange.com code review for code review on stackexchange.com. She did post two questions, and the first one, she learned a few things. One most important one is "Do not use abstract variable name. Do not let user guess what the variable name does".

Julia spent 30 minutes to review the practice in April 2016, and then, she went through the code, found the bug.

Last practice scoring 8 of 80:
(more than 1 hour, still having bugs, score 8.89/ wrong answer)
https://gist.github.com/jianminchen/57572227dafe939060f7cc81b193cd9b

Code review done by Julia on Dec. 6, 2016
1. Do not use abstract variable names. Please use meaningful name
line 16, s1
line 17, sA
line 20, T
line 22, arr
line 27, aA

In the function rotateArrayOneStepAntiClockwise
line 53, cnt
int 53, arr
line 71, ci
line 73, startR
line 74, startC
line 75, endR
line 76, endC
line 78, tmpVal
line 81, i
line 85, i,
line 89, i,
line 94, i,

2. function name should use
rotateArrayOneStepAntiClockwise
Should use PascalCased
RotateArrayOneStepAntiClockwise

"In C#, method names should be PascalCased, not camelCased"

Workout:
c# solution: pass all test cases
https://gist.github.com/jianminchen/6fabef7436097552e35633a549b0268a

Discussion:

Use meaningful variable name - The code is much easy to understand, therefore, static analysis should be much more easy.

For example, Julia reviewed the code on Dec. 6, 2016, line 53 cnt, the variable name is not meaningful, so she decided to replace the name using "steps". Line 114, there is some calculation, so in order to avoid timeout, there is actual steps taken < strip size. So, she decided to add a new variable name on line 114, called actualSteps. Just those two changes, Julia fixed the bug she could not fix in April, 2016 over 1 hour.




No comments:

Post a Comment