Changing the format of the code, when it makes the code more readable, is welcome and useful.
Changing the code is different, for two reasons.:
- You could change what doesn't make the code work, and who reads the questions would not understand why the user is asking the question, or what is wrong with the code.
- The OP would have some difficulties to understand how to map the code proposed in the answers to the code he finds in his files.
If by modifying the code you mean to write the correct name of a function, a class, or a method, that is fine if:
- It is not what causes the code to not work;work
- theThe user already written the name of that function, class or method correctly in the same code snippet.
If by modifying the code you mean to change the code as you did in your "state 3" example, then I would say it is not fine at all. I would rather write an answer to the question, and suggest the OP how to better write the code he wrote.