Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Effective Python: Chapter 1 & 2

  • Item 17:
    • iter(foo) is iter(foo) – different from iter(foo) is foo?
  • Item 12:
    • Renzo disagrees
    • should we avoid else blocks.
    • "If a feature is rare and somewhat surprising, you shouldn't use it." – Akiva
    • Alternative is good: break loop out into a separate function
    • Use with comment to describe behavior.
  • Item 2:
    • double-underscore is not for private variables.
  • Item 3:
    • How to handle native strings?
      • from __future__ import unicode_literal & silence when needed (variable behavior between files (yuck))
      • lint native strings
      • have coercion functions
    • Needs engineering education
  • Item 155: Closures
    • Accessing non-locals: create a class
    • Use nonlocals as read only
    Item 21: keyword only args
    Nimisha does not recommend using **kwargs to enforce keyword-only args, because it makes the code ugly and hard to readslice
    • Is it bad that it is forgiving?
      • Sometimes it's useful anyway
      • Maybe there should be a failfast version.
  • Item 10: enumerate
    • Very useful
    • Takes initial index!  Cool!
  • Item 11: zip
    • Makes Akiva nervous, because it has weird behavior with different length strings
    • zip_longest does the longer one (padding with Nones)
  • Item 5: sliceIs it bad that it is forgiving?
  • Sometimes it's useful
  • Maybe there should be a failfast version12:
    • Renzo disagrees
    • should we avoid else blocks.
    • "If a feature is rare and somewhat surprising, you shouldn't use it." – Akiva
    • Alternative is good: break loop out into a separate function
    • Use with comment to describe behavior.
  • Item 14: Avoid None
    • not var is a source of bugs because None and 0 are both false
    • It's fairly useful for containers

...

    • (lists, dicts, strings, etc.)
  • Item 15: Closures
    • Accessing non-locals: create a class
    • Use nonlocals as read only
  • Item 17: be defensive when iterating over sequences twice.
    • iter(foo) is iter(foo) – different from iter(foo) is foo?
  • Item 21: keyword only args
    • Nimisha does not recommend using **kwargs to enforce keyword-only args, because it makes the code ugly and hard to read
      • Sometimes it's useful anyway