4 ms·
From Alex Martelli , a prominent Python expert [1]: > I'm one of those who prefers words to punctuation -- it's one of the reasons I've picked Python over Perl
by ayhanfuat 3y ago
From Alex Martelli , a prominent Python expert [1]:
> I'm one of those who prefers words to punctuation -- it's one of the reasons I've picked Python over Perl, for example. "Life is better without braces" (an old Python motto which went on a T-shirt with a cartoon of a smiling teenager;-), after all (originally intended to refer to braces vs indentation for grouping, of course, but, hey, braces are braces!-).
> "Paying" some nanoseconds (for the purpose of using a clear, readable short word instead of braces, brackets and whatnots) is generally affordable (it's mostly the cost of lookups into the built-ins' namespace, a price you pay every time you use a built-in type or function, and you can mildly optimize it back by hoisting some lookups out of loops).
> So, I'm generally the one who likes to write dict() for {}, list(L) in lieu of L[:] as well as list() for [], tuple() for (), and so on -- just a general style preference for pronounceable code. When I work on an existing codebase that uses a different style, or when my teammates in a new project have strong preferences the other way, I can accept that, of course (not without attempting a little evangelizing in the case of the teammates, though;-).
[1] https://stackoverflow.com/a/2745292/2285236 https://stackoverflow.com/a/2745292/2285236
- mgraczyk 3y agoI find {} much more readable then dict() because the former is more common. On the other hand list(L) more readable than L[:] because the fact that slicing copies is more obscure, and these are not equivalent when L is not a list. My take would be to ignore performance and generally do what is more commonly done.
- nephanth 3y agoMy problem with {} is that the syntax for dicts {x1:y1, x2:y2 ...} and sets {x1, x2 ...} Are very close, and {} is slightly ambiguous. I've run into bugs because i wrote {} for the empty set. Since then i write dict() and set()
- xarope 3y ago+1. I've run into this too, and ended up using set() to clarify.
- dr_kiszonka 3y agoYou could write, e.g., `flags: set = {}` to get both speed and readability.
- grumpyprole 3y ago> I'm one of those who prefers words to punctuation It's not punctuation, it's notation. Notation is often essential for readability, we use it for mathematics and music for a very good reason. Consider why JSON is generally preferred to XML. While this guy might have a preference for pointless verbosity, most likely the person who needs to read his code won't.
- deleted 3y ago[deleted]