I'm learning Spark these days, but I'm a little confused by Spark configurations.
AFAIK, there are at least 3 ways to config:

1. Environment variables, <http://spark.apache.org/docs/latest/spark-standalone.html>
2. Command line arguments, like `./bin/spark-submit --class <main-class> --master xxx --deploy-mode xxx --conf key=value`
3. Code, like in Scala/Java code.

Why are there so many ways to do it, what are the differences? Is there a best practice for this?