4 ms·
If you read code and don't think about what it's doing, are you really "reading" it? Reading code without running it in your head feels like reading prose with
by Wowfunhappy 2y ago
If you read code and don't think about what it's doing, are you really "reading" it?
Reading code without running it in your head feels like reading prose without actually comprehending it.
- evilduck 2y agoMaybe? I don’t need to read and calculate every iteration of some loop to understand that it’s mapping. While if I need to determine the actual output value of a function, I might.
- nextaccountic 2y agoSometimes working out the details what is the right output of a piece of code (like, in the line x = f(15), is x 2345 or 2346?) is very time consuming It's also sometimes unnecessary to understand the high level picture of what the code does (like "oh, this computes the GCD using Euclidean algorithm, I had to code this in uni once") So, most people read in a higher level fashion and understand just fine. It's really like reading math. When you read 23443 + 54454 * 454534, do you need to work out the computation to understand what this does?
- eru 2y ago> If you read code and don't think about what it's doing, are you really "reading" it? A lot of code doesn't _do_ anything. And you can still read it. Eg I'm thinking about type declarations, or constraint based programming, etc.
- usrusr 2y agoI'd put most of my code reading much closer to "inferring intention" than to "running in my head". It's really more like navigating through a complex building, looking for certain rooms than simulating execution. "running in my head" is to reading code like "pronouncing in my head" is to reading prose. Both aren't the norm.
- wongarsu 2y agoYou can read (scan) code to get the general gist of it. It's more at the level of "this code looks at the pathname, then some cookies, and then either calls the signin function or returns True". That's about the same level where I read most prose. It's enough to answer the question "what does this do" (answer: "calls signin if you aren't logged in but should be") or "how complex is this" but not enough to modify the code or understand the intricacies of it. What you are referring to is simulating the execution in my head to figure out which execution flows exist, figuring out which cases aren't covered, what the function calls actually do, what the significance of those cookies is, etc. That's similar to how I read contracts. But unless I have to write a literary analysis or somebody asks me to find all the plotholes and inconsistencies I don't read normal prose that way. It might be interesting if there are similarities between programmers tracing execution flows, lawyers reading an unfamiliar contract, and editors finding inconsistencies in short novels.
- Wowfunhappy 2y agoBut what participants in this study were actually asked to do is: > predict what action the code would produce So "this code looks at the pathname, then some cookies, and then either calls the signin function or returns True" seems to align with that.
- martin82 2y agoYou can read code line by line and understand what each line does, but any algorithm that has more than 5 lines of code probably needs an additional step where, after reading it line by line, you need to take a step back and think about it in a different way to understand what the whole block of code is trying to do.