Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    \$\begingroup\$ This applies to C++ as well with #define for example, but I admit it's nice that def and val are shorter. \$\endgroup\$ Commented Nov 11, 2011 at 18:21
  • \$\begingroup\$ Hm. def is the keyword to define a method, and a simple translation to c++ for val is 'const', and it is a declaration, but the type is often inferred. The shortening is in the first case the type= which is closer to typedef - isn't it? The second example isn't from me and it is new to me. I have to watch out, where to use it. \$\endgroup\$ Commented Nov 11, 2011 at 19:01
  • \$\begingroup\$ typedef long long ll; is the same as #define ll long long, so the latter's shorter by 1. But yeah, typedef does work. Looking at the val example again I definitely misread it. It seems even less Scala-specific. x = thingWithAReallyLongComplicatedNameForNoReason is a pretty general strategy :P \$\endgroup\$ Commented Nov 11, 2011 at 19:21
  • \$\begingroup\$ @userunknown When you instantiate a List or Array etc with syntax val x = List(1,2,3) you're just calling the apply method on the List object. (This technique for object creation is known as a "factory method", in contrast to using a constructor with new.) So above, we're just making a new variable that points to the same singleton object as the variable name Array. Since it's the same thing, all the methods, including apply, are available. \$\endgroup\$ Commented Nov 12, 2011 at 17:36