Hacker News new | ask | show | jobs
by qznc 4818 days ago
Skimming through the academy source, some are fine, some are not.

For example, codemp/game/g_saga.c uses goto just fine. Three "goto failure" jump to the end of the function to handle the error case differently than a normal return. Not a very good example for proper goto use, but ok.

In contrast, codemp/cgame/cg_players.c should be refactored. It seems to be model loading code. If the loading fails, some gotos jump to the start of the function and using a flag variable a default model "kyle" is used instead of the arguments. If the default model is broken, this becomes an infinite loop. My style suggestion:

  if (loadModel(foo)) return;
  if (loadModel(default)) return;
  assert (false && "fallback/default model broken");