3 ms·
"While parts of code were bad, we could have easily fixed them with refactoring if we had taken time to read and understand the source code that was written by
by DonHopkins 11y ago
"While parts of code were bad, we could have easily fixed them with refactoring if we had taken time to read and understand the source code that was written by other people."
This is the thing. Many people just HATE and REFUSE to read other people's code.
Maybe they just don't teach code reading and reviewing in computer science classes, but they should.
Printing it out on paper and reading it away from the computer is helpful, but a lot of people write code for wide screens that doesn't print out well, or they just don't give a shit and it looks terrible even on the screen. And some people just don't have the stomach for reading through a huge pile of pages, or think that's below their station in life.
But reading code is one of the best most essential ways to learn how to program, how to use libraries, how to write code that fits into existing practices, how to learn cool tricks and techniques you would have never thought of on your own, and how to gain perspective on code you wrote yourself, just as musicians should constantly listen to other people's music as well as their own.
I just don't feel safe using a library I haven't at least skimmed over to get an idea of how it's doing what it promises to do.
There are ways to make reading code less painful and time consuming, like running it under a debugger and reading it while it's running in the context of a stack and environment, looking at live objects, setting breakpoints and tracing through the execution.
Code reading and reviewing is so important, and it should be one of the first ways people learn to program, and something experienced programmers do all the time.
And of course as the old saying goes, code should be written first and foremost for other people (preferably psychopaths who have your home address, photos of your children, and your social security number) to read, and only incidentally for the computer to execute.
- stevetrewick 11y ago>Maybe they just don't teach that in computer science classes, but they should. Should they? This seems like a classic conflation of computer science with programming. Perhaps the reason this important craft skill is not taught in CS is because it has nothing to do with complexity classes, automata theory, etc. Programming != CS
- DonHopkins 11y agoThey aren't the same, but they aren't mutually exclusive either. I think all computer scientists should learn to program, and learning to program requires getting over your distaste of reading other people's code. I doubt a pure academic "computer scientist" who doesn't like to get their hands dirty reading or writing code because they look down on it as a "craft" is going to be of much use on the types of projects we're discussing that require rewriting or refactoring existing code.
- stevetrewick 11y agoTIL some people have seriously negative connotations of the word 'craft', which appears to have made it a poor word choice, please see my explanatory comment above. I'd be interested to hear if there's some context I'm missing. Both responses that express negative interpretations of the word have mentioned computer scientists' attitudes, but I don't hang out with any IRL. Have I missed out on some historic flame war?
- DonHopkins 11y agoNo, you just missed out on some bad professors. ;)
- Joeri 11y agoIt may be the case that programming is applied CS, and that a CS grad might therefore not actually be a decent programmer. However, employers are considering a CS degree as proof of competency in programming. So, if CS classes don't teach programming, then they're failing to provide what the expectation is that people have of that degree.
- DonHopkins 11y agoAnd they're also failing to educate their CS grads as well as they should. I think every CS grad should have a firm grasp of programming, and I'd consider a CS grad who doesn't know how to program to have a gaping hole in their education. This notion of considering programming a "craft" that's below you gets at the attitude problem I think a lot of people (not just pure theoretical computer science graduate students) have towards reading other people's code.
- maccard 11y agoI spend a lot of time looking at a profiler view of my application in work, it's a great way to see what the most "important" areas of the code are. You get call stacks for the hottest code paths, can read the code with annotations about how expensive a certain line is, etc. It's a good way to look at code I've found!
- jrapdx3 11y agoUnderstanding others code can be difficult, frustrating, or just plain tedious. But who wouldn't have to do it? When software isn't working, seems to be a normal part of figuring out where things are going wrong, which is a normal part of fixing bugs, etc. Of course, it's agonizingly ironic to discover that reviewing one's own code written long ago may be no easier to decipher. It's a humbling experience when it happens, but what would ever teach the lesson more effectively about writing code that can be read by mere humans. I know it makes me think about the variable names I use, the merit of "one-liners", how much white space to leave, and the clarity of explanatory comments, among other things. It's a form of art to know when to be verbose and when not to be. Some programmers may be superior "code artists", but every programmer should be able to write well enough.