4 ms·
> Yet its [python] easy readability comes at the cost of performance. This does not sound correct. Why would there be a tradeoff between readability and perfor
by catlifeonmars 4y ago
> Yet its [python] easy readability comes at the cost of performance.
This does not sound correct. Why would there be a tradeoff between readability and performance?
- KronisLV 4y agoThis probably just refers to the current reality of using Python in many cases. If you want it's readability, you'll (most likely) need to deal with it's relatively slow runtime. That said, the readability itself shouldn't have much to do with the performance, as many reimplementations of the Python runtime already show.
- Retr0id 4y agoIn python, and many other languages, there are plenty of performance hacks you can apply that might make your code faster, but simultaneously less readable - often by stripping away levels of abstraction, or restructuring your code/data in unintuitive ways. For example, the prime-counting example in the article could've been optimised slightly by inlining the is_prime function into the body of the count_primes function (thus removing the overhead of calling a function).
- BerislavLopac 4y ago"Readability" is solely a function of familiarity.
- klibertp 4y agoIn most part, but not only. There are biological constraints on how the eye can move, and there are cognitive barriers you cannot overcome (how many "things" you can hold in your working memory at once). The code can be extremely familiar, but still hard to read, if it's too dense, too sparse, too long, involves too many concepts, and so on. You should still optimize the code you write along these axes to make it readable. It's true, however, that most of what people call "readability" is actually just familiarity - whether you should optimize the code for those unfamiliar with the language/domain/idiom is a separate question (the answer being: it depends).
- Retr0id 4y agoI strongly disagree. Truly readable code ought to be understandable to a newcomer to a particular codebase (or even, the language) - usually the sweet-spot is somewhere slightly terser than that, though.
- BerislavLopac 4y agoWhat you're saying, in other words, is that your definition of "readable code" is "code which is understandable to a newcomer to a particular codebase" - which is a perfectly valid take, and each team has full rights to set their definition on a level that suits them the best. My comment simply observes the reality, and does not recommend any given practice.
- catlifeonmars 4y agoThat’s true, but it’s not really a characteristic of Python specifically. You could replace “Python” with basically any other language (yes, even languages with “zero cost” abstractions like Rust or C++) and the statement “readability comes at the cost of performance” would still hold true. Poor performance is simply not an intrinsic property of the syntax/grammar of Python.