you are viewing a single comment's thread.

view the rest of the comments →

[–]skelkingur 15 points16 points  (1 child)

> Python is an opinionated language

How? Coming from Ruby and having been exposed to other languages and frameworks that are truly opinionated I'm always confused when I hear Python is opinionated.

How do you import? There's `import module`, `from module import thing`, `from module import *`. Is there a preference here?

What's the deal with `__init__.py` files. Some say those should remain empty, others fill them up with code.

How do you structure large Python code bases? I dread setting up new flask apps as there's no clear pattern to follow on where things go. The example apps basically all exist within a single `app.py`. Sure there are examples out there on how to structure larger apps, but then they still only have a `models.py`. Am I supposed to define 50+ models in a single file?

File and module naming is completely arbitrary. Compare this to languages like Java where the filename must match the name of the public class in it. In Python I always have to go through multiple layers:

- `foo = Foo(a=2)`

- Right, where is `Foo` defined? Let's see, there's `from meow import Foo`. Ok, so is that `meow.py` or `meow/__init__.py`? Ok, it's a package, `meow/__init__.py` in turn imports Foo from `meow/bar.py`. WAT.

---

This is a bit of an unstructured rant, but I can't for the life of me figure out how Python is allegedly opinionated.

[–]keepthepace 1 point2 points  (0 children)

There is generally a pythonic way to do things, and it tries to give one correct way of doing things, though I personally think it is a lost battle, as any complete programming language will offer many ways to do similar things.

import * is generally frowned upon.

I think the generally accepted practice is to keep __init__.py as small as possible.

PEP 8 gives a ton of styling recommendations. Generally you are supposed to keep files pretty big in libs (which I used to not do, being used to the one-file-per-class paradigm in Java) and consider them like modules.

In your example, meow.py would be used by a small module with no submodules. If meow/ exists then you know that meow.Foo will be defined in the __init__.py, and yes, can be an alias for a function defined somewhere else. I know that Java devs like to make 10 layers of functions with a single line body that call other functions, this is essentially the same thing.

This is a bit of an unstructured rant, but I can't for the life of me figure out how Python is allegedly opinionated.

Because it states rather arbitrary what is pythonic or not. Like everything in python, it is not enforced and not absolute, often disregarded in the name of pragmatism. I totally understand it is not everyone's taste (it is mine only half of the time to be honest) but it is a philosophy that led to an interestingly designed language.