refactoring code before(right side), after(left side) #Python #RefactoringCode context : The functions check if the 'value' can be inserted in a particular position(x, y) in its row or column , in a game of sudoku.
Refactoring: The first if condition checks if the position (x, y) is possible in the board. We observe that it doesn't tell to much directly and have to read the if conditions to understand. So we move it out of function and put it in a lambda function 'in_board'.
Now the code expresses itself and can be reused in other functions too. Second refactoring is of the loop which compares each value in row/column of (x, y) and match it with the value. return False if value is present and true if not present.
This could be refactored by using all builtin function which makes the code more expressive.
United States Tendencias
- 1. Knicks 11.9K posts
- 2. Landry Shamet 1,145 posts
- 3. #AEWDynamite 20.1K posts
- 4. Philon 1,664 posts
- 5. Brandon Williams N/A
- 6. #CMAawards 5,080 posts
- 7. #Survivor49 3,592 posts
- 8. #AEWCollision 8,033 posts
- 9. Vucevic 4,159 posts
- 10. Vooch N/A
- 11. Blazers 4,057 posts
- 12. #mnwild N/A
- 13. Derik Queen 3,072 posts
- 14. Dubon 3,592 posts
- 15. Nick Allen 2,116 posts
- 16. Wallstedt N/A
- 17. Simon Walker N/A
- 18. Donovan Mitchell 3,868 posts
- 19. Josh Hart 2,476 posts
- 20. Bristow 1,059 posts
Something went wrong.
Something went wrong.