You can google the movie code, but essentially, the industry voluntarily agreed to a set of moral codes in the movie to not glorify premarital sex or violence, "bad gus" had to reach an appropriate end for their actions (e.g., prison, death), etc.
See Pre-Code Hollywood and Motion Picture Production Code.
-PJ