Python Hall of Shame

From YM2149.org
Jump to navigationJump to search

roman

Lib for converting to and from roman numerals, riddled with examples of how at a granular level not to write software.

  • https://github.com/zopefoundation/roman
  • strict coding standards ineffective at filtering out bad code, though perhaps they've done enough to facilitate fixing forward
  • at least there are tests, so we can refactor with confidence
  • romanNumeralMap is not self-documenting, i would call it something like numeraltovalue and delete the useless comment
    • this embeds the subtraction logic, normally such tasks are for computers not humans
  • conversion of 0 to N may violate principle of least astonishment
  • romanNumeralPattern duplicates data already expressed in romanNumeralMap
  • tests modify sys, when argparse has api to pass in custom argv
    • and stdout, when main could be refactored to make it testable without changing stdout
    • if you really need to redirect stdout there is api in unittest to do that
    • but ideally do not modify global state at all, as any leaks can make subsequent testing invalid