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. Nick Mangold 18.5K posts
- 2. Saquon 8,722 posts
- 3. Vini 67.4K posts
- 4. #FlyEaglesFly 4,547 posts
- 5. #ElClasico 82.1K posts
- 6. Go Birds 7,276 posts
- 7. Mike Green 1,035 posts
- 8. Lamine 138K posts
- 9. Tyler Nubin N/A
- 10. #Hardrockbet 3,609 posts
- 11. Andy Dalton 2,241 posts
- 12. Fermin 41K posts
- 13. Madrid 419K posts
- 14. Barca 145K posts
- 15. Ravens 26.5K posts
- 16. Xabi 33.5K posts
- 17. #AskFFT 1,223 posts
- 18. Mooney 3,139 posts
- 19. #BillsMafia 4,595 posts
- 20. Mbappe 125K posts
Something went wrong.
Something went wrong.