Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107526
| From | Michael Selik <michael.selik@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How much sanity checking is required for function inputs? |
| Date | 2016-04-24 01:38 +0000 |
| Message-ID | <mailman.19.1461461927.32212.python-list@python.org> (permalink) |
| References | (6 earlier) <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C21A3.5090507@icloud.com> <CAGgTfkPZZkKiMeS=2bke-qooGDC0_cegE2TDhiubPN4-nNmcZg@mail.gmail.com> |
On Sat, Apr 23, 2016 at 9:31 PM Christopher Reimer <
christopher_reimer@icloud.com> wrote:
> On 4/21/2016 10:25 PM, Stephen Hansen wrote:
> >
> > Why not, 'color in ("black", "white")'?
>
> Checkers seems popular around here. What if I want to change "white" to
> "red," as red and black is a common color scheme for checkers. Do I
> change a single constant variable or replace all the occurrences in the
> files?
>
Why so many files? Python can easily support thousands of lines in a file.
If it's just one file any text editor can do a quick find-replace.
That said, it's easy to make some global ``red = 'red'``.
Some of these constants are shortcuts. Instead of writing slice(0, 16)
> or slice(48, 64), and getting the two confused, I write
> const['board_bottom'] or const['board_top'], respectively, when I want
> to pull the correct set of positions from coordinates list.
>
Why hide these things in a dict ``const`` instead of just making them
top-level variables in the module themselves? ``board_top = slice(48,
64)``
> That said, if you're wanting to share constants across different parts
> > of your code, use a module.
>
Or just use one file to keep things easier. But, yes, I agree a module of
constants is appropriate for bigger projects.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How much sanity checking is required for function inputs? Michael Selik <michael.selik@gmail.com> - 2016-04-24 01:38 +0000
csiph-web