Review: Tips For Clean Code

Summarize skills to write clean code with fewer bugs


## Blog link: https://code.dennyzhang.com/sliding-puzzle
for (ik, jk) in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
    i2, j2 = i0+ik, j0+jk
    if i2<0 or i2 >= 2 or j2<0 or j2>=3: continue
    matrix[i0][j0], matrix[i2][j2] = matrix[i2][j2], matrix[i0][j0]
    newState = self.toString(matrix)
    if newState not in visited:
        queue.append(newState)

  • Presum
  • Scan and save to avoid 2 pass
  • Avoid unnecessary precheck

See more blog_posts.

<div style=”overflow: hidden;”>

<div style=”float: left; padding: 5px”> <a href=”https://www.linkedin.com/in/dennyzhang001“><img src=”linkedin.png” alt=”linkedin” /></a></div>

<div style=”float: left; padding: 5px”><a href=”https://github.com/DennyZhang“><img src=”github.png” alt=”github” /></a></div>

<div style=”float: left; padding: 5px”><a href=”https://www.dennyzhang.com/slack” target=”_blank” rel=”nofollow”><img src=”slack.png” alt=”slack”/></a></div>

</div>


Share It, If You Like It.

Leave a Reply

Your email address will not be published.