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


Groups > comp.lang.python > #18643

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!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <darcy@druid.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'passes': 0.05; 'stuff.': 0.05; 'none:': 0.07; 'python': 0.08; '425': 0.09; 'dict': 0.09; 'none):': 0.09; 'optionally': 0.09; 'variables,': 0.09; 'am,': 0.12; 'def': 0.13; 'float': 0.13; '__init__': 0.16; 'email name:patrick': 0.16; 'im:': 0.16; 'naming': 0.16; 'self.data': 0.16; 'superfluous': 0.16; 'testcases': 0.16; 'useless.': 0.16; 'wrote:': 0.18; 'voting': 0.18; 'seems': 0.20; 'to:2**1': 0.21; 'wrote': 0.22; 'header:In-Reply-To:1': 0.22; 'wonder': 0.23; 'pep': 0.23; 'though.': 0.23; 'values.': 0.23; 'index': 0.24; 'subject:please': 0.24; 'tests': 0.25; 'code': 0.25; 'classes': 0.26; 'missed': 0.28; 'not.': 0.28; 'coding': 0.28; 'script': 0.28; 'far.': 0.29; 'looks': 0.29; "i've": 0.31; 'values': 0.32; 'adds': 0.32; 'cases': 0.32; 'yet': 0.32; 'programmers': 0.32; 'pretty': 0.32; "can't": 0.32; 'header:User-Agent:1': 0.33; 'this.': 0.33; 'to:addr:python-list': 0.34; 'it.': 0.34; 'things': 0.34; 'subject:project': 0.34; 'test.': 0.34; '(not': 0.35; 'list.': 0.35; 'to:no real name:2**1': 0.35; 'test': 0.35; 'however,': 0.36; 'good.': 0.37; 'sequence': 0.37; 'skip:" 10': 0.37; 'but': 0.37; 'run': 0.37; 'received:192': 0.37; 'skip:_ 10': 0.37; 'could': 0.37; 'some': 0.38; 'fail': 0.39; 'possible.': 0.39; "i'd": 0.39; 'should': 0.39; 'why': 0.39; 'help': 0.39; "it's": 0.40; 'to:addr:python.org': 0.40; 'received:192.168': 0.40; 'url:net': 0.60; 'range': 0.61; 'more': 0.61; 'your': 0.61; 'love': 0.62; 'stop': 0.63; 'afraid': 0.63; 'you.': 0.63; 'here': 0.65; 'subject:your': 0.80; 'average': 0.80; 'lose': 0.84; '07:10': 0.84; 'contiguous': 0.84; 'democracy': 0.84; 'received:98.158': 0.84; 'stock.': 0.84; 'ugly,': 0.84
Date Sat, 07 Jan 2012 08:04:02 -0500
From D'Arcy Cain <darcy@druid.net>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0
MIME-Version 1.0
To python-list@python.org, patrick@bierans.de
Subject Re: your feedback to my first project please
References <1067747504.957862.1325938220403.JavaMail.open-xchange@email.1und1.de
In-Reply-To <1067747504.957862.1325938220403.JavaMail.open-xchange@email.1und1.de
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
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.4510.1325941452.27778.python-list@python.org> (permalink)
Lines 79
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325941452 news.xs4all.nl 6877 [2001:888:2000:d::a6]:49857
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18643

Show key headers only | View raw


On 12-01-07 07:10 AM, patrick@bierans.de wrote:
> It's my first script in python and I'd like to know if my way of coding
> so far is right and if YOU have some little tips for me
> or if you can point my nose on some things I've missed so far.

Looks pretty good overall.  I have a little armchair quarterbacking
for you.

The main thing I wonder is why a dict to store values.  You index by
a contiguous range of ints so why not use a list.  __init__ becomes
this.  Note I also lose those superfluous underscores.

   def __init__(self, dim, default=0):
     self.data = [default] * dim
     self.pos = 0
     self.dim = dim

Here is how I would write avg() (not _avg)

   def _avg(self):
     """Calculates the average of all values currently in stock.
        This also includes the default values not yet overwritten."""

     return sum(self.data)/self.dim

You could drop your inout method with this change to avg():

   def _avg(self, value = None):
     """Calculates the average of all values currently in stock.
        This also includes the default values not yet overwritten.
        Optionally adds a new value."""

     if value is not None:
       self.in(value)

     return sum(self.data)/self.dim

I am not sure how you get a float out of this though.  You may
want to set self.dim to float(dim) in __init__.

> I've read a lot of the official documentation - even some of the weired
> but cool stuff. And I also read some PEPs like the PEP 8. And I'd love to
> go for TDD. But feedback would help me on my way.

I don't know why TDD seems to be more popular with Python programmers
than others but I do recommend as much of that as possible.

> - How is my code formatting?

Good.

> I know the TestCases are ugly, I still have no feeling for it. :(

Test cases don't have to be pretty, just extensive.  What I can't tell
is whether you wrote the tests first or not.  The sequence should be;

  1. Write the test
  2. Run the test to prove it fails
  3. Write code until test passes
  4. Stop

Steps 2 and 4 are particularly important.  Step 2 assures that you
have a real test.  A test that can't fail is useless.  Step 4 assures
that you never add code without a test.

However, don't be afraid to add extra tests at any time.

> - What about my coding style in general?
> Is my naming of variables, classes and methods/functions stupid?

I would just ease up on the underscores.

Looks like you are on the right track though.

-- 
D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
IM: darcy@Vex.Net

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


Thread

Re: your feedback to my first project please D'Arcy Cain <darcy@druid.net> - 2012-01-07 08:04 -0500

csiph-web