~george-edison55/audataserver-proxy/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# The 60 second guide to being Pythonic, whatever that means

 - ## Write documentation as you go along

    - The first lone string in every method and class is called a "docstring".
      You can use it to explain *how to use* the method (not how it works).

        def f(x):
            ''' square x '''
            return x**2

 - ## Take the time to read PEP8

   These are the most important points it makes:

    - Two blank lines after top-level functions and classes,
      one blank line after methods. Sprinkle blank lines sparingly

    - Classes are UpperCamelCase, functions are underscore_separated_lowercase
      Don't mix the two.

    - Indentation is always four spaces. Don't be a hero. ;-)

    - Lines may never be longer than 79 characters.
      You can always insert a line break in between parantheses

        print(this_line_is_long(so_break(
            "it down", "at the parantheses")))

    - Always put spaces around operators (excepting perhaps "-a" and "~a")

        DON'T:  (x<<n)|(x>>(32-n))
        DO:     (x << n) | (x >> (32 - n))

    - **Install the "pep8" programm and run your code through it constantly**

 - ## Use advanced language features

    - Instead of writing "if x == False", write "if not x" or "if x"

    - Don't build a list if you don't have to, use lazy evaluation

      - Instead of "[f(x) for x in data]", write "(f(x) for x in data)",    
        these can be nested. f(x) will only be calculated when you actually
        get the item

    - **Carefully check the *standard library*. It's likely the code you're
      writing already ships with python, is written in C, and by someone
      with more computer science degrees than you can shake a stick at**

      For example: You will very probably never have to write a
      sorting algorithm in python. Use sorted(my_iterable) instead

Okay, 60 seconds was a bit optimistic.