Edited, memorised or added to reading queue

on 17-Aug-2014 (Sun)

Do you want BuboFlash to help you learning these things? Click here to log in or create user.

Flashcard 149625870

Tags
#bloch-effective-java-2ed #equality #java
Question

Suppose we have a class that tries to cooperate with String. What is wrong with it?


public final class CaseInsensitiveString {

    private final String s;

    @Override public boolean equals(Object o) {
        if (o instanceof CaseInsensitiveString)
            return s.equalsIgnoreCase(((CaseInsensitiveString) o).s);
        if (o instanceof String)
            return s.equalsIgnoreCase((String) o);
       return false;
    }

    // rest of the code
}
Answer
It violates symmetry of equality - "BlaBla".equals(whatever) will do case-sensitive comparison, even if whatever is CaseInsensitiveString (in which case the result is false)

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149626385

Tags
#bonds #duration #finance
Question
[another name of DV01, not the meaning of the abbreviation DV01] or DV01 is the change in price in dollars, not in percentage.
Answer
Dollar duration

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
Dollar duration or DV01 is the change in price in dollars, not in percentage.

Original toplevel document

Bond duration - Wikipedia, the free encyclopedia
e point change in yield) or ($ per 1 basis point change in yield) The DV01 is analogous to the delta in derivative pricing (The Greeks) – it is the ratio of a price change in output (dollars) to unit change in input (a basis point of yield). <span>Dollar duration or DV01 is the change in price in dollars, not in percentage. It gives the dollar variation in a bond's value per unit change in the yield. It is often measured per 1 basis point - DV01 is short for "dollar value of an 01" (or 1 basis poi







#odersky-programming-in-scala-2ed #scala
You can reassign vars
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




#odersky-programming-in-scala-2ed #scala
You can't reassign vals
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




#odersky-programming-in-scala-2ed #scala
the first element in a Scala array named steps is steps(0), not steps[0], as in Java
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149629596

Tags
#odersky-programming-in-scala-2ed #scala
Question
What does to stand for in this example?

for (i <- 0 to 2)
  print(greetStrings(i))
Answer
a method call (0).to(2)
if a method takes only one parameter, you can call it without a dot or parentheses.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
You cannot write “println 10”, but you can write “Console println 10”.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149629623

Tags
#odersky-programming-in-scala-2ed #scala
Question
What does + really stand for in 2 + 3?
Answer
it is a method call: (2).+(3)
method is named "+"

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629643

Tags
#odersky-programming-in-scala-2ed #scala
Question
if greetStrings is an array, greetStrings(i) gets transformed into
Answer
greetStrings.apply(i)

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
Accessing an element of an array in Scala is simply a method call like any other. This principle is not restricted to arrays: any application of an object to some arguments in parentheses will be transformed to an apply() method call. Of course this will compile only if that type of object actually defines an apply method.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




#odersky-programming-in-scala-2ed #scala
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.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149629682

Tags
#odersky-programming-in-scala-2ed #scala
Question
What will greetStrings(0) = "Hello" be transformed into?
Answer
greetStrings.update(0, "Hello")

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629693

Tags
#odersky-programming-in-scala-2ed #scala
Question
What method are you calling here and where is it defined?
val numNames = Array("zero", "one", "two")
Answer
a factory method apply which takes variable number of argumetns and is defined on Array companion object
the code gets transformed to
val numNames2 = Array.apply("zero", "one", "two")

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629708

Tags
#odersky-programming-in-scala-2ed #scala
Question
What does the cons expression, e.g. 1::twoThree, gets translated to (in terms of method calls)?
What rule is used?
Answer
twoThree.::(1)
if a method's name used in operator notation ends with colon, it is called on the right operand

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629728

Tags
#odersky-programming-in-scala-2ed #scala
Question
to instantiate a new tuple that holds some objects, just [...].
Answer
place the objects in parentheses, separated by commas

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
Both mutable and immutable sets offer a + method, but their behavior differs. Whereas a mutable set will add the element to itself, an immutable set will create and return a new set with the element added.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149629764

Tags
#odersky-programming-in-scala-2ed #scala
Question
Although mutable sets offer an actual += method, immutable sets do not. In this case, jetSet += "Lear", is essentially [...]
Answer
a shorthand for jetSet = jetSet + "Lear"

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629771

Tags
#odersky-programming-in-scala-2ed #scala
Question
When you add a key-value pair to a map: treasureMap += (2 -> "Dig.") , what is 1 -> "Dig." really?
Answer
It is a method call (1).->("Dig") which returns a tuple containing key and value

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
Where you’d say “public” in Java, you simply say nothing in Scala. Public is Scala’s default access level.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




#odersky-programming-in-scala-2ed #scala
method parameters in Scala is that they are vals, not vars
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149629823

Tags
#odersky-programming-in-scala-2ed #scala
Question
Whenever you [...], its result type will definitely be Unit. This is true no matter what the body contains, because the Scala compiler can convert any type to Unit.
Answer
leave off the equals sign before the body of a function

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
a semicolon is required if you write multiple statements on a single line
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149629855

Tags
#odersky-programming-in-scala-2ed #scala
Question
When [...], it is called that class’s companion object.
Answer
a singleton object shares the same name with a class

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629862

Tags
#odersky-programming-in-scala-2ed #scala
Question
What is the class that has companion object called?
Answer
companion class of that object

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629873

Tags
#odersky-programming-in-scala-2ed #scala
Question
Where a companion class and its companion objects have to be defined?
Answer
in the same source file

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629884

Tags
#odersky-programming-in-scala-2ed #scala
Question
What is special about access control between companion object and companion class?
Answer
they can access each other's private members

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Article 149629895


#odersky-programming-in-scala-2ed #p109 #scala

In short, a line ending is treated as a semicolon unless one of the following conditions is true: The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.The next line begins with a word that cannot start a statement.The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.



Flashcard 149629904

Tags
#odersky-programming-in-scala-2ed #scala
Question
In short, a line ending is treated as a semicolon unless one of the following conditions is true:
  1. The line in question ends [...].
  2. The next line begins with a word that cannot start a statement.
  3. The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.
Answer
in a word that would not be legal as the end of a statement, such as a period or an infix operator

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
Open it
In short, a line ending is treated as a semicolon unless one of the following conditions is true: The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.The next line begins with a word that cannot start a statement.The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.&#







Flashcard 149629915

Tags
#odersky-programming-in-scala-2ed #scala
Question
In short, a line ending is treated as a semicolon unless one of the following conditions is true:
  1. The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.
  2. The next line begins [...].
  3. The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.
Answer
with a word that cannot start a statement

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
Open it
rt, a line ending is treated as a semicolon unless one of the following conditions is true: The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.The next line begins <span>with a word that cannot start a statement.The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway. <span><body><html>







Flashcard 149629922

Tags
#odersky-programming-in-scala-2ed #scala
Question
In short, a line ending is treated as a semicolon unless one of the following conditions is true:
  1. The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.
  2. The next line begins with a word that cannot start a statement.
  3. The line ends while [...].
Answer
inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
Open it
following conditions is true: The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.The next line begins with a word that cannot start a statement.The line ends while <span>inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway. <span><body><html>







#odersky-programming-in-scala-2ed #scala
Any standalone object with a main method of the proper signature can be used as the entry point into an application.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




#odersky-programming-in-scala-2ed #scala
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.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149629968

Tags
#odersky-programming-in-scala-2ed #scala
Question
How to express s.indexOf(’o’, 5) in operator notation?
Answer
s indexOf ('o', 5)

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
The only identifiers that can be used as prefix operators are +, -, !, and ~.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149630004

Tags
#odersky-programming-in-scala-2ed #scala
Question
Scala will transform the expression -2.0 into [...]
Answer
the method invocation (2.0).unary_-

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630011

Tags
#odersky-programming-in-scala-2ed #scala
Question
if you define a method unary_* and then try to call it on object in prefix notation *p, how will Scala parse it and why?
Answer
*.p because * is not one of the four names allowed for prefix methods

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630031

Tags
#odersky-programming-in-scala-2ed #scala
Question
Postfix operators are methods that [what's their signature and how are they invoked?].
Answer
take no arguments, when they are invoked without a dot and parentheses

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630046

Tags
#odersky-programming-in-scala-2ed #scala
Question
How does scala decide on precedence when methods are used in operator notation, like 2 + 2 * 7 ? What is Scala's default rule here?
Answer
Scala decides precedence based on the first character of the methods used in operator notation (this rule has exceptions). If the method name starts with a *, for example, it will have a higher precedence than a method that starts with a +.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
One exception to the method / operator precedence rule based on first character in the method name is this: If an operator ends in an equals character (=), and the operator is not one of the comparison operators <=, >=, ==, or !=, then the precedence of the operator is the same as that of simple assignment (=).
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




#odersky-programming-in-scala-2ed #scala
x *= y + 1
means the same as:
x *= (y + 1)
because *= is classified as an assignment operator whose precedence is lower than +, even though the operator’s first character is *, which would suggest a precedence higher than +.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Article 149630089


#odersky-programming-in-scala-2ed #p136 #scala

When multiple operators of the same precedence appear side by side in an expression, the associativity of the operators determines the way operators are grouped. 



Flashcard 149630098

Tags
#odersky-programming-in-scala-2ed #scala
Question
When [...], the associativity of the operators determines the way operators are grouped.
Answer
multiple operators of the same precedence appear side by side in an expression

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
Open it
When multiple operators of the same precedence appear side by side in an expression, the associativity of the operators determines the way operators are grouped.







Flashcard 149630105

Tags
#odersky-programming-in-scala-2ed #scala
Question
When multiple operators of the same precedence appear side by side in an expression, the [...] of the operators determines the way operators are grouped.
Answer
associativity

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
Open it
When multiple operators of the same precedence appear side by side in an expression, the associativity of the operators determines the way operators are grouped.







Flashcard 149630121

Tags
#odersky-programming-in-scala-2ed #scala
Question
The associativity of an operator in Scala is determined by [...].
Answer
its last character

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630137

Tags
#odersky-programming-in-scala-2ed #scala
Question
any method that ends in a ‘:’ character (e.g. cons) is invoked on [which operand is the receiver and which is the argument of the method invocation?]. Methods that end in any other character are the other way around.
Answer
its right operand, passing in the left operand

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630157

Tags
#odersky-programming-in-scala-2ed #scala
Question
No matter what associativity an operator has, however, its operands are always evaluated [in what order?].
Answer
left to right

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
In Java, classes have constructors, which can take parameters, whereas in Scala, classes can take parameters directly.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149630184

Question
Where will Scala compiler put the println() code?

class Rational(n: Int, d: Int) {
  println("Created "+ n +"/"+ d)
}
Answer
Into the primary constructor

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill






Flashcard 149630195

Question
How can we forbid creating rationals where denominator equals 0?

class Rational(n: Int, d: Int) {
  println("Created "+ n +"/"+ d)
}
Answer
Add preconditon using require method that throws an exception if it receives false:

class Rational(n: Int, d: Int) {
  require(d != 0)
  println("Created "+ n +"/"+ d)
}

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill






Flashcard 149630206

Tags
#odersky-programming-in-scala-2ed #scala
Question
Why won't this compile?

class Rational(n: Int, d: Int) { // This won’t compile
  require(d != 0)
  override def toString = n +"/"+ d
  def add(that: Rational): Rational =
  new Rational(n * that.d + that.n * d, d * that.d)
}
Answer
Because n and d can only be accessed in methods for this object - they seem to be captured like in closure for toString. They are not fields / members though

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630230

Tags
#odersky-programming-in-scala-2ed #scala
Question
In Scala, constructors other than the primary constructor are called
Answer
auxiliary constructors

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630246

Tags
#odersky-programming-in-scala-2ed #scala
Question
Auxiliary constructors in Scala start with [...].
Answer
def this(...)

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
Identifiers in user programs should not contain ‘$’ characters, even though it will compile; if they do this might lead to name clashes with identifiers generated by the Scala compiler.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




#odersky-programming-in-scala-2ed #scala
the identifier :-> would be represented internally as $colon$minus$greater
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149630349

Tags
#odersky-programming-in-scala-2ed #scala
Question
How to call Thread.yield() in Scala, where yield is a reserved word?
Answer
Thread.`yield`()
string enclosed in backticks becomes an identifier, no matter how arbitrary it is.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs