PS4, Spring 2011: Looking at the sample code, I can't see why build_coder is necessary; it seems like it doesn't do anything build_encoder doesn't also do. (This appears to be confirmed by the solution set.) Am I missing something here?
I have not worked the MIT problem sets, but from looking at the psudocode in the PDF, it looks like the only difference is that build_coder allows for a positive or negative shift, and build_encoder only does a positive shift value. With this type of cypher, the build_coder would be more efficient. The decoding can be done with the same code by shifting the opposite direction. This reduces programming time.
i couldn't tell what they wanted - i implemented build_coder() then build_encoder is just: return build_coder(shift)
and of couse, build decoder is just: return build_coder(-shift)
@bwCA yah, pretty typical code reuse. So have people write the code once, but call it with logical names. Then the interface to the user just asks for the shift value and if you want to encode or decode. They don't need to know you wrote something only once.
Ah! That makes perfect sense. I shoulda thought the whole problem through, not just the first bit; would've made it a bit more intuitive. Thanks.
Join our real-time social learning platform and learn together with your friends!