Not coalescing around None-aware
Not coalescing around None-aware
Posted Dec 25, 2022 6:21 UTC (Sun) by Nahor (subscriber, #51583)In reply to: Not coalescing around None-aware by mb
Parent article: Not coalescing around None-aware
You're mixing cause and effect.
"verbosity" is not about "how easy it is to read something", it's about the number of tokens/words needed to say something.
Then based on your familiarity with a given expression, the verbosity will have a varying impact on your parsing/understanding speed.
Note though that it will never be as fast as the "??" operator. In big part because you need to check that the words are what you expect them to be (Is the "data" after the "if" really "data" or is it "date" or "dota"? Is the "None" really "None" or is it "Note" or "Noon"? ...). Because of the more limited scope of "??", some of those questions just become irrelevant / have a single and necessary answer.
And that familiarity goes hand in hand with Zorro's comment. The "??" operator, while initially not expressive, will become more expressive as you get familiar with that construct.
Familiarity will make things more readable in all cases, either by making things appear more compact/less verbose by skipping some parts, or by making them more expressive as it gets more ingrained.
> The big advantage of the verbose form is that you can *also* read and understand it, if you don't know the pattern
And we are back to "compact" vs "expressive". One is expressive but verbose, the other is compact but less expressive. One is more readable for newbies, the other for veterans. And people don't agree where the balance point should be.
> Saying that people don't have to [learn] ?? is also wrong, because other people will use it in their code and examples that Newbies will read
Nobody said anything like that. Everybody has to learn. Even the long expression needs to be learned for that matter, because it's not common to have the true-statement on the left of the "if", or that statement that returns a value ("else default") (*). The amount of learning effort is not the same, but it's still there in both case.
(*) more specifically, in most languages, "if" is a statement, which cannot have a value, while here in python, the "if" is an expression, which do have one.
Posted Dec 28, 2022 15:14 UTC (Wed)
by marcH (subscriber, #57642)
[Link]
Except for people who have to make a small change to a Python script rarely, only a couple times a months. I have and always had teammates in that case and that's where Python really shines compares to shell scripts or Perl or others. While the verbose " if None" variations annoy me every time, I totally understand the "Perlification" fear of "??".
Isn't there some middle ground alternative?
Not coalescing around None-aware
> Familiarity will make things more readable in all cases,...