←back to thread

317 points est | 3 comments | | HN request time: 0.762s | source
Show context
logicallee ◴[] No.17448729[source]
This is unpythonic, breaking about half of these design rules:

https://en.m.wikipedia.org/wiki/Zen_of_Python

For anyone who hasn't read the original PEP link, what do you suppose this does? Guess its meaning:

1.

    if (row := cursor.fetchone()) is None:
          raise NotFound
      return row
2.

Next guess the meaning of this - what does it look like it does?

  row = cursor.fetchone()
  if row is None:
      raise NotFound
  return row


Answers:

The first does the second. The second doesn't need explanation. I literally don't need to tell you what it does.

(The two examples are from the link.)

Now you might think that this means I'm against this PEP.

But actually [EDIT: because I know there is a VERY high bar to being accepted into Python] to me it means this is going to save an incredible amount of time - it must be very good indeed to be accepted.

So if they decided to adopt it - sure, I'll use it. And I bet it's great in practice.

It's also super explicit. If you don't know what := does you will go look it up.

If Python is still driven by Python design philosophy and all that discussion, then this will be very helpful. It surely had a very high threshold to meet.

replies(2): >>17448868 #>>17449189 #
PurpleRamen ◴[] No.17449189[source]
The problem were always those people who will misuse something. The Zen was never meant as a guide, but as a guardian. Python in the early days was good because there simply was no way to write ugly code. But with all the abilitys modern python has, this wall has fallen, and now ugly python has become normal. And with this it will sometimes even become horrible.
replies(1): >>17449294 #
1. logicallee ◴[] No.17449294[source]
I thought the Zen was some of the design philosophy that went into the language itself. (The Wikipedia entry calls it "a collection of 20 software principles that influences the design of Python Programming Language".)

So at least according to Wikipedia it is a guide. Of course, whether it's applied in practice is a different matter.

replies(1): >>17449417 #
2. PurpleRamen ◴[] No.17449417[source]
At the time it was written, python was already around a decade old. There was some discussion about the "true" way of python and some demands to "fix" python, yada yada. Someone demanded some short description of the python philosophy to counter those discussion, and the Zen was made up for this.

It's a condensed definition of the philosophy and goals which went into python at that point. A guide to define the borders of the road to good python, but also a guard against those who wanna change the direction of this road.

replies(1): >>17450232 #
3. logicallee ◴[] No.17450232[source]
Interesting history, thanks. If you can find any sort of cite (maybe a short interview or forum link) I bet you could add this context to the Wikipedia article in a few minutes, it's missing it now.