4 ms·
I love Python too (a lot), but I disagree with some of these. > I love that they become generators when you use () instead of []. I kind of like this, and I k
by DonaldPShimoda 8y ago
I love Python too (a lot), but I disagree with some of these.
> I love that they become generators when you use () instead of [].
I kind of like this, and I kind of hate it. My second-favorite language is Haskell, where everything is lazy, so to me it almost seems like everything should be generators anyway (except when a value is expected).
> % for string interpolation was so good they had to bring it back.
I hate % for string interpolation. It's ugly. Why do my variables need "variables" in the strings? It's indirect interpolation. I far prefer f-format strings, because `print(f"Correct: {correct}/{total}")` reads much better.
> Tripple quotes using """ and ''' are hard to beat.
Unconvinced. I feel like the syntax for multiline strings could be a bit simplified.
Also, it's a pain to combine multiline strings with indentation. I don't want all the extra whitespace at the fronts of the lines, but I also don't want to process the text immediately afterwards... sigh.
But I totally agree with the other points. Overall, the syntactic sugar is phenomenal! Just these points I disagree about.
- kjeetgill 8y agoEager lists have their place! Ya can't sort or slice into a generator. I like the choice. I'm mostly still in Python 2.7 land so I forgot about the new f strings. I've never used them and I'm 50:50 only because I can do "%s %s %s" % (a.b(), z[:4], x2) without binding new variables. Can f strings do that? I don't know. I agree about the whitespace issues. Have you seen a language do them better? I proposed using | to prefix each line for Java's string literals. At least they're explicit that way. I'm just glad Python used """ instead of backticks or or <<<START style here docs.
- DonaldPShimoda 8y ago> Eager lists have their place! Ya can't sort or slice into a generator. I like the choice. Something like that could be handled implicitly... hmm but that seems bad. Maybe you're right that having a choice is better! > I can do "%s %s %s" % (a.b(), z[:4], x2) without binding new variables. Can f strings do that? I don't know. In 3.x f-string style, `f"{a.b()} {z[:4]} {x2}"` would work just fine! Python just expects any expression inside the curly braces, so as long as you give up a value (and that value is either a string or an object of a class that implements `__str__`, I think), you're golden. It's particularly useful when you have a lot of interpolation to do. The more arguments there are, the more tedious it is to read through a %-style format and figure out which variables correspond to what markers in the string. > I agree about the whitespace issues. Have you seen a language do them better? Not really, unfortunately. I think a case could be made that all indentation should be based on either (a) the triple-quote or (b) the first non-whitespace character of the first line. But I don't know if that's intuitive enough. Definitely something to think about, though!