DEV Community

Discussion on: In Your Opinion, What Makes Code Pythonic?

Collapse
 
bloodgain profile image
Cliff

Pythonic is just the community jargon for idiomatic. Are you following the idioms of Python?

In programming terms, an idiom is like a design pattern, only smaller or more abstract. For example, using a list comprehension rather than a generator function in Python. In C++, using the RAII principle to manage memory instead of manually allocating and deallocating is idiomatic.

Note that in Python, idiomatic code tends toward better readability. Even list comprehensions, which are a bit more opaque than the usual Python, could be deduced quite readily by an experienced coder, even if they aren't familiar with the concept. This is not necessarily the case with all languages. Like design patterns, they are just something a fluent user of the language will recognize without having to analyze it. For a linguistic example, the meaning of the phrase "let's call it a day" would not be obvious to someone just learning English, but any fluent speaker would know it means "let's stop working (on this) today/for now and come back to it later".