They can't really prohibit anyone from writing the code, but only from publishing it, but what would happen then if exactly as you say go to a country where it is allowed and publish it there? Even if you return, on what legal grounds are they going to sue you? It's is going to be almost impossible for them to forbid writing code.
Of course, the government cannot stop developers to write the code, no way to stop it. But since they prohibit publish it, it is very annoying for developers, they must move to another country. Actually, the government must understand that prohibition isn't the right solution, should consider other proper ways. Why don't think about making some regulations but not stop it, right? The regulation should be friendly with the developers and fulfill what the government wants.