Skip to content

Common Pitfalls

Alex Sherman edited this page Jul 12, 2018 · 4 revisions

DECO was designed to be as simple as possible, but there are still a few gotchas when using it. Here's a list of some ways to try to avoid some common pitfalls.

In general

  • Keep it simple
  • Do everything with square bracket operations: obj[key] = value
  • Apply the decorators to functions in the module global namespace, not class methods

In the @concurrent decorator

  • Pass everything in, don't use global variables (may change in the future)
  • Only mutate things with square brackets, meaning avoid using the following
    • Attribute access like obj.attribute = value
    • Instance methods like list.append
    • Iteration using generators (instead pass in return value of the generator)

In the @synchronized decorator

  • Keep it simple, usually a single for loop is sufficient
  • Only call, or assign the result of @concurrent functions to indexable objects such as
  • concurrent(...)
  • result[key] = concurrent(...)
  • Never indirectly read objects that get assigned to by calls of the @concurrent function
  • You must directly call @concurrent functions by their name, calling references of @concurrent functions will confuse @synchronized

Clone this wiki locally