LWN: Comments on "Python identifiers, PEP 8, and consistency" https://lwn.net/Articles/877115/ This is a special feed containing comments posted to the individual LWN article titled "Python identifiers, PEP 8, and consistency". en-us Fri, 31 Oct 2025 15:30:11 +0000 Fri, 31 Oct 2025 15:30:11 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Python identifiers, PEP 8, and consistency https://lwn.net/Articles/880021/ https://lwn.net/Articles/880021/ moxfyre <div class="FormattedComment"> Puhleez! That should be…<br> <p> `from __future__ import foolish_consistency`<br> </div> Thu, 30 Dec 2021 03:45:19 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/878549/ https://lwn.net/Articles/878549/ nye <div class="FormattedComment"> <font class="QuotedText">&gt; At the other extreme of the range, there&#x27;s PHP to consider :-)</font><br> <p> If anything, I would say that PHP is *closer* to the consistent end of the range than Python is, at least if you consider its trajectory. Many of the changes of the last four or five years have been in the direction of improving consistency - sometimes in ways that are similar to those rejected in this Python discussion. Notable are certain cases where &quot;backwards compatibility&quot; was the only defence for otherwise indefensible behaviour, like the weirdness in `implode()` - PHP is definitely more willing than post-3.0 Python to break compatibility in favour of correctness, and consistency is increasingly a part of that.<br> <p> Granted there are a lot of standard library functions which are simple wrappers around C functions, and in those cases they normally opt for &quot;consistency&quot; with the C function rather than with each other. I personally wish it had fewer of these very shallow wrappers, especially for very widely used libraries like cURL, but I can see the argument.<br> </div> Mon, 13 Dec 2021 17:19:43 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877412/ https://lwn.net/Articles/877412/ smitty_one_each <div class="FormattedComment"> This conversation gets at diminishing returns.<br> <p> Yeah, `from datetime import datetime` is an eyesore, but it makes an important point about the history of the project.<br> <p> The newbie marks a turning point when the basics of the language/library are understood, and delving into the &#x27;hysterical raisins&#x27; why things are the way they are becomes of interest.<br> <p> This sort of totalitarian cleanup would be appropriate for a Python4, when the GIL is relaxed, and the Promised Land entered.<br> </div> Thu, 02 Dec 2021 13:47:20 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877340/ https://lwn.net/Articles/877340/ buck <div class="FormattedComment"> Indeed, this got me thinking of the &quot;six&quot; module and wondering whether an &quot;eight&quot; module would allow one to opt into PEP 8-ified naming, but your post has me sold on `import __foolish_consistency__` instead.<br> </div> Thu, 02 Dec 2021 06:32:43 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877303/ https://lwn.net/Articles/877303/ NYKevin <div class="FormattedComment"> It is obvious that there is a tradeoff. The problem is, I&#x27;ve seen people say &quot;there is a tradeoff, therefore the status quo is fine.&quot; But that&#x27;s a non sequitur. The fact that a tradeoff exists has nothing to do with the question of whether or not the status quo is at the right point of that tradeoff. Arguments should be grounded in the specific facts of each individual case, and you almost never see that when people start bringing out the &quot;foolish consistency&quot; quote.<br> </div> Wed, 01 Dec 2021 19:39:09 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877298/ https://lwn.net/Articles/877298/ NYKevin <div class="FormattedComment"> Having spent a fair amount of time working in a case-insensitive Pascal-like language (hello, Skyrim modding!), this is actually a lot less painful than it sounds.* However, your capitalization will get irregular if you don&#x27;t have a standard style and some kind of automated enforcement mechanism. If your language supports variable shadowing (which Papyrus does not, but Python obviously does), then it might be more painful because you will have a larger set of variables potentially &quot;in scope&quot; and there is greater potential for collisions, which the compiler will not warn you about.<br> <p> <font class="QuotedText">&gt; That doesn’t do much for studlyCaps versus underscores, I admit. I guess if you must have aliases, they should be declared specially so that linter tools (and the compiler’s own diagnostics) can help the programmer. They should not just be a bunch of wrapper functions.</font><br> <p> You don&#x27;t need wrapper functions in Python. Python functions and classes are first-class objects, so you can just do this:<br> <p> def original_name(args...): ...<br> <p> alias = original_name<br> <p> If a linter is unable to figure that out, it needs to be redesigned from the ground up.<br> <p> * Except for the case-insensitive strings. Those are terrible.<br> </div> Wed, 01 Dec 2021 19:35:45 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877292/ https://lwn.net/Articles/877292/ pj I feel like people who want that level of consistency could make a `pep8ed` module that would be just aliases. <p> <pre> from pep8ed.datetime import DateTime, TimeDelta </pre> <p> they could even write code to monkeypatch such aliases in so all they'd have to do is something like: <p> <pre> from pep8er import pep8ify import datetime pep8ify(datetime) now = datetime.DateTime.now() </pre> <p> ...once this kind of thing is done, it arguably could go live with stdlib. It'd be cute to be able to <p> <pre> import __foolish_consistency__ </pre> <p> to enable such a feature :) Wed, 01 Dec 2021 17:24:19 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877290/ https://lwn.net/Articles/877290/ jmaa <div class="FormattedComment"> Remember when Tony Hoare called the null pointer a billion dollar mistake?<br> <p> In the spirit of quantifying mistakes, let&#x27;s try a Fermat-style equation for how much money and time might be wasted in migrating codebases to use new consistent identifiers, in a scenario where the original names are deprecated. I pulled these numbers from my ass, but they sound plausible:<br> <br> 1 000 000 000 lines of actively maintained Python code<br> 0.001 incidence ratio of deprecation<br> 1 minute per incidence<br> 40$ hourly programmer wage<br> <p> So that&#x27;s around 16666 wasted work hours, and $666666 down the drain. This only counts the direct migration work, not all of the political drama and dread related to backwards-incompatible version upgrades, or the costs incurred by botched migrations.<br> </div> Wed, 01 Dec 2021 17:04:49 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877241/ https://lwn.net/Articles/877241/ martin.langhoff <div class="FormattedComment"> _Too much_ consistency can asphyxiate. Python has generally struck a good balance at the consistent and tidy end of the spectrum.<br> <p> That&#x27;s one of the points where having a lead everyone trusts to make calls in these gray zones is key.<br> <p> At the other extreme of the range, there&#x27;s PHP to consider :-)<br> <p> <p> </div> Wed, 01 Dec 2021 14:43:53 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877233/ https://lwn.net/Articles/877233/ epa <div class="FormattedComment"> I like the approach taken by Haskell, where types and constructors must start with a capital letter, and ordinary functions must not. <br> <p> In Python, one answer might be to make the language case insensitive. Wait, hear me out… suppose you can declare particular source files or classes to be case insensitive, so callers can use any case. The library code can then be made consistent. An automatic linter or cleaner will convert code to the canonical form used in the library. If you do that cleanup, you can then go back to strict case matching. Or you might choose to keep working in case-insensitive mode and get warnings, rather than hard errors, on mismatches. Effectively making it a code style issue rather than some non-negotiable semantic question, which it doesn’t need to be. <br> <p> That doesn’t do much for studlyCaps versus underscores, I admit. I guess if you must have aliases, they should be declared specially so that linter tools (and the compiler’s own diagnostics) can help the programmer. They should not just be a bunch of wrapper functions. <br> </div> Wed, 01 Dec 2021 07:44:39 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877232/ https://lwn.net/Articles/877232/ NYKevin <div class="FormattedComment"> <font class="QuotedText">&gt; Angelico, along with others in the thread, pointed to the first section of PEP 8, which is titled &quot;A Foolish Consistency is the Hobgoblin of Little Minds&quot; (from the Ralph Waldo Emerson quote). That section makes it clear that the PEP is meant as a guide; consistency is most important at the function and module level, with project-level consistency being next in line. Any of those is more important than rigidly following the guidelines. As Angelico put it: &quot;When a style guide becomes a boat anchor, it&#x27;s not doing its job.&quot;</font><br> <p> I hate this section of the PEP. You can cite it as justification for literally any violation of PEP 8, regardless of whether there&#x27;s a good reason to violate PEP 8. In my experience, it&#x27;s very uncommon for people citing this section of the PEP to actually explain the underlying justification for making an exception, even though that very section explicitly states that &quot;Consistency with this style guide is important.&quot;<br> <p> As for consistency within the standard library, or within individual modules... that&#x27;s a terrible argument. The standard library is wholly inconsistent with itself, and the collections module is an excellent example of this inconsistency. This is actually an argument *in favor* of picking a specific style and standardizing on it, rather than continuing with the status quo. Of course, if you have to pick one style, you should probably pick the PEP 8 style, and so this is not a refutation at all.<br> </div> Wed, 01 Dec 2021 02:45:21 +0000 Python identifiers, PEP 8, and consistency https://lwn.net/Articles/877224/ https://lwn.net/Articles/877224/ iabervon <div class="FormattedComment"> I think it&#x27;s useful to use lowercase words for some classes that are generic structure elements, to distinguish them from classes with business logic or application-specific semantics. I think it ought to be TimeDelta to indicate that it&#x27;s got a particular interpretation but float to indicate that it could be lots of different things from a percentage to a number of seconds. Classes where you can have literals or special syntax for creating them or anything you get out of JSON would be lowercase. If you have a field or variable with a lowercase type, or a function that returns a lowercase type or takes lowercase type arguments, you should think about how your naming, comments, and documentation explain how to interpret the value. If a function returns a CamelCase type, the type&#x27;s documentation should provide that explanation instead, and the function&#x27;s documentation can just talk about which one it returns or how it is constructed.<br> <p> Of course, by this metric, readers of PEP 8 are almost certainly not going to be naming a class that ought to be lowercase, and few packages outside of the standard library&#x27;s builtins would even do it (exceptions being, perhaps, construct, numpy, and pandas). But I think it would be good (as a retcon) to specify for educational purposes. &quot;If I tell you it&#x27;s a pathlib.Path, you have some idea what to expect; if I tell you it&#x27;s a str, you really don&#x27;t.&quot;<br> </div> Tue, 30 Nov 2021 23:25:02 +0000