viff

changeset 903:105bd2138d86

Added small hints section.
author Martin Geisler <mg@daimi.au.dk>
date Tue, 09 Sep 2008 10:35:36 +0200
parents 86cd18e04c56
children 27eb22c25f4b
files doc/coding-style.txt
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/doc/coding-style.txt	Thu Sep 04 17:06:37 2008 +0200
     1.2 +++ b/doc/coding-style.txt	Tue Sep 09 10:35:36 2008 +0200
     1.3 @@ -51,3 +51,29 @@
     1.4  coding style.
     1.5  
     1.6  .. _Twisted: http://twistedmatrix.com/
     1.7 +
     1.8 +Hints for indexed variables
     1.9 +---------------------------
    1.10 +
    1.11 +When the code is based on a mathematical text, one often sees lots of
    1.12 +*b*\ :sub:`i` variables. A nice way to deal with those in code is to
    1.13 +consider them part of a list called ``b`` and create it like this::
    1.14 +
    1.15 +  b = [self.rt.prss_share_random(Zp, binary=True)
    1.16 +       for _ in range(k)]
    1.17 +
    1.18 +It is not a good idea to name the list ``bi`` since that is what you
    1.19 +would want to call the elements in the list::
    1.20 +
    1.21 +  x = [bi * bi for bi in b]
    1.22 +
    1.23 +If the index of the current element is needed::
    1.24 +
    1.25 +  number = sum([2**i * bi for i, bi in enumerate(b)])
    1.26 +
    1.27 +If you want to work with the list by index, you get the nice
    1.28 +correspondence between *b*\ :sub:`i` and ``b[i]``::
    1.29 +
    1.30 +  z = 0
    1.31 +  for in range(k)
    1.32 +    z += b[i] + x[k - i]