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 الاتجاهات
- 1. Dodgers 780K posts
- 2. World Series 414K posts
- 3. Blue Jays 156K posts
- 4. Yamamoto 243K posts
- 5. Nigeria 790K posts
- 6. Good Sunday 44.4K posts
- 7. jungkook 352K posts
- 8. Will Smith 54.2K posts
- 9. #River 5,053 posts
- 10. Yankees 16.6K posts
- 11. Miguel Rojas 47K posts
- 12. Carlos Manzo 324K posts
- 13. #Worlds2025 44.2K posts
- 14. Baseball 175K posts
- 15. #T1WIN 15.4K posts
- 16. Kendrick 19.3K posts
- 17. Kershaw 40.8K posts
- 18. Vladdy 23.7K posts
- 19. Mets 11.6K posts
- 20. Dave Roberts 15.6K posts
Something went wrong.
Something went wrong.