Re: Python (was Re: I did not inhale)

Liste des GroupesRevenir à cu shell 
Sujet : Re: Python (was Re: I did not inhale)
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.misc
Date : 29. Aug 2024, 01:23:25
Autres entêtes
Organisation : None to speak of
Message-ID : <875xrkb2iq.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Wed, 28 Aug 2024 13:29:18 -0700, Keith Thompson wrote:
But ok, I found your post and removed all the #end comments.  I found it
just as readable without them as with them.
>
You know what? You are right. That example was just too
well-structured.
>
Here’s a more dangerous one:
>
    def register_additional_standard(self, **kwargs) :
        "registers additional standard interfaces that are not automatically" \
        " installed at Connection creation time. Currently the only one is" \
        " the object-manager interface, registered with\n" \
        "\n" \
        "    «conn».register_additional_standard(managed_objects = True)\n"

That's not the conventional way to format a docstring.  If you're using
backslashes to splice lines in Python, it's likely you're doing
something wrong.

        for key in kwargs :
            if kwargs[key] :
                if key == "managed_objects" :
                    if self._managed_objects != None :

I think "is not None" is more idiomatic.

                        raise asyncio.InvalidStateError \
                          (
                            "object manager interface already registered"
                          )

You don't need the \ if you put the ( on the same line.

                    #end if
                    self.register \
                      (
                        path = "/",
                        interface = ManagedObjectsHandler(),
                        fallback = True
                      )

Again, you've decided how you want to place parentheses and you're
forcing the syntax to cater to that.  I might write that as:

                    self.register(
                        path = "/",
                        interface = ManagedObjectsHandler(),
                        fallback = True
                    )

                    self._managed_objects = {}
                else :

You leave a space between "else" and ":".  It's not wrong, but it's not
something I've ever seen.  It's likely to be just a little jarring to
readers.

                    raise TypeError("unrecognized argument keyword “%s”" % key)

Do you have a requirement to use older versions of Python that don't
support f-strings?

                #end if
            #end if
        #end for
        return \
            self

Why not just "return self"?

    #end register_additional_standard
>
versus
>
    def register_additional_standard(self, **kwargs) :
        "registers additional standard interfaces that are not automatically" \
        " installed at Connection creation time. Currently the only one is" \
        " the object-manager interface, registered with\n" \
        "\n" \
        "    «conn».register_additional_standard(managed_objects = True)\n"
        for key in kwargs :
            if kwargs[key] :
                if key == "managed_objects" :
                    if self._managed_objects != None :
                        raise asyncio.InvalidStateError \
                          (
                            "object manager interface already registered"
                          )
                    self.register \
                      (
                        path = "/",
                        interface = ManagedObjectsHandler(),
                        fallback = True
                      )
                    self._managed_objects = {}
                else :
                    raise TypeError("unrecognized argument keyword “%s”" % key)
        return self

Again, the #end comments don't make it any more readable *for me*.
I suspect that would be even more true for more experienced Python
programmers.

I was looking for quite a tricky example I remember seeing on the
ArjanCodes channel on YouTube, but I can’t find it.

In any language, if a block of code is so deeply indented that it's
confusing, you should consider refactoring it.  (Though that's not
always the answer.)

I once reviewed some C code with misleading indentation.  Depending on
the viewer's tab settings (4 vs 8 columns) it looked either like this:

    if (condition)
        this;
        that;

or like this:

    if (condition)
        this;
    that;

Of course it meant the same to the compiler.

In any language, I think it's important to use consistent indentation
that reflects the structure of the code, and to avoid mixing tabs and
spaces.  (My personal preference is to use spaces exclusively, but I'll
conform to what existing code does.)  As I've said elsethread, Python's
rules just force me to do what I would have done anyway.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
15 Aug 24 * Re: I did not inhale241Kalevi Kolttonen
16 Aug 24 `* Re: Python (was Re: I did not inhale)240Lawrence D'Oliveiro
16 Aug 24  +* Re: Python (was Re: I did not inhale)236Kaz Kylheku
16 Aug 24  i`* Re: Python (was Re: I did not inhale)235Kalevi Kolttonen
16 Aug 24  i +* Re: Python (was Re: I did not inhale)2John Ames
17 Aug 24  i i`- Re: Python (was Re: I did not inhale)1D
17 Aug 24  i +* Re: Python (was Re: I did not inhale)62Muttley
17 Aug 24  i i+* Re: Python (was Re: I did not inhale)59Dmitry A. Kazakov
17 Aug 24  i ii+* Re: Python (was Re: I did not inhale)57Lawrence D'Oliveiro
18 Aug 24  i iii`* Re: Python (was Re: I did not inhale)56Dmitry A. Kazakov
18 Aug 24  i iii +* Re: Python (was Re: I did not inhale)14Muttley
18 Aug 24  i iii i`* Re: Python (was Re: I did not inhale)13Dmitry A. Kazakov
18 Aug 24  i iii i `* Re: Python (was Re: I did not inhale)12Muttley
18 Aug 24  i iii i  +* Re: Python (was Re: I did not inhale)10Dmitry A. Kazakov
18 Aug 24  i iii i  i+* Re: Python (was Re: I did not inhale)2Kaz Kylheku
18 Aug 24  i iii i  ii`- Re: Python (was Re: I did not inhale)1Dmitry A. Kazakov
19 Aug 24  i iii i  i+- Re: Python (was Re: I did not inhale)1Lawrence D'Oliveiro
19 Aug 24  i iii i  i+- Re: Python (was Re: I did not inhale)1Muttley
25 Aug 24  i iii i  i`* Re: Python (was Re: I did not inhale)5Sebastian
25 Aug 24  i iii i  i `* Re: Python (was Re: I did not inhale)4Dmitry A. Kazakov
25 Aug 24  i iii i  i  +* Re: Python (was Re: I did not inhale)2vallor
25 Aug 24  i iii i  i  i`- Re: Python (was Re: I did not inhale)1Lawrence D'Oliveiro
25 Aug 24  i iii i  i  `- Re: Python (was Re: I did not inhale)1Lawrence D'Oliveiro
18 Aug 24  i iii i  `- Re: Python (was Re: I did not inhale)1Richard Kettlewell
18 Aug 24  i iii +* Re: Python (was Re: I did not inhale)2Kenny McCormack
18 Aug 24  i iii i`- Re: Python (was Re: I did not inhale)1Muttley
18 Aug 24  i iii +* Re: Python (was Re: I did not inhale)5Kaz Kylheku
18 Aug 24  i iii i`* Re: Python (was Re: I did not inhale)4Dmitry A. Kazakov
19 Aug 24  i iii i `* Re: Python (was Re: I did not inhale)3Kaz Kylheku
19 Aug 24  i iii i  `* Re: Python (was Re: I did not inhale)2Dmitry A. Kazakov
19 Aug 24  i iii i   `- Re: Python (was Re: I did not inhale)1Kaz Kylheku
19 Aug 24  i iii `* Re: Python (was Re: I did not inhale)34Lawrence D'Oliveiro
19 Aug 24  i iii  `* Re: Python (was Re: I did not inhale)33Dmitry A. Kazakov
19 Aug 24  i iii   +* Re: Python (was Re: I did not inhale)22David Brown
19 Aug 24  i iii   i`* Re: Python (was Re: I did not inhale)21Dmitry A. Kazakov
19 Aug 24  i iii   i +* Re: Python (was Re: I did not inhale)4Muttley
19 Aug 24  i iii   i i`* Re: Python (was Re: I did not inhale)3Dmitry A. Kazakov
19 Aug 24  i iii   i i +- Re: Python (was Re: I did not inhale)1Muttley
30 Sep 24  i iii   i i `- Re: Python (was Re: I did not inhale)1Bozo User
19 Aug 24  i iii   i +* Re: Python (was Re: I did not inhale)12David Brown
20 Aug 24  i iii   i i`* Re: Python (was Re: I did not inhale)11Dmitry A. Kazakov
20 Aug 24  i iii   i i +* Re: Python (was Re: I did not inhale)3Lawrence D'Oliveiro
20 Aug 24  i iii   i i i`* Re: Python (was Re: I did not inhale)2Dmitry A. Kazakov
21 Aug 24  i iii   i i i `- Re: Python (was Re: I did not inhale)1Lawrence D'Oliveiro
20 Aug 24  i iii   i i `* Re: Python (was Re: I did not inhale)7David Brown
20 Aug 24  i iii   i i  `* Re: Python (was Re: I did not inhale)6Dmitry A. Kazakov
20 Aug 24  i iii   i i   +* Re: Python (was Re: I did not inhale)2David Brown
20 Aug 24  i iii   i i   i`- Re: Python (was Re: I did not inhale)1Dmitry A. Kazakov
21 Aug 24  i iii   i i   `* Re: Python (was Re: I did not inhale)3Lawrence D'Oliveiro
21 Aug 24  i iii   i i    `* Re: Python (was Re: I did not inhale)2Dmitry A. Kazakov
22 Aug 24  i iii   i i     `- Re: Python (was Re: I did not inhale)1Lawrence D'Oliveiro
19 Aug 24  i iii   i `* Re: Python (was Re: I did not inhale)4Keith Thompson
19 Aug 24  i iii   i  `* Re: Python (was Re: I did not inhale)3John Ames
20 Aug 24  i iii   i   +- Re: Python (was Re: I did not inhale)1Muttley
20 Aug 24  i iii   i   `- Re: Python (was Re: I did not inhale)1Stefan Ram
19 Aug 24  i iii   +* Re: Python (was Re: I did not inhale)8Lawrence D'Oliveiro
19 Aug 24  i iii   i`* Re: Python (was Re: I did not inhale)7Dmitry A. Kazakov
19 Aug 24  i iii   i +* Re: Python (was Re: I did not inhale)2Keith Thompson
19 Aug 24  i iii   i i`- Re: Python (was Re: I did not inhale)1Dmitry A. Kazakov
20 Aug 24  i iii   i `* Re: Python (was Re: I did not inhale)4Lawrence D'Oliveiro
20 Aug 24  i iii   i  `* Re: Python (was Re: I did not inhale)3Dmitry A. Kazakov
20 Aug 24  i iii   i   +- Re: Python (was Re: I did not inhale)1Lawrence D'Oliveiro
20 Aug 24  i iii   i   `- Re: Python (was Re: I did not inhale)1D
21 Aug 24  i iii   `* Re: Python (was Re: I did not inhale)2vallor
21 Aug 24  i iii    `- Re: Python (was Re: I did not inhale)1Lawrence D'Oliveiro
18 Aug 24  i ii`- Re: Python (was Re: I did not inhale)1Muttley
18 Aug 24  i i`* Re: Python (was Re: I did not inhale)2David Brown
18 Aug 24  i i `- Re: Python (was Re: I did not inhale)1Muttley
18 Aug 24  i `* Re: Python (was Re: I did not inhale)170David Brown
18 Aug 24  i  +* Re: Python (was Re: I did not inhale)2Keith Thompson
19 Aug 24  i  i`- Re: Python (was Re: I did not inhale)1David Brown
20 Aug 24  i  `* Re: Python (was Re: I did not inhale)167Kalevi Kolttonen
20 Aug 24  i   +* Re: Python (was Re: I did not inhale)3Muttley
20 Aug 24  i   i+- Re: Python (was Re: I did not inhale)1Lew Pitcher
20 Aug 24  i   i`- Re: Python (was Re: I did not inhale)1Kalevi Kolttonen
20 Aug 24  i   +* Re: Python (was Re: I did not inhale)160David Brown
20 Aug 24  i   i`* Re: Python (was Re: I did not inhale)159Kalevi Kolttonen
21 Aug 24  i   i +* Re: Python (was Re: I did not inhale)151David Brown
21 Aug 24  i   i i+* Re: Python (was Re: I did not inhale)132Muttley
21 Aug 24  i   i ii`* Re: Python (was Re: I did not inhale)131David Brown
21 Aug 24  i   i ii `* Re: Python (was Re: I did not inhale)130Muttley
21 Aug 24  i   i ii  `* Re: Python (was Re: I did not inhale)129David Brown
21 Aug 24  i   i ii   `* Re: Python (was Re: I did not inhale)128Muttley
21 Aug 24  i   i ii    `* Re: Python (was Re: I did not inhale)127David Brown
22 Aug 24  i   i ii     `* Re: Python (was Re: I did not inhale)126Muttley
22 Aug 24  i   i ii      +* Re: Python (was Re: I did not inhale)6D
22 Aug 24  i   i ii      i+* Re: Python (was Re: I did not inhale)4Muttley
22 Aug 24  i   i ii      ii`* Re: Python (was Re: I did not inhale)3D
22 Aug 24  i   i ii      ii `* Re: Python (was Re: I did not inhale)2Lew Pitcher
22 Aug 24  i   i ii      ii  `- Re: Python (was Re: I did not inhale)1Muttley
22 Aug 24  i   i ii      i`- Re: Python (was Re: I did not inhale)1David Brown
22 Aug 24  i   i ii      `* Re: Python (was Re: I did not inhale)119David Brown
22 Aug 24  i   i ii       +* Re: Python (was Re: I did not inhale)110Muttley
26 Aug 24  i   i ii       i`* Re: Python (was Re: I did not inhale)109John Ames
26 Aug 24  i   i ii       i +- Re: Python (was Re: I did not inhale)1Muttley
26 Aug 24  i   i ii       i `* Re: Python (was Re: I did not inhale)107Lawrence D'Oliveiro
26 Aug 24  i   i ii       i  +* Re: Python (was Re: I did not inhale)103John Ames
27 Aug 24  i   i ii       i  i+- Re: Python (was Re: I did not inhale)1Lawrence D'Oliveiro
27 Aug 24  i   i ii       i  i+- Re: Python (was Re: I did not inhale)1Sebastian
27 Aug 24  i   i ii       i  i`* Re: Python (was Re: I did not inhale)100Richard Kettlewell
27 Aug 24  i   i ii       i  i +* Re: Python (was Re: I did not inhale)94Bart
28 Aug 24  i   i ii       i  i `* Re: Python (was Re: I did not inhale)5Sebastian
26 Aug 24  i   i ii       i  +* Re: Python (was Re: I did not inhale)2Bart
27 Aug 24  i   i ii       i  `- Re: Python (was Re: I did not inhale)1Kaz Kylheku
22 Aug 24  i   i ii       `* Re: Python (was Re: I did not inhale)8Lawrence D'Oliveiro
21 Aug 24  i   i i`* Re: Python (was Re: I did not inhale)18Lawrence D'Oliveiro
21 Aug 24  i   i `* Re: Python (was Re: I did not inhale)7Muttley
21 Aug 24  i   `* Re: Python (was Re: I did not inhale)3Lawrence D'Oliveiro
16 Aug 24  `* Re: Python (was Re: I did not inhale)3Kalevi Kolttonen

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal