top | item 44943540

(no title)

williamscales | 6 months ago

I find myself writing a very simple style of python that avoids list comprehensions and so on when working in a shared code base.

For a language where there is supposed to be only one way to do things, there are an awful lot of ways to do things.

Don’t get me wrong, writing a list comprehension can be very satisfying and golf-y But if there should be one way to do things, they do not belong.

discuss

order

ipython|6 months ago

I find list and dict comprehensions are a lot less error prone and more robust than the “manual” alternatives.

I would say unless you have a good reason to do so, features such as meta classes or monkey patching would be top of list to avoid in shared codebases.

zahlman|6 months ago

> I find list and dict comprehensions are a lot less error prone and more robust than the “manual” alternatives.

I find them easier to understand and explain, too.

dragonwriter|6 months ago

> For a language where there is supposed to be only one way to do things

That's not what the Zen says, it says that there should be one -- and preferably only one -- obvious way to do it.

That is, for any given task, it is most important that there is at least one obvious way, but also desirable that there should only be one obvious way, to do it. But there are necessarily going to be multiple ways to do most things, because if there was only one way, most of them for non-trivial tasks would be non-obvious.

The goal of Python was never to be the smallest Turing-complete language, and have no redundancy.

Philpax|6 months ago

If I have to write Python like Go, I'd rather just write Go. (Not disagreeing with you, but this is one of many reasons that Python is the least-favourite language that I use on a regular basis.)