On Sun, May 12, 2013 at 9:33 PM, Raymond Hettinger <raymond.hettinger@gmail.com> wrote:
On May 9, 2013, at 3:29 AM, Piotr Duda <duda.piotr@gmail.com> wrote:
Animals = Enum('Animals', 'dog cat bird') which violates DRY
This is a profound misreading of DRY which is all about not repeating big chunks of algorithmic logic.
DRY, like most heuristics, is about making mistakes less likely. Mistakes are likely with huge chunks of repeated logic, because people are inclined to fix things at only one location. Mistakes are likely with the above because it is conceptually only one location, but syntactically two -- and doing something different in the second location is a mistake that the compiler won't catch. The problem with
Animals = Enum('Animals', 'dog cat bird')
is that you might accidentally type
Animals = Enum('Animal', 'dog cat bird') or Anmals = Enum('Animals', 'dog cat bird')
instead. -jJ