Changes between Version 33 and Version 34 of DjangoSpecifications/Core/Threading


Ignore:
Timestamp:
04/26/08 14:02:33 (7 years ago)
Author:
mrts
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DjangoSpecifications/Core/Threading

    v33 v34  
    245245
    246246As a matter of style, the read-only ones should really be tuples, not lists -- the 'say what you mean' idiom: if it shouldn't be modified, don't let it be by making it a tuple. Tuples are also marginally more efficient speed- and space-wise. There is a slight semantic distinction between lists and tuples though http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constant_lists/ . But as there are no constant lists in Python, tuples are the only way to be const-correct.
     247
     248== Class attributes ==
     249
     250Class attributes are shared between instances and thus between threads as well
     251(as module-level classes are just global class objects).
     252
     253The behaviour is similar to globals: in similar manner to the global keyword in
     254functions, explicit class specifier `foo.__class__.bar` is required for setting
     255class variable `bar` from instance `foo`, otherwise a instance scope variable
     256will be created that hides the class scope variable.
     257
     258(As this may not be obvious, let me illustrate it:)
     259{{{
     260>>> class Foo(object): bar = 1
     261...
     262>>> f = Foo()
     263>>> f.bar = 2
     264>>> Foo.bar
     2651
     266>>> f.bar
     2672
     268>>> f.__class__.bar
     2691
     270}}}
     271
     272As with globals,
     273 1. class variables that are assigned to when the class is defined and never modified later (THREAD-SAFE),
     274 1. mutable class level data structures (lists and dictionaries, also instances) that are assigned to when the class is defined but whose elements are modified in methods and that are accessed without using the `__class__` keyword (NOT THREAD-SAFE),
     275 1. class variables assigned to in methods by using the `__class__` keyword (NOT THREAD-SAFE),
     276
     277Metaclasses -- think through the implications.
Back to Top