Anime code review - Null Peta
Anime studios seem to love showing a bit of code on the screen to emphasize how smart the character is. And when this happens, I can’t help but pause the screen and perform a code review. This example is courtesy of Null Peta, a show about a young girl genius building a robot to replace her dead older sister. Her attempt doesn’t go too well, and she’s inspecting the code to see where she stuffed up:
Wow. Where should we start?
- This is either C or C++ given the syntax.
However, if it’s mean to be C, why are there C++-style
//comments? (Apparently these are supported via compiler extensions, but that compromises code portability. What if you want to deploy your sister on the cloud?) On the other hand, if it’s meant to be C++, it’s not very idiomatic, e.g.,
- The first
typedefis missing the member declarations, a closing
}and an identifier, which defeats its purpose.
initfunction has variable names in multiple words, e.g.,
char* body style, which should really be
char* body_style. It also uses character arrays for weight and height, and these should really be some numeric type (depending on the desired precision).
- What is
##########? Pretty sure the preprocessor won’t know what to do with that.
- The second
typedefdoesn’t make any sense.
petais an instance of the
personstructure, and it’s confusing (and wrong) to use the former as an alias for the latter.
- Why bother declaring an
initfunction if you’re using static assignment in
person peta = ...? That seems rather pointless if you’re already hard-coding the values. (In fact,
initdoes get used at the very bottom of the screen, but then why not use it here as well?)
- Comment containing the error message is unnecessary clutter.
- There’s no
ifto match the
- There’s no definition of
fopento match the
fclose(fp). I’d guess this probably results in undefined behavior if you try to close a file that has not been opened.
- There’s some gibberish after the closing brace. She was probably trying to get out of Emacs.