2 ms·
Regarding your first point, in side projects, I've started doing things like this: for c in customers: return c.first_name + c.last_name or: customer
by globuous 8y ago
Regarding your first point, in side projects, I've started doing things like this:
for c in customers:
return c.first_name + c.last_name
or:
customers.map(c => c.first_name + c.last_name)
I've started doing this because I didn't like having "customers" and "customer", I found this very un-readable. It also makes it simpler to follow what's going on since I have less code to parse.
And because I never use 1-lettered variable names (unless it's a counter like i, j, k), I find it very easy to read when this convention occurs in my code.
- DogLover_ 8y agoYes, I personally like this style. Its not a lack of thinking or laziness. Its just easier to read.
- anonytrary 8y agoUsing single char variables is fine and IMHO leads to more concise code without sacrificing readability. When you are looping over a set, it's very common to think about it like `for all x in Xylophones do {...}`. For example in a nested loop, I would much rather prefer `i` and `j` over `iterativeAuxiliaryVariable1` and `iterativeAuxiliaryVariable2`. Never using single character variables as a "best practice" is just bad advice. As with pretty much everything in programming, the real answer is "it depends".