Auto Format your logic!

I just discovered a pretty serious bug with Auto-Format (MX 2004):

If you run the following code, you’ll get “true 2”:

Now if you auto-format this code, and then run it, you’ll get:

true 2
false 2
false 1

Why? Because Auto-Format turns the code into:

Note the last two trace() statements, they’re moved outside of the else blocks! This is because of the comments at the end of the two else statements (which are now inside the else blocks). So watch where you put your comments! You can try this by auto-formatting and see the same (make sure you don’t save it!)

By the way, I always put my curly braces like this, so I haven’t ran into this bug before, until I tried to auto-format

The lesson of the day is: Don’t put your comments at the end of a statement and use auto-format, or you’ll run into logic changes like this!

3 thoughts on “Auto Format your logic!

Leave a Reply

Your email address will not be published. Required fields are marked *

− 5 = two