Deutsch English Français Italiano |
<vapnu2$3v4l8$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.unix.shell,comp.unix.programmer,comp.lang.misc Subject: Re: Python (was Re: I did not inhale) Date: Thu, 29 Aug 2024 14:01:05 +0200 Organization: A noiseless patient Spider Lines: 215 Message-ID: <vapnu2$3v4l8$1@dont-email.me> References: <uu54la$3su5b$6@dont-email.me> <va4aut$3q4g0$1@dont-email.me> <va4fbr$3qvij$1@dont-email.me> <va5108$3tmmd$1@dont-email.me> <va51ok$3tqr9$1@dont-email.me> <va5ec2$3vluh$1@dont-email.me> <va6q4g$c1a7$1@dont-email.me> <va6rpa$c6bg$1@dont-email.me> <va6se9$cb8e$1@dont-email.me> <20240826083330.00004760@gmail.com> <vaises$2k7o6$2@dont-email.me> <20240826155113.000005ba@gmail.com> <wwvo75eicla.fsf@LkoBDZeT.terraraq.uk> <vak9k9$2ujrs$1@dont-email.me> <valgpu$34s18$1@dont-email.me> <87y14hd4bk.fsf@nosuchdomain.example.com> <valnei$35rt8$2@dont-email.me> <87ikvlcs7i.fsf@nosuchdomain.example.com> <vamclm$3c4ke$1@dont-email.me> <87ttf4bdcx.fsf@nosuchdomain.example.com> <vaoaak$3l470$3@dont-email.me> <875xrkb2iq.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 29 Aug 2024 14:01:07 +0200 (CEST) Injection-Info: dont-email.me; posting-host="737b96d1a4f94365fbc2f60b2f2e5810"; logging-data="4166312"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/44F5rtMgZ/s1tDEhu5lvQj1d5kOIAsdA=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:csapkzPMd/PHSc2jF4BKVBKxOWU= In-Reply-To: <875xrkb2iq.fsf@nosuchdomain.example.com> Content-Language: en-GB Bytes: 9560 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. ========== REMAINDER OF ARTICLE TRUNCATED ==========