6 ms·
But, see, "good" is just this word. It's hard to test. "Readable", though, I can test simply by trying to read it. That is, I can test someone else's code by
by AnimalMuppet 12y ago
But, see, "good" is just this word. It's hard to test.
"Readable", though, I can test simply by trying to read it. That is, I can test someone else's code by trying to read it. I can't test my own that way; as the author, I'm not qualified to read it for understandability, because I already understand it.
So in practice, this boils down to "Read each other's code. If you can't read it, say so. If they tell you they can't read your code, fix it." That is actually fairly simple to put into practice. It doesn't help you get it right the first time, but it shows you where you got it wrong, and tells you how to know when you've fixed it. That's a big step forward from "good".
- mcphage 12y agoWhat that means, though, is you can only determine if code is readable after it's written, and read by other people. And I agree with you. But that also means that, while you're writing code, or thinking about the code you're going to write, or trying to decide between two possibilities, 'readability' doesn't mean anything. So you can't use it to guide you towards more readable code; instead it can merely be used to decide which code should be replaced / refactored / rewritten. And you can't use it to teach new developers how to write better code.
- AnimalMuppet 12y ago> And you can't use it to teach new developers how to write better code. Yes, you can. New dev writes code. It gets code reviewed. New dev gets told: "That's ugly/too complicated/hard to understand. Here's some suggestions for how to re-write it." Over a few years, new dev learns what not to do (which is about the same as developing a sense of taste, or learning a style). It's not something that can be put into a one-hour training class, though...
- analyst74 12y agoIt's harder in practice than you make it out to be. Because our insecurity hinders our ability to say "your code is too complicated for me to understand". Plus, some code is supposed to be more complicated than others, you can't always solve difficult problems with simple solutions. So unless you can understand the code and come up with a simpler solution, just complaining that it's too complicated is not gonna help anyone.
- nathankleyn 12y agoI cannot upvote this more than once, so I feel obligated to let you know how much I agree with this. "Readability" may be a personal thing, but you'll reach convergence pretty quickly by following the approach you outlined. I see it as no different to something like writing, in that respect, in that an editor and a writer begin to converge on a style together without really setting out in the first place to do so.