Learning a New Programming Language, with Life (part 4)
While preparing a course syllabus on coding in Python, for an upcoming high school class, I remembered static analysis. I haven’t decided how soon to introduce the topic, but I thought I’d better check how my own sample program fared.
No warnings or errors from Python itself. (If there had been I would have addressed them already!).
So I installed Pylint and tried its default settings. How about that. Not zero at all!
In fact, 54 coding convention messages, 12 warnings, and 1 recommendation for refactoring.
It was easy enough to clean up whitespace issues (helped to turn on “view whitespace” in my Notepad2).
And yes, many comment lines were too long. I left-justified (but indented for Python) for easy reading.
Some of the warnings are for my “TODO” comments — an extra reminder to do, or drop, next steps I’d identified earlier. Pylint message count is now down to 2 informational messages, 28 coding convention, 13 warnings, and 1 to refactor. They are valuable for my future Python learning (and teaching):
Locally disabling unused-variable (W0612) (locally-disabled)
I disabled those warnings because I know the code needs those variables. But I’ll have to explain why.
(Pylint doesn’t forget — the 2 new informational messages remind that I’ve suppressed two warnings.)
Invalid attribute name “maxRowMain” (invalid-name)
Not just that name. Most of my object names. I’ll have to find a good object-naming convention and use it.
R: 69, 4: Too many branches (13/12) (too-many-branches)
Just today I heard a Python lecturer on YouTube say, “if you’re not refactoring, you’re not learning.” Yes, that function is the longest. Not so complex, but could be simpler and easier to understand.
Attribute ‘maxRowMain’ defined outside __init__ (attribute-defined-outside-init)
A few of those also. I will have to go back and learn again about __init__: when to use it and why.
All in all, a good learning session, and direction on what I need to learn next.
Thanks to static analysis with Pylint.