How do I prevent WordPress from eating my code?

If you look at the editing box, you’ll see the curly braces as a choice. Highlight your code block, then use that curly braces icon. That will wrap the code in a ‘code’ block, so it will look like this:

<?php 
   // this is a code block
   echo "this is a code block";

You can do the same in text mode (rather than visual) by using the HTML ‘code’ tag.