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


Groups > comp.lang.python > #21625

Re: How to break long method name into more than one line?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <sorsorday@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'advice.': 0.05; 'method,': 0.05; 'one?': 0.05; 'function,': 0.07; 'limit,': 0.07; 'programmers,': 0.07; 'arguments,': 0.09; 'failing': 0.09; 'hits': 0.09; 'hurts': 0.09; 'minus': 0.09; 'readable': 0.09; 'subject:method': 0.09; 'def': 0.13; 'meaningful': 0.13; 'class,': 0.15; 'advice,': 0.16; 'kitchen': 0.16; 'naming': 0.16; 'sticking': 0.16; 'subject:break': 0.16; 'title.': 0.16; 'utterly': 0.16; 'java': 0.21; 'memory': 0.21; 'received:209.85.210.174': 0.21; 'received:mail- iy0-f174.google.com': 0.21; 'similarly': 0.23; 'tests.': 0.23; 'string': 0.24; "people's": 0.24; 'meeting': 0.25; 'expect': 0.25; 'tests': 0.25; 'saying': 0.26; '"the': 0.26; 'testing': 0.26; 'says': 0.27; 'not.': 0.28; 'skip:" 30': 0.28; 'message- id:@mail.gmail.com': 0.29; 'convention': 0.29; 'developers.': 0.29; 'forgot': 0.29; 'url:wiki': 0.29; 'fails,': 0.30; 'fails.': 0.30; 'subject:?': 0.31; 'actually': 0.31; 'cases': 0.32; 'rest': 0.32; 'does': 0.32; "can't": 0.33; 'it.': 0.33; 'it?': 0.33; 'test': 0.34; 'rule': 0.34; 'done': 0.34; 'rather': 0.34; 'anything': 0.34; 'driven': 0.34; 'function.': 0.34; 'test.': 0.34; 'probably': 0.35; 'to:addr:python-list': 0.35; 'things': 0.35; 'subject:How': 0.35; 'technical': 0.37; 'example,': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'skip:" 10': 0.37; 'another': 0.37; 'either': 0.37; 'received:209.85': 0.38; 'enough': 0.38; 'some': 0.38; 'hold': 0.38; 'think': 0.38; 'should': 0.38; 'right,': 0.39; 'url:org': 0.39; 'clearly': 0.39; 'url:en': 0.39; 'received:209': 0.39; 'called': 0.40; 'put': 0.40; 'to:addr:python.org': 0.40; 'follow': 0.61; 'your': 0.61; 'plus': 0.63; 'alternative': 0.65; 'imagine': 0.66; 'car': 0.67; 'subject:name': 0.67; 'exact': 0.68; 'learned': 0.73; 'subject:one': 0.77; 'readability': 0.84; 'subject:long': 0.93; 'oil': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=TfIFovu/WXsKVZUzrRIsSIpKEUMSX5ziTPU39NBgziU=; b=zL5VrNsx+22W883H8HvGyBE3fEipmpGopzgMiml5Ns1deKjhaQ3vh0bBMdxBglv4rn kgIZrQFor1UFyfA15l2UeE/q7L0X2PHbpfbCVu0gcmyYa6s6jdGGU/gWupKxhFLSTFn6 QkxlCoozj8/N9RmoqyKUJOqzr18dNFppqeSUTApkctvOdIqmNXPMPH4EwgvOIEFUJrrj 50HH62mn+akuo9+ms+XIp/LUMFtt19VdeR8rxHqLpufRNbqnCAeHNqYnNKpe6q6vy07M Y215OfrCRsy3ki3IAiOUXvsecjDPdbtjZf5PsCFAEZdcYdE2/7XEInJ7Bk+EI4puaOri fUQA==
MIME-Version 1.0
Date Wed, 14 Mar 2012 13:53:27 -0700
Subject Re: How to break long method name into more than one line?
From Herman <sorsorday@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.652.1331758410.3037.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1331758410 news.xs4all.nl 6914 [2001:888:2000:d::a6]:37792
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21625

Show key headers only | View raw


I followed the rule because it was a very good advice. For example,
def test_plus_1Plus1_2(self):
If this test fails, you immediately know that it's testing the "plus"
method, with 1  and 1 as the arguments, and expect to return 2.
Sticking this rule also means your test cases are small enough, so you
clearly know what you are testing on. Most of the time, the method
name is what you first see when your test fails. Another alternative
is to put meaningful string in each of the assert, which is probably
not practical. You are right, only people who really follow the TDD
method know the good things about it. This naming rule served me very
well.

Tests method should have meaningful name, and the advice by the book
is a meaningful one. I said it's the TDD book because I forgot the
exact title. It's actually called Test Driven: TDD and Acceptance TDD
for Java Developers. I thought it should be popular enough that most
people learned TDD may have heard it also used this naming advice, but
look like i was wrong.

> *The* TDD book? There's only one? Surely not.
>
> That rule sounds utterly impractical. I can't think of anything to
> recommend it. Like any other function, method or class, tests should have
> meaningful names, but reading the name alone should not necessarily tell
> you *everything* about the function.
>
> We have "len", not "len_sequence_or_mapping_int", and similarly it is
> perfectly reasonable to have "test_len_empty" rather than
> "test_len_emptylist_emptystr_emptyunicode_emptydict_emptyset_emptytuple_zero".
>
> I expect that naming rule was invented by either people who have heard of
> test driven development, but never actually done it, or by people so
> anally-retentive that if they make seven short car trips over an hour,
> they check the tyre pressure, oil and water seven times because "the
> manual says to check before *every* trip".
>
> No offence.
>
> My advice is to moderate the naming convention of your tests with a good
> dose of common sense and aim for names which are readable rather than
> names that contain everything including the kitchen sink. Imagine you are
> in a technical meeting with some of your fellow programmers, and need to
> ask for help with a failing test. Imagine saying the name of the test
> aloud in a sentence. Does it add clarity to the discussion, or obfuscate
> it?
>
> People's short term memory can only hold so much (allegedly "seven plus
> or minus two"), and if the name itself hits that limit, you leave nothing
> left for the rest of the sentence.
>
> http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two
>
> Names should be practically, rather than conforming to some naming rule
> that hurts readability and obfuscates the tests.
>
>

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


Thread

Re: How to break long method name into more than one line? Herman <sorsorday@gmail.com> - 2012-03-14 13:53 -0700
  Re: How to break long method name into more than one line? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-15 00:07 +0000

csiph-web