Section 1

Preview this deck

What is a declaration?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 14, 2020

Cards (52)

Section 1

(50 cards)

What is a declaration?

Front

Associates a name with a value. This name can then be used to refer to the value in other code. It does not evaluate to a value. It binds a name (Test) to a value (empty object) Example object Test {}

Back

What order are method calls evaluated?

Front

left-to-right

Back

What is a block?

Front

sequence of expressions or declarations surrounded by braces. A block is also an expression: it executes each of its sub-expressions in order and returns the value of the last expression

Back

How many times is the body expression of a field evaluated for an object?

Front

Only once

Back

What is substitution?

Front

You can change how you write a program without changing the meaning of the program. Example 1 + 2 + 3 6

Back

Infix operator

Front

shorthand code that can be used if a method takes only one parameter

Back

What is referential transparency?

Front

You can replace an expression with its value without changing the meaning of the program 1 + 1 and 2 are interchangeable

Back

How do you define a method in an object body expression?

Front

def name(parameter: type, ...): resultType = bodyExpression

Back

A class is a value.

Front

FALSE There is a different namespace for classes

Back

How many times is the body expression of a method evaluated for an object?

Front

Every time the method is called

Back

What are the two distinct stages that a Scala program goes through?

Front

Compile-time and run-time

Back

What is a method?

Front

refer to computations that produce values

Back

How do we interact with data?

Front

call methods

Back

How do you define a string literal?

Front

'/'

Back

How do you define a character literal?

Front

"/"

Back

What is the difference between the following: "Hello world!" println("Hello world!")

Front

- println("Hello world!") evaluates to a unit - Cannot be used as part of a larger expression - Prints the value as a side-effect - "Hello world!" evaluates to a string - Can be used as part of a larger expression

Back

All values in Scala are objects.

Front

TRUE

Back

What is the grand supertype of all Scala types?

Front

Any

Back

Scala has very few operators - almost everything is a method call

Front

TRUE

Back

What is a constructor?

Front

allows us to pass parameters to new objects as we create them

Back

What is the difference between a method and a field?

Front

A field gives a name to a value, whereas a method gives a name to a computation that produces a value

Back

What is a side-effect?

Front

You cannot replace an expression with its value without changing the meaning of the program println("hi") and "hi" are not interchangeable

Back

What happens at compile time?

Front

does the program make sense? 1. Syntactically correct 2. Type must be checked

Back

What is a field?

Front

refer to values stored within an object

Back

What is a singleton type?

Front

A type created just for an object we've created.

Back

How do you define a field in an object body expression?

Front

val name = valueExpression

Back

When are types checked in a program?

Front

During compile-time

Back

Unit

Front

result of expressions that evaluate to no interesting value, such as printing to standard output using println

Back

What is AnyVal?

Front

supertype of all value types

Back

What is an overloaded method?

Front

Methods that are defined several times for different argument types. Scala determines which variant is needed Example object calc2 { def square(value: Double) = value * value def cube(value: Double) = value * square(value) def square(value: Int) = value * value def cube(value: Int) = value * square(value) }

Back

Are methods values? Are they expressions?

Front

Calls to methods are expressions, but methods themselves are not expressions.

Back

Expressions

Front

parts of a program that evaluate to a value

Back

What is the syntax for declaring a field in an object?

Front

val name: type = valueExpression

Back

Using var in Scala is a good practice.

Front

FALSE val is a much better choice, because it is immutable. When programming in Scala prefer immutable fields whenever possible.

Back

String interpolation

Front

Allows you to embed variable references and expressions in a string s"""Use braces for expressions: ${sc.version}. You can omit the braces when just using a variable: $sc However, watch for ambiguities like ${sc}andextrastuff"""

Back

What happens at run time?

Front

The computer performs the instructions provided in the program

Back

How would you write "foo".take(1) in operator style?

Front

"foo" take 1

Back

When are Scala objects and classes loaded?

Front

Not until they are referenced (lazy loading).

Back

What happens if a type check fails?

Front

The compilation fails and the program will not be ran

Back

Literal expression

Front

literally looks like what they evaluate to "hello world"

Back

What are the two types under Any?

Front

AnyVal and AnyRef

Back

Why do you strive to avoid side effects?

Front

Make the program easier to understand

Back

What is lazy loading?

Front

In Scala objects and classes aren't loaded until they are referenced by other code.

Back

What do the parenthesis mean in the bit of code? // res10: Any = ( )

Front

Unit

Back

Types

Front

express some restrictions on programs

Back

What is a class?

Front

template for creating objects that have similar methods and fields

Back

Values

Front

exist in the computer's memory and are what a running program manipulates

Back

What type will this conditional evaluate to? if (1>2) "alien" else 2001

Front

Any, because the types mismatch between the if and else block

Back

Literal expression

Front

represents a fixed value that stands for "itself" Example: 42

Back

Arguments

Front

control how the method works. A value you pass into a method

Back

Section 2

(2 cards)

What is AnyRef?

Front

supertype of all "reference types" or classes

Back

What is the keyword to create objects from a class?

Front

New Example New Person("Brad")

Back