[SPARK-3897]format example code and explicit val instead of var

This is not a good change. It makes it looks like the comment pertains to the following line. Leave it inline.