Earlier quoted context omitted.
GP's quotes are paraphrased from PEP 20 and I think _are_ put of Python culture, at least as I've experienced it. https://www.python.org/dev/peps/pep-0020/
I'm afraid you've misunderstood olavk's point. 'The "quote" you made up' certainly refers to > "here's this cool feature for doing something you could do a different way that looks like hieroglyphics and nobody understands but you should totally use it because it's awesome!" not to > "explicit is better than implicit" and "there should be one and only one good way"
Asterisks in Python
91–100 of 110 posts
Re: Asterisks in Python
#92Earlier quoted context omitted.
Key word arguments. And I would consider the pythonic approach to be more pragmatic than anything. The language isn't haughty, it just does what it's told. That being said, you've provided a perfect example of what haughty looks like.
In the parent’s defense, people write a lot more cryptic Python than they do other languages. There are no metaclasses in Go nor abused operator overloads or half-baked DSLs. People don’t use dictionaries as structs to hang off whatever they like. It’s kind of a penny wise and pound foolish approach. Arguably it’s not python’s fault, but that’s a poor consolation for folks who have to deal with these messes.
I haven't written numerical code in Go but I am skeptical it will be as maintainable without operators. The lack of a particular feature does not in itself make code more maintainable.
I can't speak to metaclasses, since I have never had to maintain code using them. In my experience they are pretty rare.
Re: Asterisks in Python
#93Earlier quoted context omitted.
I feel you, however I also love https://github.com/Knio/dominate - a Python library to generate HTML. Generating HTML always felt awkward for me in many languages. From PHP where you sprinkle PHP between HTML or HTML between PHP, to frameworks in various languages where you populate variables and HTML is magically generated. Somewhere in between there are template languages. "Dominate" uses Python itself as the templ…
Oooh, that's nice. Thanks for sharing this. I like how it merges your mental model for HTML with Python in what feels like a very unsurprising way.
And regarding the kwargs I had this feeling first of oh no "what is this!?"
I have been programming Python since 2000 and I never used kwargs before. I knew they were there somewhere but I never bothered with them.
I was at first a bit annoyed, but I really wanted to add my own tags and discovered it was actually quite nice if I could intercept arguments in my own tags. You don't have to use kwargs to add your own tags, but you can make the tags more powerful and composable that way.
But kwargs are really only worth it to me if there is a strong component of, "write once, use many times" to it.
You don't have to use kwargs to add your own tags to Dominate, you can just return tuples of building stone tags if you want to.
Re: Asterisks in Python
#94This is one of those areas where I find Python a little contradictory. About 50% of the time it's "explicit is better than implicit" and "there should be one and only one good way" and then the other half of the time it's "here's this cool feature for doing something you could do a different way that looks like hieroglyphics and nobody understands but you should totally use it because it's awesome!
plot(*zip(*L))
What do you usually do? (Probably creating two intermediary lists with a loop?)Re: Asterisks in Python
#95This is one of those areas where I find Python a little contradictory. About 50% of the time it's "explicit is better than implicit" and "there should be one and only one good way" and then the other half of the time it's "here's this cool feature for doing something you could do a different way that looks like hieroglyphics and nobody understands but you should totally use it because it's awesome!
True, Python allows a lot of crazy hacks like monkeypatching, dynamically creating classes and so on. It is there if you need it. It is not like in Java where those things are simply impossible. The Python culture on the other hand discourages obscure hacks and unreadable cleverness, and the language is generally designed to encourage the straightforward and readable solution. I don't really see a contradiction in th…
Re: Asterisks in Python
#96Earlier quoted context omitted.
I never understand why people feel the need to find shortcuts. It’s like reading smthg[i++] in C. It’s not clear and it could be clearer if written over two lines instead but yet everyone does it.
If "everyone does it", then you should treat it as clear and just part of writing the language idiomatically. Pick your battles for when even the cognoscenti favour the more verbose approach.
Re: Asterisks in Python
#97Earlier quoted context omitted.
I never understand why people feel the need to find shortcuts. It’s like reading smthg[i++] in C. It’s not clear and it could be clearer if written over two lines instead but yet everyone does it.
It's perfectly clear and unambiguous. For some reason everyone loves it when functional languages are 'pithy' but hates it when C-like languages are equally terse.
Smthg[i++] and smthg[++i] have two different behaviors. If you tell me that this is clear I probably don't want to read your code.
Re: Asterisks in Python
#98Earlier quoted context omitted.
Taken straight out of Ruby, I see. Very convenient feature (and one of my favorites about Ruby), though it does contradict the do-it-one-way mentality.
>though it does contradict the do-it-one-way mentality. not really: use f-strings when you're passing in variables as-is (or nearly no work), and format() when you need to do work on them before stringifying them; f-strings are naturally (and obviously) more difficult to read when the variables are big, as it obscures the actual text they're being fit into, and where. The only natural area for preference to apply is…
Yes it does. You could construct the string using a for-loop. Thank you for proving my point and then down-voting me.
Re: Asterisks in Python
#99Earlier quoted context omitted.
I think the star syntax is a lot nicer than `apply`. Python actually had an `apply` builtin, but it was deprecated in Python 2.3.
Apply, and first class / higher order functions in general are good in languages where they compose well. Python's * won't compose well.
f1 = partial(f, 1, 2)
f2 = partial(f1, 3, 4)
f2(5, 6) # equivalent to f(1, 2, 3, 4, 5, 6)
It also supports kwargs.Re: Asterisks in Python
#100Earlier quoted context omitted.
In the parent’s defense, people write a lot more cryptic Python than they do other languages. There are no metaclasses in Go nor abused operator overloads or half-baked DSLs. People don’t use dictionaries as structs to hang off whatever they like. It’s kind of a penny wise and pound foolish approach. Arguably it’s not python’s fault, but that’s a poor consolation for folks who have to deal with these messes.
Is that really true? Sure you can write cryptic code using operator overloads, but the convention is to only use them in cases where they improve readability. For example numpy code would be a lot less maintainable without operator overloading IMHO. I haven't written numerical code in Go but I am skeptical it will be as maintainable without operators. The lack of a particular feature does not in itself make code more…
I've been writing Python and Go extensively for the last 10 and 5 years respectively. I really recommend giving Go a shot; you can pick it up in an afternoon and it really complements Python well since it excels at a lot of Python's weaknesses (parallelism, performance, static typing, static compilation, dependency managmenet, etc). For example, if I have to write a CLI tool, I almost always use Go since it's so much easier for coworkers to install a single binary than a Python program + dependencies + make sure you have the right version of the interpreter installed.