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., printf instead of std::cout.
  • The first typedef is missing the member declarations, a closing } and an identifier, which defeats its purpose.
  • The init function 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 typedef doesn’t make any sense. peta is an instance of the person structure, and it’s confusing (and wrong) to use the former as an alias for the latter.
  • Why bother declaring an init function if you’re using static assignment in person peta = ...? That seems rather pointless if you’re already hard-coding the values. (In fact, init does 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 if to match the else { statement.
  • There’s no definition of fp nor a fopen to 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.

So much for being a genius, huh? Though I’ll admit the color scheme is pretty nice. Anyway, a more realistic code chunk is present in New Game!!, which is discussed extensively here.

Written on October 13, 2019