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 Trendy
- 1. Northern Lights 32.3K posts
- 2. #DWTS 48.9K posts
- 3. #Aurora 6,625 posts
- 4. Justin Edwards 1,945 posts
- 5. Louisville 16.6K posts
- 6. Andy 59.7K posts
- 7. #RHOSLC 6,047 posts
- 8. #OlandriaxHarpersBazaar 4,185 posts
- 9. Lowe 12.3K posts
- 10. Creighton 1,790 posts
- 11. Oweh 1,948 posts
- 12. Kentucky 24.9K posts
- 13. JT Toppin N/A
- 14. Gonzaga 2,339 posts
- 15. Elaine 40.1K posts
- 16. Celtics 12K posts
- 17. #Illini 1,136 posts
- 18. Robert 98.6K posts
- 19. Dylan 30.5K posts
- 20. Jordan Walsh N/A
Something went wrong.
Something went wrong.