7 ms·
I've always considered it a dangerous idiom in dynamic typed languages like Python to create identifiers that differ from each other by only a single character
by 6502nerdface 10y ago
I've always considered it a dangerous idiom in dynamic typed languages like Python to create identifiers that differ from each other by only a single character (fruit/fruits), point to completely different objects, and are used in close proximity to each other. It's just asking for a hard-to-detect typo that will blow up at runtime.
- mixmastamyk 10y agoHmm, don't think that actually happens very often, because it is so readable this way.
- lgunsch 10y agoI written python for the last 4 years, and I've never had typo problems of that nature. I find the plural form to be so idiomatic it is expected and easier to understand.
- robmcm 10y agoI find this very confusing, and would much prefer to be explicit in adding the collection type. This is also useful when you have two types of collections in the same place, such as an array and dictionary.
- squeaky-clean 10y agoI would normally agree, but in the case of plurals like this (at least for myself) it's instantly obviously when one is being used incorrectly. for fruit in fruit: print(fruit) My brain is screaming at me right now that the above doesn't make sense. Even with a click glance, it sticks out like a sore thumb. I'm not entirely sure why, but I'd guess it's because it mimics natural language more, so my eyes are more used to parsing that for mistakes?