Sensible Defaults

Scala has some defaults that make code concise and easier to read and write. Here are a few of these features:

  • It has support for scripts. Not all code needs to be within a class. If a script is sufficient for your needs, put the executable code directly in a file without the clutter of an unnecessary class.

  • return is optional. The last expression evaluated is automatically returned from method calls, assuming it matches with the return type declared for the method. Not having to put in that explicit return makes code concise, especially when passing closures as method parameters.

  • Semicolons (;) are optional. You don’t have to end each statement or expression with a semicolon—see Semicolon Is Semi-optional—and this reduces ...

Get Pragmatic Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.