Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Make it idiot-proof, and someone will breed a better idiot. -- Oliver Elphick


devel / comp.lang.python / Re: Argument name should be lowercase

SubjectAuthor
o Re: Argument name should be lowercasedn

1
Re: Argument name should be lowercase

<mailman.928.1668204463.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20294&group=comp.lang.python#20294

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Argument name should be lowercase
Date: Sat, 12 Nov 2022 11:07:31 +1300
Organization: DWM
Lines: 136
Message-ID: <mailman.928.1668204463.20444.python-list@python.org>
References: <0eba3f9d-c89c-062e-425a-54aea7216b11@DancesWithMice.info>
<a68171d8-0ef1-eeba-a96d-ffd1dbd230bb@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 3aRv7SWpYH6V3oYgDUO84g3uq4EElIFwbA1EaNmDajQg==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=nfYMd2iZ; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'def':
0.04; 'pycharm': 0.04; 'fairly': 0.05; 'indicate': 0.05;
'parameter': 0.05; 'achieved': 0.07; 'hopefully': 0.07;
'subject:name': 0.07; 'used.': 0.07; 'wanting': 0.07; '=dn': 0.09;
'code?': 0.09; 'construct': 0.09; 'designation': 0.09;
'effectively': 0.09; 'etc).': 0.09; 'example.': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'it)': 0.09; 'skip:x 10': 0.09; 'treated': 0.09; 'trivial':
0.09; 'tutorial': 0.12; '(eg': 0.16; 'above)': 0.16; 'adults':
0.16; 'anyway.': 0.16; 'applied,': 0.16; 'comparing': 0.16;
'constant': 0.16; 'database,': 0.16; 'dict': 0.16; 'does,': 0.16;
'enforcing': 0.16; 'iirc': 0.16; 'incompatible': 0.16; 'instance':
0.16; 'landed': 0.16; 'mechanisms': 0.16; 'mention,': 0.16;
'message-id:@DancesWithMice.info': 0.16; 'object,': 0.16;
'place?': 0.16; 'programmer.': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'side-
effect': 0.16; 'subsequently': 0.16; 'times,': 0.16; 'wrote:':
0.16; 'python': 0.16; 'says': 0.17; 'probably': 0.17; "can't":
0.17; 'uses': 0.19; 'to:addr:python-list': 0.20; "i've": 0.22;
'communicate': 0.22; 'maybe': 0.22; 'code': 0.23; 'idea': 0.24;
'(and': 0.25; 'python,': 0.25; 'saying': 0.25; 'behavior': 0.26;
"isn't": 0.27; 'function': 0.27; 'done': 0.28; 'expect': 0.28;
'output': 0.28; 'purpose': 0.28; 'sense': 0.28; 'thinking': 0.28;
'environment': 0.29; 'header:User-Agent:1': 0.30; 'seem': 0.31;
'takes': 0.31; 'convention': 0.31; 'effect': 0.31; 'modify': 0.31;
'module': 0.31; 'header:Organization:1': 0.31; "doesn't": 0.32;
'question': 0.32; '(as': 0.32; 'context': 0.32; 'lists,': 0.32;
'nature': 0.32; 'said,': 0.32; 'but': 0.32; "i'm": 0.33; "i'll":
0.33; 'there': 0.33; 'particular': 0.33; 'someone': 0.34; 'same':
0.34; 'header:In-Reply-To:1': 0.34; 'particularly': 0.35; 'yes,':
0.35; 'people': 0.36; 'those': 0.36; 'couple': 0.37; 'guide':
0.37; 'using': 0.37; "it's": 0.37; 'personal': 0.64;
'received:51': 0.64; 'skip:v 30': 0.64; 'widely': 0.64; 'look':
0.65; 'named': 0.65; 'day': 0.66; 'numbers': 0.67; 'back': 0.67;
'skip:e 20': 0.67; 'away': 0.67; 'matter': 0.68; 'during': 0.69;
'etc,': 0.69; 'skip:w 20': 0.69; 'within': 0.69; 'skip:f 30':
0.71; 'risk': 0.71; 'global': 0.73; 'easy': 0.74; '8bit%:100':
0.76; '....': 0.76; 'cross': 0.76; 'languages,': 0.76; 'returned':
0.81; 'reasons': 0.84; '(that': 0.84; 'admit': 0.84;
'background,': 0.84; 'comments,': 0.84; 'intentions': 0.84;
'made,': 0.84; 'peculiar': 0.84; 'preferring': 0.84; 'thus,':
0.84; 'warning': 0.84; 'avoiding': 0.91; 'convey': 0.91; 'style,':
0.91; 'aspects': 0.93
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 6AF2E6181
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1668204461;
bh=8Gpq7Qe55dAipm/OUzvIRFQXAgC4EPtkoqlqoPAcRB4=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=nfYMd2iZjgIEp+CdxHbrpnlA98k8jPKd86VMXlVQ5rVQX4y2VzbPFRvbLh2Xr41Tb
fVI3xiGso/NwerOPfPYskerQUjB3sEgUezphtSN4ylXRneZwb0PeIkWwHxxVYkxquX
7Uded9h3IRYS3VH+8tgctGWbVKshtyZVe3V2WXQlQyc9i/oFmXfuXkvqVBqtlr/ZOE
zRR8QPL3ZKmJqB4VHrV132F3twizkVVAFGiLnjqDGwg3C7q35da45pAn/Eit4CMoJX
OfHUUTBgm7KWECUHX4K2EcYvLyaxOg7GjJrODCbskpq6BZmzV1ACbK8ntymCr4Qyk+
IAEH5xU1o8wjQ==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Content-Language: en-GB
In-Reply-To: <0eba3f9d-c89c-062e-425a-54aea7216b11@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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: <a68171d8-0ef1-eeba-a96d-ffd1dbd230bb@DancesWithMice.info>
X-Mailman-Original-References: <0eba3f9d-c89c-062e-425a-54aea7216b11@DancesWithMice.info>
 by: dn - Fri, 11 Nov 2022 22:07 UTC

Thanks for the thoughts!

On 11/11/2022 21.54, dn wrote:
> PyCharm is warning against using an identifier of all upper-case letters
> as a function's parameter, saying "Argument name should be lowercase".
> (weak, code smell)
>
....
PEP-008: makes no mention, and is but a guide anyway.
(that said, if one 'breaks a rule', then a good reason should be required!)

YELLING is an email-interpretation. Does it apply to code? Particularly
as we are talking Python, where an identifier using all upper-case
letters is a convention (not a language-structure, as stated in
contributions 'here') that is widely used.

Accordingly, the purpose of the UPPER_CASE is to communicate the
read-only nature of the data-item to the programmer. Combine this with
"we're all adults here", and if someone is foolish-enough to modify a
'constant', then Python will comply - but (s)he can expect push-back
during a Code Review! So, yes, «weird to see an all-cap parameter» (I
thought so too) but isn't that effect the purpose of the convention in
the first place?

There are several aspects of Python where the 'we're all adults'
thinking must be applied, eg 'private attributes'. Given that
understanding, it doesn't seem necessary to force constant-behavior on
the parameter - although when one does, there are a couple of mechanisms
and more than several projects working on this and other aspects of
enforcing data-types and their characteristics!

That said, and with @Stefan's observations, there are many reasons why
this code is piling-up trouble - and thus, should be avoided...

> def build_product_prices_dictionary( WORKBOOK_DEFINITIONS:dict )->dict:
> ...
>     price_array = xl.iget_array(
>         file_name=WORKBOOK_DEFINITIONS[ "file_name" ],
>         ...
>
> (the function def is flagged, as above)

> As far as the function is concerned, the dict and its contents are
> constants.
> (but the dict can't be treated as a global ENV[IRONMENT] object, because
> it has to cross into the module's namespace)

By way of background, in recent times, have the habit/standardised code
'template' for config/environment-setting, which instantiates a class
from (at least) JSON/YAML files. Accordingly, the instance is named in
lower-case, and particular groups of parameters (as here) can be passed
as an extract-function/property (as a general style, I avoid long
parameter/argument lists, preferring a data-collection - which landed me
in this...).

Which re-raises the question the other way around: how does the object's
name indicate its constant/read-only nature to the reader?
"Ouch" says idealism!

Back to this case, which part of a tutorial comparing different methods
to access prices in a product-catalog[ue] (eg hard-coded dict,
flat-file, workbook, database, etc). Some members of the group are
either anti-OOP or OOP-untrained. Hence avoiding my personal 'good, old,
stand-by'.

(plus it was Veterans'/Remembrance/Liberation Day, which we don't
observe (much) here (ANZAC Day instead) and I was using some
creative-coding time to [try to] take my mind off it)

The particular @Rob and I both find it peculiar (in the same sense) but
as-above, that's (ultimately) the point of the upper-casing.

The idea of moving the workbook-definitions into that module appears to
make sense and could easily be achieved - but in the singular context of
this example. However, as a matter of style, all of an application's
environment-setting would best be done in one place - with cmdLN,
config-file(s), etc, all being combined, and with the output of a single
'authority' as its objective.

I could try to 'get away with it', but if some Apprentice takes the idea
and later uses it as a 'template', a general grumpiness will result...
(no it's not a learning-objective, but sometimes people take-away
unintended 'side effects', maybe like this).

However, in that spirit, am contemplating use of a DataClass. It will be
as easy to read as any config file, even to non-OOP-ers; has no learning
side-effect down-side (that I've spotted, as-yet); and can be 'seen' as
a instance by the workbook module (instance named using lower-case).
This, hopefully also measuring-up to @Thomas' observations of risk that
the current code's intentions be misconstrued later.

I'll admit to (idealists look away now!) not being 'above' the use of
globals, particularly?if only an ENVIRONMENT class - IIRC this
irresponsible behavior being when the environment is fairly trivial (cf
multi-layered or large numbers of 'tunable factors').

Because the ENVIRONMENT is returned to the mainline, which subsequently
uses those parameters to call the 'action' functions/methods (and know
which to call), it is not available within the import-ed module's
namespace. Hence the fall-back to passing it/the Workbook sub-set of
parameters, as an argument. (see above for normal/traditional 'solution'
to traversing namespaces)

> Is passing the dict as an argument/parameter considered to be
> incompatible with its designation as a constant?

There's an argument to be made, particularly by those from other
languages, relating to pass-by-reference, pass-by-value; which suggests
that the WORKBOOK_DEFINITIONS parameter is effectively being used on the
LHS of an assignment...

Probably 'nuff said'!

> Perhaps the style should be more enum-like, ie the dict's name in
> lower-case, with the key-named in upper case, eg
>
>     workbook_definitions[ "FILE_NAME" ]

Like @MRAB, I'm thinking that getting tangled-up in the conventions of
constant identification, cf wanting to convey the read-only nature of
the construct is unhelpful (and an unneeded headache from over-thinking).

Changing the dict-keys to upper-case encourages the 'constant/read-only'
interpretation, and might cause least distraction to the
learning/discussion/comparison objectives...

> Advice, comments, critique welcome!

--
Regards,
=dn

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor