Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18642

Re: your feedback to my first project please

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'stuff.': 0.05; 'method,': 0.07; 'suite.': 0.07; 'python': 0.08; '__future__': 0.09; 'also:': 0.09; 'assert': 0.09; 'false,': 0.09; 'integers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'settled': 0.09; 'trailing': 0.09; 'variables,': 0.09; 'def': 0.13; '"from': 0.16; 'assertion': 0.16; 'email name:patrick': 0.16; 'enough?': 0.16; 'hint': 0.16; 'naming': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'red,': 0.16; 'underscore': 0.16; 'underscore.': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'rewrite': 0.18; '(most': 0.21; 'appropriate': 0.22; 'division': 0.23; 'from:addr:web.de': 0.23; "shouldn't": 0.23; 'tests.': 0.23; 'keyword': 0.24; 'subject:please': 0.24; 'traceback': 0.24; 'code': 0.25; 'classes': 0.26; 'import': 0.27; 'coding': 0.28; "who's": 0.28; 'script': 0.28; 'looks': 0.29; 'class': 0.29; 'generally': 0.30; 'seem': 0.30; 'values': 0.32; 'cases': 0.32; "won't": 0.33; 'header:X-Complaints-To:1': 0.33; 'to:addr:python- list': 0.34; 'last):': 0.34; 'safely': 0.34; 'subject:project': 0.34; 'changing': 0.35; 'test': 0.35; 'post': 0.36; 'file': 0.36; 'example,': 0.37; 'good.': 0.37; 'variables': 0.37; 'but': 0.37; 'run': 0.37; 'except': 0.37; 'think': 0.37; 'skip:_ 10': 0.37; 'could': 0.37; 'doing': 0.38; 'using': 0.38; 'received:org': 0.38; 'some': 0.38; 'correctly': 0.39; "i'd": 0.39; "it's": 0.40; 'to:addr:python.org': 0.40; 'your': 0.61; 'full': 0.62; 'leading': 0.62; 'afraid': 0.63; 'internet': 0.64; 'free': 0.64; 'warm': 0.64; 'here.': 0.66; 'subject:your': 0.80; 'confidence': 0.82; '1/2': 0.84; '10)': 0.84; 'sum': 0.89; 'regret': 0.91; 'seriously,': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: your feedback to my first project please
Date Sat, 07 Jan 2012 13:59:46 +0100
Organization None
References <499.26273427463$1325938350@news.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p50849e43.dip.t-dialin.net
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4509.1325941199.27778.python-list@python.org> (permalink)
Lines 77
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325941199 news.xs4all.nl 6913 [2001:888:2000:d::a6]:48008
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18642

Show key headers only | View raw


patrick@bierans.de wrote:

>    It&#39;s my first script in python and I&#39;d like to know if my way
>    of coding <br/>

A warm welcome and a grumpy "please post in plain-text" ;)

>    I am settled - so you can go full on. ;)

You seem to be sure you won't regret that ;)

>    - What about my coding style in general?

Looks good.

>    &#160; Is my naming of variables, classes and methods/functions stupid?

> def __init__(self, dim_, default_=0):

No. Except for the trailing underscore. I think "dim" is a keyword in 
Basic...

>    - Do my test cases cover enough? Are they unelegant?

Don't use assert, use the appropriate method, like self.assertEquals(...).
Generally your test cases test the wrong stuff. An attribute's leading 
underscore is a good hint that you shouldn't inspect its value in your 
tests. For example, to get some confidence that the internal variables are 
initialised correctly you could do

class TestAverageStack(unittest.TestCase):
    def test(self):
        a = AverageStack(10)
        self.assertEquals(a.inout(100), 10)

That way you remain free to completely rewrite the AverageTest 
implementation without changing the test suite.

> Can I write some variables in the assertion messages? I found
> some code in the internet using % and ` but it is not working here.

You must be doing it wrong.

>>> assert False, "who's afraid of %s, %s, and %s?" % ("red", "yellow", 
"blue")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError: who's afraid of red, yellow, and blue?

>    - Do you have some performance improvements for my class? It will have
>    to run at highest performance.

Rewrite it in C ;) Seriously, have a look at collections.deque; if you need 
to support only integers you can also safely store the sum and add new 
values and remove outdated ones without risking that errors accumulate.

>                 for i in range(self._dim):
>                         _sum += self._data[i]
>                         _count += 1
>                 return _sum / _count

You need "from __future__  import division":

>>> 1/2
0
>>> from __future__ import division
>>> 1/2
0.5

Also:

>>> d = {1:10, 2:20, 3:30}
>>> sum(d.itervalues())
60

That's all folks...

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: your feedback to my first project please Peter Otten <__peter__@web.de> - 2012-01-07 13:59 +0100

csiph-web