3 ms·
No, I don't know of any research although it may exist. My personal definition of readability is very simple: the time it takes to understand a particular piece
by zwieback 12y ago
No, I don't know of any research although it may exist. My personal definition of readability is very simple: the time it takes to understand a particular piece of code. I think there's a balance between overly dense code and code that requires me to scroll through several pages or jump between files.
It takes me longer to parse dense Ruby or Python code because I'm not very familiar with the languages but I'm aware that those languages give us ways to write more expressive code with less syntax overhead. The trick is to write compact code that is still easy to understand for someone other than the author.
- klibertp 12y ago> don't know of any research although it may exist I couldn't really find any, but I'd be very happy to learn that it exists. We'd be much better off as an industry if it existed. > the time it takes to understand a particular piece of code Can you see a problem with this definition? Do you think that any given piece of code has time_needed_to_understand property, which is at least similar - or at least in the same order of magnitude! - for all the people who could read it? Exactly the same few lines of code can take one person half a day to understand while some other person will know their meaning in less than 10 seconds. It's much worse than that, actually. You can show the same piece of code to several people, and you're almost guaranteed to hear complaints about both "too terse" and "too verbose"; both "too explicit" and "too implicit"; both "too noisy" and "without enough syntax sugar". And this happens even if we're talking about people who mainly program in the same language - adding other languages makes this far, far worse. You get holy wars on the grounds of readability and syntax, you get people who just won't ever touch X, because it's so much uglier (and less readable) than Y and so on. It's insane. Personally, I try to write "readable" code in every language I happen to use. I actually read a couple of books on the subject and looked through many pieces of code/projects which are widely considered "readable". That doesn't matter, because every now and then I still hear that the code I wrote is "too terse"/"too much syntax"/"too little syntax"/"too verbose" - the same code, just in the eyes of different people. Back to the article, so that it's not entirely off-topic, I find this: http_retry = retry(DOWNLOAD_TRIES, HttpError) harder_download = http_retry(download_image) images = map(harder_download, urls) very "readable" (by your definition of "readability"), as it takes me less than a second to comprehend what is it about. Conversely, this: images = [] for url in urls: for attempt in range(DOWNLOAD_TRIES): try: images.append(download_image(url)) break except HttpError: if attempt + 1 == DOWNLOAD_TRIES: raise I find much less readable, because I need to track a lot of irrelevant data to understand what it is about. On the other hand, if my task was to understand why the code retries one time less than it should (for example), then the latter code is much more readable, because I don't need to navigate to some other file to see a definition of retry (which takes time) and I just see the potential off-by-one error in front of my eyes. Anyway, "readability" is really a hard problems for the whole industry, I just wish people would admit that much and started to do some serious research on the topic instead of thinking it's obvious. Edit: I'd also like to know what people who downvoted my first post here think.
- colomon 12y agoI don't speak Python (guessing that's what this is) but the problem I have with the short version is that it still seems oddly verbose. Why not something like this? images = map(retry(DOWNLOAD_TRIES, HttpError,download_image), urls) (I may have slightly fumbled the syntax here, but with luck my point is clear.)