Programming in Scala Quotes

Rate this book
Clear rating
Programming in Scala: A Comprehensive Step-by-step Guide Programming in Scala: A Comprehensive Step-by-step Guide by Martin Odersky
1,663 ratings, 4.22 average rating, 100 reviews
Programming in Scala Quotes Showing 31-60 of 92
“Scala implicitly imports members of packages java.lang and scala, as well as the members of a singleton object named Predef, into every Scala source file.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“p == Person("Sally", 21)”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“First, the compiler will create a companion object and place a factory method in it named apply.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“Given each singleton object is an instance of its superclasses and mixed-in traits, you can invoke its methods via these types, refer to it from variables of these types, and pass it to methods expecting these types.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“Defining a singleton object doesn't define a type (at the Scala level of abstraction). Given just a definition of object ChecksumAccumulator, you can't make a variable of type ChecksumAccumulator. Rather, the type named ChecksumAccumulator is defined by the singleton object's companion class.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“A class and its companion object can access each other's private members.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“You must define both the class and its companion object in the same source file.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“Scala has singleton objects. A singleton object definition looks like a class definition, except instead of the keyword class you use the keyword object.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“one way in which Scala is more object-oriented than Java is that classes in Scala cannot have static members.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“In a Scala program, a semicolon at the end of a statement is usually optional. You can type one if you want but you don't have to if the statement appears by itself on a single line.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“Although the Scala compiler will correctly infer the result types of the add and checksum methods shown in the previous example, readers of the code will also need to mentally infer the result types by studying the bodies of the methods. As a result it is often better to explicitly provide the result types of public methods declared in a class even when the compiler would infer it for you.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“you can leave off the result type and Scala will infer it.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“On the other hand, design choices depend on the design context, and Scala makes it easy to write methods that have multiple, explicit returns if that's what you desire.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“The recommended style for methods is in fact to avoid having explicit, and especially multiple, return statements.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“In the absence of any explicit return statement, a Scala method returns the last value computed by the method.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“One important characteristic of method parameters in Scala is that they are vals, not vars”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“One important way to pursue robustness of an object is to ensure that the object's state—the values of its instance variables—remains valid during its entire lifetime.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“where you'd say "public" in Java, you simply say nothing in Scala. Public is Scala's default access level.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“The for-yield produces exactly the same result as map because the compiler transforms the for-yield expression into the map call.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“Every useful program is likely to have side effects of some form; otherwise, it wouldn't be able to provide value to the outside world.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“-> method, which you can invoke on any object in a Scala program, returns a two-element tuple containing the key and value.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“Tuples are very useful, for example, if you need to return multiple objects from a method.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“List does offer an "append" operation—it's written :+”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“shorthand way to specify an empty list is Nil,”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“If a method is used in operator notation, such as a * b, the method is invoked on the left operand, as in a.*(b)—unless the method name ends in a colon. If the method name ends in a colon, the method is invoked on the right operand.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“::', which is called "cons." Cons prepends a new element to the beginning of an existing list”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“List has a method named `:::' for list concatenation.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“Similarly, when an assignment is made to a variable to which parentheses and one or more arguments have been applied, the compiler will transform that into an invocation of an update method that takes the arguments in parentheses as well as the object to the right of the equals sign. For example: greetStrings(0) = "Hello"
will be transformed into: greetStrings.update(0, "Hello")”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“When you apply parentheses surrounding zero, one, or more values to a variable, Scala will transform the code into an invocation of a method named apply on that variable.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0
“As of Scala 3, the indentation-based style, called "quiet syntax," is recommended over the curly brace style. Scala 3 also introduced end markers, to make it easier to see where larger indented regions end. End markers consist of the keyword end followed by a specifier token, which is either an identifier or a keyword.”
Martin Odersky, Programming in Scala Fifth Edition: Updated for Scala 3.0