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

04/26/08 14:02:33 (8 years ago)



  • DjangoSpecifications/Core/Threading

    v33 v34  
    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 . But as there are no constant lists in Python, tuples are the only way to be const-correct.
     248== Class attributes ==
     250Class attributes are shared between instances and thus between threads as well
     251(as module-level classes are just global class objects).
     253The behaviour is similar to globals: in similar manner to the global keyword in
     254functions, explicit class specifier `` is required for setting
     255class variable `bar` from instance `foo`, otherwise a instance scope variable
     256will be created that hides the class scope variable.
     258(As this may not be obvious, let me illustrate it:)
     260>>> class Foo(object): bar = 1
     262>>> f = Foo()
     263>>> = 2
     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),
     277Metaclasses -- think through the implications.
Back to Top