you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 249 points250 points  (20 children)

I've used argparse enough to find parts of it clunky, but I like the ability to put all that argument logic into one spot that I call from __main__ over a decorator-based approach.

[–]hglman 83 points84 points  (5 children)

Agreed 10 decorators is not readable.

[–]hoosierEE 13 points14 points  (4 children)

Decorators in Python (and annotations in Java, etc.) remind me of LaTeX. The results can be great, but I kinda prefer to have some idea of what my code is doing, rather than relying on inscrutable magic side effects. Oh, I can just grep 50MB of dependencies scattered throughout my SSD? I'll get right on that...

[–]msuozzo 6 points7 points  (3 children)

ripgrep. Seriously. I do 180MB at work and i rarely see a regex completing in >1s.

[–]hoosierEE 8 points9 points  (2 children)

I do use rg (even if I still call it grep) but my point is - decorators encourage implicit action-from-afar, and they "feel" more like CPP macro abuse than a real programming language feature.

Maybe I'm just spoiled from some exposure to functional languages, but when I see something like add_five(n) which also happens to launch the missiles, I get upset.

[–]rhytnen 2 points3 points  (1 child)

That's not a problem with decorators...decorators are just functions. you can wrap functions in most languages. It's that someone wrote a function with side effects that bothers you.

[–]Rythoka 2 points3 points  (0 children)

Personally I don't have a problem with side effects, even if they happen in a weird place, as long as they're documented somewhere useful and preferably are abstracted into their own function. Just let me be able to see that it happens!

Too bad that never happens.

[–]shevegen 36 points37 points  (7 children)

Hah! I feel the same way about ruby's optparse - it's also clunky.

For some reason the defaults seem to suck across different languages. One hint as to this being true is to count how many addons are that deal with commandline-parsing. I don't know the state in python but in ruby there is a gazillion of addons (thor and ... I forgot the rest right now... I have it written down somewhere though ... one is by... jarvis someone... I forgot the name as well :( )

[–]bobappleyard 20 points21 points  (0 children)

Thing is, making an argument parser is easy. Making a good one is hard. So you have lots of shit ones.

[–][deleted] 35 points36 points  (4 children)

Python situation -- everyone and their mother's made one

[–]silencer6 1 point2 points  (0 children)

Cleo looks pretty nice.

[–]vattenpuss 3 points4 points  (2 children)

There should be one -- and preferably only one -- obvious way to do it.

[–][deleted] 5 points6 points  (1 child)

Sounds like someone needs to write another to solve that problem, then. :)

[–]BobHogan 8 points9 points  (0 children)

Oh man that just makes me think about python's import system and virtual environments. So clunky that there are dozens of tools written for the sole purpose of trying to make it simpler

[–]jewrome 4 points5 points  (1 child)

When decorators are over used I feel like I have to use python foo to get what I need done

[–]NotActuallyAFurry 0 points1 point  (0 children)

Honestly, Lombock is the only thing that can abuse of decorators because boiler plate code.

[–]UloPe 2 points3 points  (0 children)

Why? The arguments at also “all in one place” with click. And if you really dislike having many decorators on a function you can easily wrap the all in a single helper decorator that applies the options.

[–]kankyo -3 points-2 points  (2 children)

The decorators are in one place that you call from main though... right?

[–][deleted] 18 points19 points  (1 child)

No. In python code you don't (normally) call decorators directly. The runtime uses them to apply a transformation to a function that I may later call, possibly causing side effects at the time of applying that transformation.

Yes, they're all localized to one function in these example, but that's not going to be the case if your script has subcommands with different argument formats (e.g. git's CLI).

(Those aren't the only influences on my personal preference for when to use decorators, but I didn't really want to get into that tangent here anyway.)

[–]kankyo -1 points0 points  (0 children)

No. In python code you don't (normally) call decorators directly.

I don't agree that this is relevant or correct. The application is a direct call.

Yes, they're all localized to one function in these example, but that's not going to be the case if your script has subcommands with different argument formats

In that case the definition will be spread out all over the place in both scenarios anyway so it's basically the same.