Search code examples
scalafunctionmethodsprogram-entry-point

What is the best way to write a main in scala?


Since I have started to learn this language I've noticed that there are several ways to write a main method in order to run your code. What is the most used and best one?


Solution

  • This

    object SO extends App {
        //Your main method's code goes here, since we have extended App
    }
    

    or

    object SO {
      // here goes the main
      def main(args: Array[String]): Unit = {}
    }
    

    Personally I prefer the second one, as it distinguishes the main method more clearly.