I mean, you literally wrote:
[Steven D'Aprano]
To me, "visual flow of code" is the way it flows down and across the page, not the shape of the
individual words.
So it sounded a lot like you were.
[Steven D'Aprano]
I'm disputing your claim that the presence of a
all-caps CONSTANT somewhere on a page full of lower and mixed case code
"destroys the visual flow of code".
Maybe I was being a little hyperbolic, but it depends on degree. If every other line of code has LOGGER.debug(...) or STATSD_EMITER.count(...) in it, then it tends to out-shout the code you're trying to read.
[Steven D'Aprano]
The rest of your comment is a distraction.
Like going on a rant about one of my sources contrast ratios and font choices?
[Steven D'Aprano]
When we read, we don't actually look at every letter in a sentence,
but actually the shapes of the words.
That's an over-simplification, i.e. inaccurate.
I'm sure you've heard of "
Typoglycemia" before. It would be interesting to see how readability degrades as more and more of the scrambled words are converted to all caps.
[Steven D'Aprano]
But certainly looking at the overall shape of words is *part* of what we do. However, if it was
*all* we do when reading, then we couldn't tell these words apart:
case more core mean even user
then when this that else than
I guess I might have some sort of disability that you don't but I find those two lines much more difficult to read or even focus on than normal text. It's very hard to describe the sensation, but it's very unpleasant. It's like my eye doesn't know where to start so I keep scanning back and forth like a
Cylon.
[Steven D'Aprano]
If I remember correctly, didn't you make the claim earlier that all-caps
names draw the eye and emphasize that word?
Yes. It was I who said that. I know it seemingly contradicts statements in some of the sources I cited, but I think in those cases are referring to "slabs" of all caps. When it's lots of normal text with a few all caps, my eye is drawn to the all caps; when it's a block of all caps, everything is a wash and perhaps the few lower-case words stand out.
I'm sorry that's confusing. I might go look for better sources that pertain more exclusively to code, but honestly; it doesn't look like anyone else cares or will agree with me any time soon.
[Steven D'Aprano]
It seems strange that you are so worried about
the microsecond or so extra reading time it takes to recognize an
all-caps word, based on the "shape of the word" model, yet are prepared
to pay this enormous cost probably counted in multiple seconds: ...
It seems like the fundamental problem you have is trying to find where and when a variable was last bound.
I don't understand why your go-to solution to that problem is in the style-guide of a language. It doesn't seem at all
related to style. It seems like the kind of problem that's completely in the wheel-house of an IDE. Does it not feel to you
like you're relying on a style-kludge to make up for inadequate tools?
Why perpetuate that? Why not demand more from your tools?
[Steven D'Aprano]
You are correct, having a good naming convention for constants is not
strictly necessary. Especially for those who don't care about the
readability of their code.
I've pointed this out several times before, but Python itself violates the all caps constant naming convention all over the place and yet,
hardly anybody notices. The fear you seem to have about not communicating constancy clearly seems to be entirely hypothetical. The only
person that's tried to show me a case where using all caps was crucial completely defeated his own argument by presenting a non-constant
that had to be documented because its usage was so non-obvious.
I haven't heard an explanation yet for why it's so important that
pickle.DEFAULT_PROTOCOL be all caps while
sys.copyright is not.
If it's as important as you claim, then shouldn't there be mass hysteria? Cats and dogs getting along together, etc.?
[Steven D'Aprano]
Sure, but only because you know the semantics that pi is a numeric
constant, digits refers only to the Hindi-Arabic numerals 0...9, etc. I
wouldn't have guessed that timedelta.resolution is a constant, because I
don't know that module so well.
Be honest: what would your first guess be if you saw code using timedelta.resolution?
Where and when would you guess it was last bound?
Would you guess that it's a variable that changes on a whim or is often rebound?
How often do you deal with interfaces where module-level variables are intended to be re-bound?
Would you say that's good practice?
[Steven D'Aprano]
how about
filename
pattern
location
person
sigma
characters
Which of those are constants?
All of those are taken from real code I've written, except "characters"
which I just made up. All of them have been constants in some modules
and variables in others, except for sigma, but I'm not telling you which
it was. Since it is so easy for you to tell a constant from a variable,
you ought to be able to tell which it was. Right?
I would be able to tell very quickly if I saw those in my IDE whether they were local or global variables.
I tend to only import up to the module level (as per Google's style guidelines) specifically so that others know
where various variables (like math.pi) come from.
In my experience, most constants are configuration that people haven't decided to make configurable yet.
I worked at a computer vision lab where the camera had a resolution of 640 x 480 which were originally represented as
constants in a lot of our code VERTICAL_RESOLUTION and HORIZONTAL_RESOLUTION,
eventually; they became self.horizontal_resolution and self.vertical_resolution. So, my guess is that sigma is either a variable
or will become a variable at some point in the future.