Is it acceptable to use tricks to save programmer when putting data in your code?

coding-style, python

Solution

Code is usually read many times, and it is written only once. Saving writing time at the expense of readability is not usually a good choice, unless you are doing some throw-away code.

The second version is less explicit, and you need some time to understand what the code is doing. And we are simply talking about variable instantiation, not about algorithms!

Problem

Example: It's really annoying to type a list of strings in python: ``` ["January", "February", "March", "April", ...] ``` I often do something like this to save me having to type quotation marks all over the place: ``` "January February March April May June July August ...".split() ``` Those took the same amount of time, and I got 2x the # of months typed in. Another example: ``` [('a', '9'), ('4', '3'), ('z', 'x')...] ``` instead of: ``` map(tuple, "a9 43 zx".split()) ``` which took much less time.

Original source