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

Liste des GroupesRevenir à cl misc 
Sujet : Re: Python (was Re: I did not inhale)
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.misc
Date : 29. Aug 2024, 14:01:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vapnu2$3v4l8$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 29/08/2024 02:23, Keith Thompson wrote:
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.
So why not try to write /all/ your code in a well-structured manner, so that you don't feel the need to add these "#end" comments?

>
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.
Agreed 100%.

 
         for key in kwargs :
             if kwargs[key] :
                 if key == "managed_objects" :
                     if self._managed_objects != None :
 I think "is not None" is more idiomatic.
I don't know if that is true or not that it is more idiomatic - I would certainly be happy with either.
     def register_additional_standard(self, managed_objects) :
         """
         registers additional standard interfaces that are not automatically
         installed at Connection creation time. Currently the only one is
         the object-manager interface, registered with
         «conn».register_additional_standard(managed_objects = True)
         """
         if 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 = {}
         return self
(Usenet formatting is limited to 72 characters standard - modern programming is not.  Overly long lines are not good, but a hard limit at, say, 80 characters is a bad idea.)

 
                         raise asyncio.InvalidStateError \
                           (
                             "object manager interface already registered"
                           )
 You don't need the \ if you put the ( on the same line.
Line continuation characters in Python are usually an indicator of poor formatting, or an unhealthy obsession with line length limits.

 
                     #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.
I personally prefer a space before the colon in Python.  It is probably less common than no space, but it is certainly not a rare habit.

 
                     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"?
Indeed.

 
     #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 don't know if I am more experienced than you in Python (I may have been using Python for longer, but you may have worked with it more), but I would say that the "#end" comments directly detract from readability.

 
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.)
Agreed.

 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.
As someone who works with C programming that is often high-reliability (not necessarily safety critical, but updates after production can be very expensive), both are unacceptable in the kind of coding standards we use.  I accept single-line "if" statements without braces if they are simple enough, otherwise braces are required.
if (condition) return;
if (condition) {
return;
} else {
break;
}
If the "true" statement is on a separate line, braces are /always/ required for my type of code.  Almost any indentation is done inside a pair of braces - it keeps everything simple and consistent, and it's easy to spot mistakes.

 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.
 
I do the same.  (Well, I use tabs more than spaces, but otherwise I do the same.)

Date Sujet#  Auteur
29 Mar 24 * Command Languages Versus Programming Languages669Lawrence D'Oliveiro
29 Mar 24 +- Re: Command Languages Versus Programming Languages1candycanearter07
29 Mar 24 +* Re: Command Languages Versus Programming Languages170Muttley
29 Mar 24 i+- Re: Command Languages Versus Programming Languages1Josef Möllers
29 Mar 24 i+* Re: Command Languages Versus Programming Languages9Richard Kettlewell
29 Mar 24 ii`* Re: Command Languages Versus Programming Languages8Muttley
29 Mar 24 ii `* Re: Command Languages Versus Programming Languages7Kaz Kylheku
29 Mar 24 ii  `* Re: Command Languages Versus Programming Languages6Muttley
29 Mar 24 ii   `* Re: Command Languages Versus Programming Languages5Kaz Kylheku
30 Mar 24 ii    `* Re: Command Languages Versus Programming Languages4Muttley
30 Mar 24 ii     +- Re: Command Languages Versus Programming Languages1Janis Papanagnou
30 Mar 24 ii     `* Re: Command Languages Versus Programming Languages2Kaz Kylheku
1 Apr 24 ii      `- Re: Command Languages Versus Programming Languages1Muttley
29 Mar 24 i`* Re: Command Languages Versus Programming Languages159John Ames
29 Mar 24 i +* Re: Command Languages Versus Programming Languages157Muttley
29 Mar 24 i i+- Re: Command Languages Versus Programming Languages1John Ames
29 Mar 24 i i+* Re: Command Languages Versus Programming Languages151Kaz Kylheku
29 Mar 24 i ii`* Re: Command Languages Versus Programming Languages150Muttley
29 Mar 24 i ii +* Re: Command Languages Versus Programming Languages148Kaz Kylheku
29 Mar 24 i ii i+* Re: Command Languages Versus Programming Languages4David W. Hodgins
29 Mar 24 i ii ii+* Re: Command Languages Versus Programming Languages2Johanne Fairchild
30 Mar 24 i ii iii`- Re: Command Languages Versus Programming Languages1David W. Hodgins
30 Mar 24 i ii ii`- Re: Command Languages Versus Programming Languages1Janis Papanagnou
30 Mar 24 i ii i`* Re: Command Languages Versus Programming Languages143Muttley
30 Mar 24 i ii i `* Re: Command Languages Versus Programming Languages142Kaz Kylheku
1 Apr 24 i ii i  `* Re: Command Languages Versus Programming Languages141Muttley
1 Apr 24 i ii i   +* Re: Command Languages Versus Programming Languages139Johanne Fairchild
1 Apr 24 i ii i   i`* Re: Command Languages Versus Programming Languages138Muttley
1 Apr 24 i ii i   i +- Re: Command Languages Versus Programming Languages1Kaz Kylheku
2 Apr 24 i ii i   i `* Re: Command Languages Versus Programming Languages136Johanne Fairchild
2 Apr 24 i ii i   i  +* Re: Command Languages Versus Programming Languages115ram@zedat.fu-berlin.de (Stefan Ram)
2 Apr 24 i ii i   i  i+* Re: Command Languages Versus Programming Languages112Stefan Ram
2 Apr 24 i ii i   i  ii+* Re: Command Languages Versus Programming Languages110Stefan Ram
3 Apr 24 i ii i   i  iii`* Re: Command Languages Versus Programming Languages109Lawrence D'Oliveiro
3 Apr 24 i ii i   i  iii `* Re: Command Languages Versus Programming Languages108David Brown
3 Apr 24 i ii i   i  iii  +- Re: Command Languages Versus Programming Languages1Lawrence D'Oliveiro
3 Apr 24 i ii i   i  iii  +- Re: Command Languages Versus Programming Languages1John Ames
3 Apr 24 i ii i   i  iii  `* Re: Command Languages Versus Programming Languages105Keith Thompson
3 Apr 24 i ii i   i  iii   +* Re: Command Languages Versus Programming Languages100Richard Kettlewell
4 Apr 24 i ii i   i  iii   i+- Re: Command Languages Versus Programming Languages1Muttley
4 Apr 24 i ii i   i  iii   i`* Re: Command Languages Versus Programming Languages98Stefan Ram
5 Apr 24 i ii i   i  iii   i `* Re: Command Languages Versus Programming Languages97Lawrence D'Oliveiro
5 Apr 24 i ii i   i  iii   i  +* Re: Command Languages Versus Programming Languages49Muttley
5 Apr 24 i ii i   i  iii   i  i+* Re: Command Languages Versus Programming Languages3candycanearter07
5 Apr 24 i ii i   i  iii   i  ii`* Re: Command Languages Versus Programming Languages2Muttley
6 Apr 24 i ii i   i  iii   i  ii `- Re: Command Languages Versus Programming Languages1candycanearter07
6 Apr 24 i ii i   i  iii   i  i`* Re: Command Languages Versus Programming Languages45Lawrence D'Oliveiro
6 Apr 24 i ii i   i  iii   i  i `* Re: Command Languages Versus Programming Languages44Alan Bawden
6 Apr 24 i ii i   i  iii   i  i  +* Re: Command Languages Versus Programming Languages13Lawrence D'Oliveiro
8 Apr 24 i ii i   i  iii   i  i  i`* Re: Command Languages Versus Programming Languages12John Ames
9 Apr 24 i ii i   i  iii   i  i  i `* Re: Command Languages Versus Programming Languages11Lawrence D'Oliveiro
9 Apr 24 i ii i   i  iii   i  i  i  +* Re: Command Languages Versus Programming Languages9John Ames
9 Apr 24 i ii i   i  iii   i  i  i  i`* Re: Command Languages Versus Programming Languages8Richard Kettlewell
9 Apr 24 i ii i   i  iii   i  i  i  i +* Re: Command Languages Versus Programming Languages2Janis Papanagnou
9 Apr 24 i ii i   i  iii   i  i  i  i i`- Re: Command Languages Versus Programming Languages1Richard Kettlewell
9 Apr 24 i ii i   i  iii   i  i  i  i `* Re: Command Languages Versus Programming Languages5David Brown
9 Apr 24 i ii i   i  iii   i  i  i  i  `* Re: Command Languages Versus Programming Languages4Lawrence D'Oliveiro
9 Apr 24 i ii i   i  iii   i  i  i  i   `* Re: Command Languages Versus Programming Languages3David Brown
10 Apr 24 i ii i   i  iii   i  i  i  i    `* Re: Command Languages Versus Programming Languages2Lawrence D'Oliveiro
10 Apr 24 i ii i   i  iii   i  i  i  i     `- Re: Command Languages Versus Programming Languages1Kaz Kylheku
9 Apr 24 i ii i   i  iii   i  i  i  `- Re: Command Languages Versus Programming Languages1Kaz Kylheku
6 Apr 24 i ii i   i  iii   i  i  +* Re: Command Languages Versus Programming Languages3Kaz Kylheku
6 Apr 24 i ii i   i  iii   i  i  i`* Re: Command Languages Versus Programming Languages2David Brown
6 Apr 24 i ii i   i  iii   i  i  i `- Re: Command Languages Versus Programming Languages1Muttley
6 Apr 24 i ii i   i  iii   i  i  +- Re: Command Languages Versus Programming Languages1candycanearter07
6 Apr 24 i ii i   i  iii   i  i  `* Re: Command Languages Versus Programming Languages26Muttley
7 Apr 24 i ii i   i  iii   i  i   +* Re: Command Languages Versus Programming Languages22Alan Bawden
8 Apr 24 i ii i   i  iii   i  i   i`* Re: Command Languages Versus Programming Languages21Muttley
8 Apr 24 i ii i   i  iii   i  i   i `* Re: Command Languages Versus Programming Languages20David Brown
8 Apr 24 i ii i   i  iii   i  i   i  `* Re: Command Languages Versus Programming Languages19Muttley
8 Apr 24 i ii i   i  iii   i  i   i   +* Words to the wise (Was: Command Languages Versus Programming Languages)2Kenny McCormack
8 Apr 24 i ii i   i  iii   i  i   i   i`- Re: Words to the wise (Was: Command Languages Versus Programming Languages)1Muttley
8 Apr 24 i ii i   i  iii   i  i   i   `* Re: Command Languages Versus Programming Languages16Kaz Kylheku
8 Apr 24 i ii i   i  iii   i  i   i    +* Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)9Kenny McCormack
9 Apr 24 i ii i   i  iii   i  i   i    i`* Re: Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)8Janis Papanagnou
9 Apr 24 i ii i   i  iii   i  i   i    i +- Re: Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)1D
9 Apr 24 i ii i   i  iii   i  i   i    i `* Re: Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)6candycanearter07
9 Apr 24 i ii i   i  iii   i  i   i    i  `* Re: Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)5Janis Papanagnou
9 Apr 24 i ii i   i  iii   i  i   i    i   +- Re: Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)1candycanearter07
10 Apr 24 i ii i   i  iii   i  i   i    i   `* Re: Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)3Lawrence D'Oliveiro
10 Apr 24 i ii i   i  iii   i  i   i    i    +- Re: Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)1Chris Elvidge
10 Apr 24 i ii i   i  iii   i  i   i    i    `- Re: Phrases that should be banned on Usenet (Was: Command Languages Versus Programming Languages)1candycanearter07
9 Apr 24 i ii i   i  iii   i  i   i    `* Re: Command Languages Versus Programming Languages6Muttley
9 Apr 24 i ii i   i  iii   i  i   i     +- Re: Command Languages Versus Programming Languages1Kaz Kylheku
9 Apr 24 i ii i   i  iii   i  i   i     +- Re: Command Languages Versus Programming Languages1Janis Papanagnou
9 Apr 24 i ii i   i  iii   i  i   i     `* Re: Command Languages Versus Programming Languages3Muttley
9 Apr 24 i ii i   i  iii   i  i   i      `* Re: Command Languages Versus Programming Languages2John Ames
9 Apr 24 i ii i   i  iii   i  i   i       `- Re: Command Languages Versus Programming Languages1Muttley
8 Apr 24 i ii i   i  iii   i  i   +- [meta] Re: Command Languages Versus Programming Languages1Janis Papanagnou
10 Apr 24 i ii i   i  iii   i  i   `* Re: Command Languages Versus Programming Languages2Keith Thompson
10 Apr 24 i ii i   i  iii   i  i    `- Re: Command Languages Versus Programming Languages1Kenny McCormack
5 Apr 24 i ii i   i  iii   i  `* Re: Command Languages Versus Programming Languages47Janis Papanagnou
5 Apr 24 i ii i   i  iii   i   +* Re: Command Languages Versus Programming Languages27Stefan Ram
6 Apr 24 i ii i   i  iii   i   i+* Re: Command Languages Versus Programming Languages4Muttley
7 Apr 24 i ii i   i  iii   i   ii`* Re: Command Languages Versus Programming Languages3Lawrence D'Oliveiro
8 Apr 24 i ii i   i  iii   i   ii `* Re: Command Languages Versus Programming Languages2Muttley
9 Apr 24 i ii i   i  iii   i   ii  `- Re: Command Languages Versus Programming Languages1Lawrence D'Oliveiro
6 Apr 24 i ii i   i  iii   i   i+- Re: Command Languages Versus Programming Languages1Janis Papanagnou
6 Aug 24 i ii i   i  iii   i   i`* Re: Command Languages Versus Programming Languages21Sebastian
7 Aug 24 i ii i   i  iii   i   i `* Re: Command Languages Versus Programming Languages20Lawrence D'Oliveiro
7 Aug 24 i ii i   i  iii   i   i  +* Re: Command Languages Versus Programming Languages3Kaz Kylheku
8 Aug 24 i ii i   i  iii   i   i  +* Re: Command Languages Versus Programming Languages4Andreas Eder
25 Aug 24 i ii i   i  iii   i   i  `* Re: Command Languages Versus Programming Languages12Sebastian
5 Apr 24 i ii i   i  iii   i   +- Re: Command Languages Versus Programming Languages1Kaz Kylheku
6 Apr 24 i ii i   i  iii   i   `* Re: Command Languages Versus Programming Languages18Lawrence D'Oliveiro
3 Apr 24 i ii i   i  iii   `* Re: Command Languages Versus Programming Languages4David Brown
2 Apr 24 i ii i   i  ii`- Re: Command Languages Versus Programming Languages1Kaz Kylheku
2 Apr 24 i ii i   i  i`* Re: Command Languages Versus Programming Languages2Kaz Kylheku
2 Apr 24 i ii i   i  `* Re: Command Languages Versus Programming Languages20Lawrence D'Oliveiro
1 Apr 24 i ii i   `- Re: Command Languages Versus Programming Languages1Lawrence D'Oliveiro
1 Apr 24 i ii `- Re: Command Languages Versus Programming Languages1Andreas Eder
29 Mar 24 i i+- Re: Command Languages Versus Programming Languages1Christian Weisgerber
30 Mar 24 i i+* Re: Command Languages Versus Programming Languages2David Brown
30 Sep 24 i i`- Re: Command Languages Versus Programming Languages1Bozo User
29 Mar 24 i `- Re: Command Languages Versus Programming Languages1Kaz Kylheku
29 Mar 24 +* Re: Command Languages Versus Programming Languages473Johanne Fairchild
29 Mar 24 +* Re: Command Languages Versus Programming Languages2David Brown
29 Mar 24 +* Re: Command Languages Versus Programming Languages15Lawrence D'Oliveiro
30 Mar 24 +* Re: Command Languages Versus Programming Languages3Dmitry A. Kazakov
30 Sep 24 `* Re: Command Languages Versus Programming Languages4Bozo User

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal