[Tutor] What's in a name.
ThreeBlindQuarks
threesomequarks at proton.me
Thu May 18 21:45:07 EDT 2023
I appreciate the correction Cameron. How much does it narrow things if the goal is to only have one OBVIOUS way?
I have seen too many places where even the obvious ways were too numerous.
If I ask you to take a string and substitute in various parameters held in variables, which method is obvious?
At least five major methods are supported that overlap quite a bit and some have relatively unique features. These days, some might argue you should mainly just use an f-string but clearly older code mainly used other methods and there is no pressure to change.
Arguably quite a few programs in ANY language have a somewhat obvious way to do parts of a task or even to combine those parts into larger and larger subunits. Python is far from unique in this regard.
But consider newly added features that allow you to do things that have often been done another way. I mentioned the walrus operator which provides a new way you can write code even if it does not really need it as in a multi-line style. What about the new pattern matching features? Arguably you could use them to do complex things but also trivial things like use them instead of an if/else statement.
I am not making fun of Python but continue to not take seriously anyone who truly believes there are usually obvious ways to do things in a language like Python. I submit many people either do not know the Pythonic way that others claim is a thing or disagree with it at times.
I remember reading that perhaps a pythonic way not often found easily in languages like C was to just try something without lots of checking and arrange to deal with errors like dividing by zero. I admit I am attracted by such ideas but also not fully trusting them at times.
In various languages I noted the errors that propagated in calculations that contained unknown data as in NA as well as when you allow values like Inf or NaN. Unless you are SURE there are no such numbers, it can get a bit annoying as they are not treated as an error in situations like sum(vector) returning an NA if any one of the contents is NA and propagating that into any equation that uses it and so on. Lots of statistical analyses become garbage unless you use a variant that says things like sum(vector, na.rm=TRUE) OR you pre-process your data and remove or hide parts before doing an analysis.
Any catchable error that finally triggers an alarm may be far removed from the cause. So some programmers would rather go slowly and carefully and check as they go along. Arguably, Pythonistas do not advocate this try/except method to be used in complex cases. Sometimes the way to do it is not as obvious as others.
Just for fun, consider the quadratic formula and the one best/right way to calculate when it has ± as part of the formula. Some who consider things like efficiency will calculate some parts and store them in variables then continue to calculate the two alternatives. Others will just brute force do two complete and independent calculations. Still others may want to cache answers in case the same one will be asked again. Some may even want to use a fairly expensive equation solver that does not use the formula at all.
A language can only force a single solution by making other methods not be present or make them too hard to use much.
The goal of Python to me is to be more inclusive and make many ways possible. But, the goal includes fighting some of that bloat mainly by placing much functionality in modules loaded only when needed.
So although we are discussing a historical quote, I wonder if they would say that again or even want there to be a main obvious way.
Sent with Proton Mail secure email.
------- Original Message -------
On Thursday, May 18th, 2023 at 7:38 PM, Cameron Simpson <cs at cskk.id.au> wrote:
> On 18May2023 23:17, ThreeBlindQuarks threesomequarks at proton.me wrote:
>
> > Python people have made a truly stupid statement years ago suggesting
> > that the language generally has one obvious way to do things.
>
>
> That's not what the Zen says:
>
> There should be one-- and preferably only one --obvious way to do it.
>
> That's a design objective: for common tasks, there should be an obvious
> thing to do for it, and not a plethora of similar features requiring a
> careful choice.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list