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


Groups > comp.lang.python > #109687

MAthematical formula terms make for terrible names in a program (was: What's good for mathematical formulas can be bad for program code (was: how to extract a variable as parameter which has index using by a for loop?))

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject MAthematical formula terms make for terrible names in a program (was: What's good for mathematical formulas can be bad for program code (was: how to extract a variable as parameter which has index using by a for loop?))
Date Thu, 09 Jun 2016 06:26:58 +1000
Lines 30
Message-ID <mailman.84.1465417626.2306.python-list@python.org> (permalink)
References <dc4d4599-05e1-4156-8ce6-66ff955d9851@googlegroups.com> <5757ddcd$0$1520$c3e8da3$5496439d@news.astraweb.com> <85eg871l65.fsf_-_@benfinney.id.au>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de Be8vmOWMlHrud8ytxSrrRQydWh5T1+EIGOWXd556hDig==
Cancel-Lock sha1:TSG1OTAnptIp/8Kxpwbqxy60Tgs=
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.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'skip:[ 20': 0.03; 'subject:code': 0.07; 'defined,': 0.09; 'meaningful': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:using': 0.09; 'subject:which': 0.09; 'wednesday': 0.15; '"b"': 0.16; '2016': 0.16; 'means.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:formula': 0.16; 'subject:make': 0.16; 'subject:program': 0.16; 'subject:variable': 0.16; 'wrote:': 0.16; 'variable': 0.18; 'do.': 0.22; "aren't": 0.22; 'names.': 0.22; 'trying': 0.22; 'code.': 0.23; 'academic': 0.23; 'this:': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'define': 0.27; 'least': 0.27; 'mathematical': 0.27; 'idea': 0.28; 'character': 0.29; 'knows': 0.32; 'apply,': 0.33; "d'aprano": 0.33; 'instead,': 0.33; 'science,': 0.33; 'steven': 0.33; 'definition': 0.34; 'attempt': 0.35; '(and': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'names': 0.38; 'someone': 0.38; 'mean': 0.38; 'means': 0.39; 'test': 0.39; 'to:addr:python.org': 0.40; 'chance': 0.60; 'your': 0.60; 'fundamental': 0.66; 'accompanying': 0.67; 'choose': 0.68; '8bit%:21': 0.70; 'advantages': 0.72; 'sole': 0.76; 'hand': 0.82; '_o__)': 0.84; 'received:125': 0.84; 'subject:formulas': 0.84; 'subject:good': 0.84; '\xe2\x80\x9cthe': 0.93
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <85eg871l65.fsf_-_@benfinney.id.au>
X-Mailman-Original-References <dc4d4599-05e1-4156-8ce6-66ff955d9851@googlegroups.com> <5757ddcd$0$1520$c3e8da3$5496439d@news.astraweb.com>
Xref csiph.com comp.lang.python:109687

Show key headers only | View raw


Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:

> On Wednesday 08 June 2016 17:31, meInvent bbird wrote:
>
> > H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))]
>
> This is a mess. I don't understand what you are trying to do. You have
> these variable names that don't mean anything, like "b" and "H2", and
> others which aren't defined, like MM. I don't understand what you are
> trying to accomplish, or the purpose of your code.

The nice thing about mathematical formulas is that one has latitude, in
the accompanying academic paper, to define at length the
single-character names. This means the formulas are briefer to write
by hand on the blackboard, and the reader can refer to the author's
extensive explanation of what the character means.

Mathematicians (and other scientists), please don't attempt to cram
meaning into single-letter names in your program code. None of the above
advantages apply, and we get only the disadvantages Steven describes.

Instead, choose meaningful names that someone who knows that meaning has
at least a better-than-random chance of remembering.

-- 
 \       “The fundamental principle of science, the definition almost, |
  `\             is this: the sole test of the validity of any idea is |
_o__)                                 experiment.” —Richard P. Feynman |
Ben Finney

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


Thread

how to extract a variable as parameter which has index using by a for loop? meInvent bbird <jobmattcon@gmail.com> - 2016-06-08 00:31 -0700
  Re: how to extract a variable as parameter which has index using by a for loop? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-08 18:56 +1000
    Re: how to extract a variable as parameter which has index using by a for loop? meInvent bbird <jobmattcon@gmail.com> - 2016-06-08 02:20 -0700
      Re: how to extract a variable as parameter which has index using by a for loop? Joonas Liik <liik.joonas@gmail.com> - 2016-06-08 12:48 +0300
      Re: how to extract a variable as parameter which has index using by a for loop? Ben Finney <ben+python@benfinney.id.au> - 2016-06-09 06:28 +1000
    MAthematical formula terms make for terrible names in a program (was: What's good for mathematical formulas can be bad for program code (was: how to extract a variable as parameter which has index using by a for loop?)) Ben Finney <ben+python@benfinney.id.au> - 2016-06-09 06:26 +1000

csiph-web