I would add that for vast swaths of time in a lot of areas of the world in between Hammurabi and now, there wasn't even a written code of law, it was more based on customs. Rome did not have written laws for the first 300 years of its founding. A friend I was talking about this was in disbelief when I mentioned this.
Because the basic crimes are so universally understood and detested, that there needs to be nothing written. Murder, theft, robbery, etc. Every person knows from birth that those things are wrong, and it takes severe brain washing for people to change their minds on it.
Good point. That Rome fact raised my eyebrow, but then I remembered how low literacy has been historically, and the eyebrow returned to the usual position.