Hacker News new | past | comments | ask | show | jobs | submit login

They make code concise.List Comprehensions, magic methods - Yes . implementing __len__ on your class and using len() everywhere(with list, string and your new class) is better than coding a method called get_count() , total_count(), etc etc.

They help make code more declarative rather than filling it with implementation logic. Anyone can just read the code and understand it instead of getting bogged down with the implementation. Especially list comprehensions. [len(i) for i in k] is much better than reading a for loop implementation looping through k and append len of each object in the loop to a result array




Is that last list comprehension really much better though, keeping in mind that most of us code in several languages, and might be predominantly context experts rather than coders at the same time?

x = [] for i in k: x.extend(len(i))

is really, really easy for me to understand instantly, if I have just been writing an actuarial model using R, c++, c#, vba, sql, html, css and python for the day, which I have.

Shortness is not always conciseness, methinks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: