good chemistry is complicated,
and a little bit messy -LW
Re^2: Is it correct?by wade (Pilgrim)
|on Jul 14, 2008 at 18:26 UTC||Need Help??|
I think the novice has to own the problem domain. He knows what problem he's trying to solve and the context in which it will be run. Given this, I'd respond as follows (if it were me who asked the original questions):
1. Does it work correctly?
Um, I guess so. It seems to work? I cannot think of anything wrong with it; can you?
I really think, here that you have to understand what you want the program to do. You need to understand the straight-down-the-center as well as the corner cases and, if you don't grok the code, at least have some tests you can run.
2. Do you understand it?
Somewhat. I think I understand it, maybe... Is there something I am missing?
This is, of course, subjective. If you don't get the basic principles, RTFM a bit and get some understanding -- you may have already done this, I don't know. Trace through the code by hand with some data and see if you think it does what you think it's supposed to. Add some 'print' statements to verify.
You may, depending on the original advice, come to a better understanding of side-effects and such at a later time. That's okay.
3. Would anyone else understand it?
FIIK, a) I am not someone else, so how should I know what someone else thinks. b) I just learned this myself, and this is the way I learned it.
4. Will you understand it in a month's time?
I hope so.
To address 3. and 4., together, I think these are really meant to ask: is the code readable? Are the variable names clear? Is the style easily read? Did you comment it well? I find that, when I'm learning something, I comment the holy snot out of it, explaining every detail as I think I understand it. If I learned something when I wrote the code, I make darned sure that someone else with the same level of experience I had when I started would understand the code.
5. Does it strike a good balance between terseness and verbosity?
This is like asking a 5 year old whether War and Peace strikes a good balance between terseness and verbosity. One must have sufficient mastery over the material to be able to judge.
No, I think this is more like asking a 12 year old whether the New York Times strikes a good balance between terseness and verbosity. It's a stretch but it's a good thing to consider. The answer may stray away for what an experienced programmer would say but that's okay.
6. Could you make changes to it without it being likely to break in unforeseen ways?
Good Question, how would I go about finding this out? What are the unforeseen ways?
Again with the RTFMing and the tracing of the code. This requires deeper understanding than do the other points. Give it a go, though. Look at side-effects. Try funkified data as an input. Always check the corner cases.
To figure out what the corner cases are, look at the expectation of the data. If the code is expecting numbers, try characters. How does the code respond to a gigantic amount of input or none at all?
7. Is it fast enough?
Is there a faster way to do it?
The answer is 'probably' but that's not the question you should be asking. Does the program run fast enough to fulfill your needs. Writing something faster than that often requires sacrificing readability and that would be a bad thing.
Update: fixed a typo