Contents
Refactor GnomeSudoku code
My random and unstructured thoughts on how sudoku code can be improved.
in SudokuNumberGrid (gsudoku.py), parameters of methods should be coordinates, not the object representing each number-box. There aren't any cases going against this now, so it just guides future changes. (But is this proper?)
SudokuGameDisplay (gsudoku.py) has too many methods.
Make (most) methods as private.
Add a method to SudokuGameDisplay to retrieve a box, instead of using __entries__[(x, y)] everywhere.
- def get_number_box (self, x, y)
then replace all __entries__
- def get_number_box (self, x, y)
- Functions/methods should have docstring, at least the newly added ones.
- Define an interface for sudoku logic.
- input: requests to update the logic
- output: signals per the result of the request.
Checke the code using Pylint
run_pylint.sh: Check the Code
The following code is much adopted from orca's.
#!/bin/bash # # Script to run pylint on the GNOME-Sudoku sources you've modified or added. # if [ "x$*" == "x" ] then FILES=`git status | egrep 'modified:|new file:' | grep '[.]py$' | awk '{ print $NF }'` echo $FILES else FILES="$*" fi echo Thank you for your attention to quality # write pylint files into a separate 'lint' dir. (test -d lint) || mkdir lint for foo in $FILES do echo OUTPUT_FILE=lint/`basename $foo .py`.pylint # no need to check if OUTPUT_FILE is newer than foo if [ -e $OUTPUT_FILE -a $OUTPUT_FILE -nt $foo ] then echo "$foo is not changed since last check" else echo Checking $foo, sending output to $OUTPUT_FILE pylint $foo > $OUTPUT_FILE 2>&1 fi grep "code has been rated" $OUTPUT_FILE done
report.sh: Get a list of status from generated .pylint files
#!/bin/bash function report { for file in `ls lint/*.pylint` do # the status is on the second line from end of file. echo -n `tail -n 2 $file | cut -f7 -d ' ' | cut -f1 -d '/'` echo -e "\t: `basename $file | cut -f1 -d '.'`" done } report | sort -n