Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As well as supporting type inference, this has an ergonomic benefit too.</p> <p>For any given variable name + type, chances are that the name is the more important piece of information. Moving it to the left makes it more prominent, and the code more readable once you're accustomed to the style.</p> <p>Other ergonomic benefits:</p> <ul> <li>With <code>val</code>, <code>var</code> or <code>def</code> before member names, instead of their type, they all neatly line up in a column.</li> <li>If you change just the type of a member, or drop it entirely in favour of inference, then a fine-grained diff tool will clearly show that the name is unaltered</li> <li>Likewise, changing between a val/var/def is very clear in diffs</li> <li>inference should be considered default behaviour in Scala, you only need type specifications in certain specific scenarios, even then it's mostly done for the compiler. So putting them at the very start of a declaration emphasises the wrong thing.</li> <li>"name: Type" instead of "Type name" more closely matches the way most programmers will actually think about a declaration, it's more natural.</li> <li>The differing C/C++ and Java conventions for pointers and arrays (i.e <code>*</code> being a prefix on the following name and not a suffix on the preceeding type in C/C++, or <code>[]</code> being a valid suffix on both names and types in Java) are still confusing to newcomers or language converts, and cause some very real errors when declaring multiple variables on a single line. Scala leaves no room for doubt and confusion here.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload