Luet oppimateriaalin englanninkielistä versiota. Mainitsit kuitenkin taustakyselyssä
osaavasi suomea. Siksi suosittelemme, että käytät suomenkielistä versiota, joka on
testatumpi ja hieman laajempi ja muutenkin mukava.
Suomenkielinen materiaali kyllä esittelee englanninkielisetkin termit.
Kieli vaihtuu A+:n sivujen yläreunan painikkeesta. Tai tästä: Vaihda suomeksi.
This page summarizes the meanings of some programming terms.
Many of the terms have additional or alternative meanings beyond those listed below. This
page focuses on the meanings that are most pertinent for O1. The definitions are informal
and sometimes imprecise, but sufficient for our purposes.
You may also want to take a look at Scala’s official glossary,
which has some overlap with this one. We don’t follow it to the letter in O1, though.
Did you come to this page looking for something that isn’t here?
Let me know: email@example.com.
a class that 1) may have abstract methods and abstract variables; 2) may not be
instantiated directly but only via its subclasses; 3) may be inherited by other
classes; and 4) (in Scala:) may pass constructor parameters to its supertypes (unlike a trait,
which cannot) ¶ See Chapter 7.5.
a method whose signature is defined but whose body is not ¶ See Chapters 7.3 and 7.5. Traits
and abstract classes, which may not be directly instantiated, may have abstract
an instance variable whose data type is defined but whose value is not ¶ See Chapter 7.3.
Traits and abstract classes, which may not be directly instantiated, may
have abstract variables.
a generalization; a conceptualization; a model that leaves out unnecessary or undesirable details ¶
To program is to create and use abstractions; see, e.g., Chapters 1.6, 2.1, 2.3, 3.2, 6.1,
6.3, 7.1, 7.3, and 9.3. There are different kinds of abstraction. For instance, adding a
parameter to a function or class abstracts away that parameter’s specific values and makes the
solution more generic. An interface, on the other hand, can abstract away the implementation of
how a program component solves a problem; see level of abstraction.
a reserved word that specifies a program component’s visibility ¶ For example, the private
and protected keywords are access modifiers that constrain access to a component. Also called a
todellinen parametri, argumentti
another term for argument ¶ Contrasts with formal parameter.
short for artificial intelligence
a stepwise method for solving a particular problem ¶ See Chapter 1.2. An algorithm can be
implemented as a program in various ways, e.g., in different programming languages. Nevertheless,
algorithms do not necessarily involve computers or programs; for example, long division is an algorithm (that can be either carried
out by a person or implemented as a computer program).
(in O1Library and some other contexts:) a location at which a picture attaches when positioned
relative to other pictures ¶ E.g., “Put this pic’s anchor at the top-right corner of that pic.”
A picture’s anchor may be its middle point or one of its corners, for example. In O1Library,
anchors are represented by class Anchor. See Chapter 2.5 and that class’s documentation.
a function defined by a function literal and therefore without a name ¶ See Chapter 6.2. Also
known as a lambda function.
an unnamed parameter variable, denoted by an underscore in Scala’s abbreviated function literals ¶
See Chapter 6.2.
the top-level superclass of all Scala classes ¶ See Chapter 7.5.
a superclass of most Scala classes ¶ See Chapter 7.5. The virtual machine that runs Scala
programs uses references to access objects of type AnyRef; cf. AnyVal. AnyRef is an
immediate subclass of Any. See also Object.
a superclass of certain Scala classes that have been optimized for efficiency ¶ See Chapter 7.5
(and 3.5). The virtual machine that runs Scala programs doesn’t use references to access objects
of type AnyVal; cf. AnyRef. AnyVal is an immediate subclass of Any.
1) an interface that can be used for building various applications; 2) a software library
that provides tools for programmers who build applications ¶ Short for “application programming
interface”. A service on the internet (such as Google Maps) can provide an API that enables programs
to access the service. Many programming languages are associated with a library that is applicable
to a wide range of problems and is referred to as the language’s API; for instance, Scala has the
short for application
(In Scala:) a singleton object within an application that defines what the computer should do
when the application is launched ¶ In a sense, the app object represents the application as a whole.
It provides an starting point for the program’s execution. You can turn a Scala object into an app
object with extends App; see Chapter 2.7. An alternative to defining an app object is to define
a main function.
a computer program that is meant for end users to use for a specific purpose ¶ See
Chapters 1.1 and 1.2.
1) to instruct the computer to execute a function; to call, to invoke; 2) (in Scala:)
a special name that makes it possible to call a method without explicitly using its
name ¶ See Chapters 5.3 and 6.2. A method named apply serves as the objects’ “default method”:
myObj(params) is shorthand for calling myObj.apply(params) and only works if the object has
such an apply method.
1) parameter expression; 2) parameter value ¶ This term is used widely outside of O1. Some use
it (carelessly) as interchangeable with parameter. On the other hand, it’s common to speak of
“arguments” when considering a function externally from its caller’s perspective (as in a
function-calling expression) and of “parameters” when considering a function’s definition and
implementation (especially: when speaking about parameter variables); some people argue that
that is the only correct usage. In O1, we have deliberately avoided “argument” in order to make
our terminology more consistent and the concepts hopefully easier to learn.
a mutable collection of fixed size that keeps its elements in order by their numerical index ¶
See Chapter 12.1 and cf., e.g., vector and buffer. In many programming languages, Scala included,
the array is a sort of “basic collection type” that has been used to implement many other types of
1) (traditionally:) a field of research that draws on multiple disciplines, including computer
science and psychology, and that seeks to model the human mind and to imitate it in programs
and computing devices; 2) (in casual current usage:) nearly any application that conveys an
impression of intelligence when observed by a (present-day) human or that entrusts a computer
with tasks that have been previously been carried out only by humans. ¶ Commonly abbreviated as
AI. Applications that are intelligent in the second sense usually do not at all attempt to imitate
human cognition. Many of the applications currently described as AI involve machine learning.
AI is commonly divided into narrow and general AI or in weak and
assembly, symbolinen konekieli
a common alternative name for symbolic machine language
to store a (new) value in a variable ¶ For instance, the Scala command myVariable = 10 is an
assignment. It assigns the new value ten to a (var) variable, replacing the value
that was previously stored in the variable. See Chapter 1.4.
myVariable = 10
a part of a recursive algorithm or program, in which the (sub)problem’s solution
can be worked out without a recursive call ¶ See Chapter 12.2.
a synonym for superclass
a basic unit of digital information, which may have one of exactly two values ¶ Short for “binary
digit”. The two possible values of a bit are often referred to as zero and one; a sequence of bits
can thus represent binary numbers. Computers represent different kinds of information as systematic
combinations of bits; see Chapter 5.4
(in Scala:) a sequence of one or more consecutive commands that has its own indentation level
and whose last command gives the value of the entire block ¶ For instance, a function body may be
defined as a block. Similarly, the then and else branches of a selection command may be blocks.
The block structure of a program affects scope. In particular: the scope of a local variable doesn’t
extend beyond the block in which the variable is defined; see Chapter 5.6.
see function body, class body
Scala’s data type for representing truth values. ¶ There are just two values of type
Boolean: true and false. See Chapter 3.3; see also relational operator and logical operator.
a setting in a debugger that causes a program run to pause once it reaches a specified execution
step ¶ See O1’s debugger tutorial.
(in Scala:) a mutable collection that keeps its elements in order by their numerical index and
supports the addition, removal, and replacement of elements ¶ See Chapter 1.5. Cf., e.g., array
and vector. Elsewhere within computing, the term has other meanings, too.
to prepare a program for execution or deployment ¶ This broad and vague term refers to all sorts of
automated steps that depend on circumstances. In many contexts, compilation is a central
part of building a program; building may also include automated testing and generation of documents
from code, among other things. For practical purposes in O1, building a program is synonymous with
a colloquialism for an error ¶ The word is especially often used of errors in program behavior:
runtime errors and logical errors.
see call by name
see call by value
a sequence of eight bits ¶ See Chapter 5.4.
a name for some languages that are frequently used as intermediate languages ¶ See Chapter 5.4.
For instance, the intermediate language that Scala programs are usually compiled to, which the
Java Virtual Machine, executes is known as bytecode.
to instruct the computer to execute a function ¶ See function call. Synonyms: invoke, apply.
a way of passing an expression as a parameter such that the expression is not evaluated
before it is passed to a function but whenever (or if) its value is actually used during the
function call ¶ See Chapter 7.2. If the value of a by-name parameter isn’t used in all the
possible scenarios, the parameter may be referred to as non-strict. A by-name parameter isn’t
evaluated lazily: instead, the expression is re-evaluated every time its value is needed.
In Scala, this is the other main parameter-passing mechanism alongside the still more common
call by value.
a lazy way of passing an expression as a parameter: the expression is only evaluated the
first time (if ever) is is needed, after which any subsequent use of the parameter reuses the
already-evaluated value ¶ Similar to call by name but differs from it in that the parameter
expression is not re-evaluated; i.e., the parameter variable is lazy. Call-by-need parameter
passing is directly supported by some programming languages, most notably Haskell. In Scala,
you can achieve the same effect indirectly by storing the value of a call-by-name parameter
in a local variable.
a way of passing a parameter such that the called function can manipulate a variable in the
calling code (rather than just receiving a value from a variable or elsewhere; cf. call by value) ¶
This is the original and — arguably — the only correct sense of the term. Call by reference
does not feature in nearly all programming languages, and you won’t encounter it in O1 or Scala.
Nowadays, some programmers use this term of any parameter whose value is a reference (i.e.,
a reference is passed as a call-by-value parameter). Although many deem that usage incorrect,
it has grown more common. In practice, it can be unclear what different people mean by “call by
a way of passing a parameter such that the parameter expression is evaluated eagerly, already
before the function call begins, after which the expression’s value is passed to the function ¶
In Scala, call by value is the default and most common way to pass parameters; its alternative is
a stack-like data structure that contains frames and that the computer uses to track active
function calls during a program run ¶ See Chapters 1.7 and 1.8.
a reserved word in Scala whose primary purposes are 1) to mark the start of each
pattern within a match command; 2) to start the definition of a case class ¶
See Chapters 4.3 and 4.4.
a Scala class that has been defined using the case keyword and that, as a consequence,
implicitly gains certain characteristics ¶ There’s nothing unique about case classes in the
sense that a regular class can also be programmed to do the same; however, the case keyword is a
convenient shorthand for giving a class a set of characteristics that is frequently useful. Here are
some main ones: 1) it’s easy to deconstruct an instance of a case class with a pattern
in a match command and thus extract the instance’s contents (Chapters 4.4 and 7.4); 2) a case
class’s toString method produces more readable output than the default toString that
other objects have; and 3) when applied to objects of a case class, the == operator compares
whether the objects’ instance variables have the same values (rather than whether two references
point at the same object, which is what the operator does by default; Chapter 3.3). In O1, case
classes don’t feature prominently, but they are common in Scala programs elsewhere.
(in Scala:) a reserved word used in exception handling to start a block that is executed in
case a runtime error occurred during the try block ¶ The catch block follows the try block
and is executed after it but before a possible finally block.
1) a data type of a kind of objects; 2) the definition of such a data type as program code ¶ See
Chapters 2.1, 2.3, and 2.4. A class defines what a particular type of objects are like; this
constrasts with a singleton object that is defined separately from all other objects. Whereas an
object represents a single “thing”, a class represents a more general concept that objects of that
class are individual occurrences of. A class can be instantiated, creating a new object of that
type, an instance of the class. See also trait, abstract class. (Clarification: In O1, we say
that a Scala class or trait is a data type or that it defines a data type. This simplifies things
slightly. To be more precise, a class or trait may define one or more types. Class Int, for
example, defines one data type, but Buffer defines multiple data types that differ in the
type parameter: Buffer[Int], Buffer[String], etc.)
the main contents of a class definition ¶ A class body defines the class’s instance variables
and methods. Commands written directly into the body of a Scala class, outside the class’s
methods, are executed when the class is instantiated; in other words, the class body serves as
the class’s constructor.
a file that is meant as input to the Java Virtual Machine and that contains instructions in the
JVM’s intermediate language ¶ Scala programs are usually compiled into class files
before being run by the JVM. Class files have the .class suffix.
see type hierarchy
a library that contains classes
a setting in some programming tools (including the JVM) that specifies which
folders and files the tool should look in to find a program’s components ¶ In IntelliJ,
you can adjust a module’s classpath by selecting File → Project Structure... → Modules
and finding the module’s Dependencies tab. One reason for doing so is to make one module
build on another; see Chapter 11.1.
a data structure that comprises a function definition as well as access to specific
variables defined in that function’s external context ¶ See Chapter 7.1.
see program code
see style conventions
togetherness, wholeness; the extent to which a program component forms a single, unified, and
cleanly delimited whole whose parts connect to one another ¶ For instance, a class is cohesive if
it defines a single, distinct concept and doesn’t have members that are extraneous or unconnected
to that well-defined purpose. Cohesion is a desirable characteristic in program design; see
a data structure that provides access to multiple values of a particular type ¶
In Scala, collections are objects. The values stored in a collection are known as its elements.
Collections come in many varieties that have different efficiency characteristics, among other
differences. Some collections store elements in a specific order defined by numerical indices.
Some collections are immutable, others mutable. Many collections are strict but some are
non-strict. Many collection types take type parameters. The collection types that come up in
O1 include buffers, strings, vectors, arrays, maps, lists, lazy-lists, and stacks.
Tuples can be considered an unusual sort of collection.
an instruction for the computer to do something ¶ In O1, we use this term in a loose and
informal sense to mean pretty much any sort of instructions issued to the computer. For instance,
statements that have an effect on program state are commands, as are effect-free expressions.
a text-based environment for using a computer ¶ A user who works at the command line launches
programs by typing in the program’s name (and additional information as appropriate). Typically,
the program will then print out some text in response. A command-line environment is often
thought of as an alternative to a graphical user interfaces; on the other hand, a command-line
environment may also appear within a GUI. Examples of command-line environments include
Windows’s Command Prompt and Linux’s Terminal. Chapter 5.4 shows a few examples of using
Scala programming tools at the command line.
a section of source code that is meant for human readers and that the computer does not interpret
as being part of the program that it executes ¶ Comments don’t affect what happens during a
program run. Appropriate use of comments is good style. See Chapter 1.2 and
O1’s style guide. See also documentation comment.
a singleton object that is the “companion” of a specific class and represents that very class
in an object-oriented program ¶ A companion object must have the same
name as its class companion and must be defined in the same source file; see Chapter 5.3.
The class and its companion have access to each other’s private members. One use for a companion
object is to store constants associated with the class; it may also store other information that is
associated with the general concept represented by the class but isn’t instance-specific.
the same as relational operator
an error that manifests itself when processing a program statically, that is, without running
the program; especially: an error observed as the program is compiled ¶ See Chapters 1.8,
3.5, and 7.3 and cf. runtime error and logical error. Many compile-time errors are syntax errors.
an auxiliary program that takes in source code and translates it to another representation;
especially: a program that does such translation statically, separately from any program
run ¶ Programs can be compiled into an intermediate language or directly into machine language.
Scala programs are most often compiled into an intermediate language that is compatible with the
Java Virtual Machine. See Chapter 5.4 and cf. interpreter. See also build.
1) (generally:) a part; 2) (specifically:) a GUI component
a device that processes information by executing programs ¶ A computer isn’t electronic
by definition, but most computers are electronic. See also computer system.
a combination of computer hardware and software ¶ A computer system can be a general-purpose computer
or an embedded system.
to combine by putting one after the other ¶ In programming, the word commonly applies to strings.
For instance, the strings "con" and "catenate" can be concatenated to produce the string
a class that is not an abstract class (and not a trait, either) ¶ An “ordinary class”. A concrete
class may not have abstract methods. A class doesn’t have to be abstract to serve as a superclass;
classes may inherit from a concrete class too, as shown in Chapter 7.5.
see type compatible
see text console
a variable whose value is known before the program is run and that permanently stands for that
value in the program ¶ See Chapter 2.6 and O1’s style guide. All
constants are fixed values. In Scala, practically all constants are val:gl:s <val variable>.
s <val variable>
a subprogram that is executed as part of the instantiation process ¶ The term refers
to the code that gets run on a newly created instance after memory has been allocated for storing
the instance. The primary purpose of a constructor is to initialize the instance’s state as
appropriate for the class in question. Many constructors take parameters
that specify what the new instance should be like, expanding on the general template of the class.
In Scala, it’s not necessary to write a separate constructor method (as in some other languages);
instead, the constructor comprises the instructions written directly into the class body; see
Chapter 2.4. However, it is possible to give a Scala class a separate constructor in order to
overload object creation; see, e.g., Chapter 4.1.
a parameter that is passed to a constructor ¶ See Chapters 2.3 and 2.4. Constructor parameters
are used when instantiating a class, thereby creating new objects. The most typical
thing to do with a constructor parameter is to assign its value to an instance variable, but some
constructor parameters have other uses during object initialization.
a variable that is used for accessing and modifying a collection of elements ¶ This is one of the
roles of variables. See Chapter 4.2.
any construct that is meant for organizing items of data ¶ The word is especially commonly (and
sometimes exclusively) used of structures that are designed to hold large amounts of data so that
the data can be efficiently processed; the implementations of collections are data
structures in this sense. Files also have their own internal data structures. In O1, we use this
term in a broad and loose sense that encompasses even relatively simple constructs; for example,
we may refer to an object as a data structure.
a definition of a particular form of data and what operations are available on that data ¶ See,
e.g., Chapters 1.3 and 2.3. It’s common to speak of simply “types” rather than “data types”.
Programming languages come with a selection of predefined data types for common needs; for
instance, Scala’s Int type represents integers and defines the fact that integers can be summed
(among other things). Moreover, programmers can define custom data types in their programs. See
also type parameter, static type, dynamic type, and class.
to attempt to locate and fix errors in a program; especially: to look for runtime
or logical errors
an auxiliary program that help the programmer to examine a program’s execution step by step
and examine the changing contents of memory ¶ A debugger can be used while debugging or to
explore program behavior for some other reason. This ebook has a separate page
on using a debugger.
a broad programming paradigm in which problems are primarily thought of in terms of definitions,
rules, constraits (etc.) rather than sequences of consecutive commands as in imperative programming ¶
See Chapter 11.2. Many rather different subparadigms are commonly listed as falling under the broad
umbrella of declarative programming. Functional programming is arguably the
most significant of these subparadigms.
a synonym for subclass
assessing a program or algorithm manually and without running it ¶ For instance, a programmer may
read a program’s source code onscreen or from a paper printout as they mentally work though the
a kind of GUI element; a window that is temporarily displayed to the user and that plays a role
in the “dialogue” between the user and the application ¶ See Chapter 12.4. Many applications
have a large main window with smaller dialogs popping up as needed.
a synonym for immediate subclass
a synonym for immediate superclass
one or more documents that explain a program to a human reader ¶ It’s especially common to write
documentation about the interfaces between program components; see Chapters 3.2 and 3.5. See
a comment that is formatted in a particular way, so that tools can semi-automatically generate
documentation for the program ¶ See Chapter 3.2. For instance, given a Scala program with
documentation comments embedded in its source code, the Scaladoc tool generates web pages that
document the program.
the conceptual area that a program is concerned with; a problem space; the “world” of a program ¶
For instance, the domain of a computer game encompasses the concepts and rules of the game world.
This sense of the word is not to be confused with network domains such as aalto.fi.
a programming language that is not meant for general use but tailored to a specific application
domain ¶ See Chapter 10.3. Commonly abbreviated as DSL.
a notation for calling methods that is characterized by a period-dot written between
the expression that identifies the target object and the method name ¶ Example: myObject.myMethod(myParam).
Dot notation is common in many object-oriented languages, Scala
included. See Chapters 2.1 and 5.2 and O1’s style guide. Cf. operator notation.
(in Scala and various other languages:) a data type that represents decimal numbers as
floating-point numbers ¶ See Chapters 1.3 and 5.4. The name is short for “double-precision
a program whose purpose is to govern the use of a particular auxiliary device, such as a mouse
or a graphics card ¶ Drivers help the operating system access auxiliary devices.
the principle of defining each aspect of a program in one place only ¶ Short for “don’t repeat
yourself”. Applied to source code, the DRY principle encourages the programmer to avoid writing
redundant code. Following the principle generally makes programs easier to modify. See, e.g.,
Chapters 1.4, 5.1, 7.3, and 9.3. There are various other programming principles that go by
different names but express essentially the same notion. Antonym: WETWET.
short for domain specific language
associated with a program run or with the process of executing a program; defined only at
runtime; non-static, changing ¶ There’s a duality to computer programs: they can be thought of
as both static and dynamic; see, e.g., Chapters 1.2 and 2.1. Things that happen at runtime, such
as the inputs that a program receives from its user, can impact on the program’s dynamic aspect
but not its static one. See also dynamic type.
the policy of choosing which function gets executed not before the program run (statically),
but during it (dynamically) ¶ In object-oriented programming, the main implication of
dynamic binding is that the system uses the dynamic type of the target object to decide which
method implementation to run; this decision is made when the method call actually happens at
runtime. That is, the choice of method implementation is affected by which subclass’s
instance the message-receiving object is. See Chapter 7.3.
see dynamic binding
an implementation technique in which subproblems’ solutions are stored in memory so that they can
be efficiently retrieved and applied (perhaps multiple times) while solving the greater problem at
hand ¶ Chapter 12.2 contains a simple example of dynamic programming. In this context, “dynamic”
doesn’t mean quite the same thing as elsewhere in O1. The word appears in the name of this technique
in part because it sounds fancy.
the type of a value ¶ Determined dynamically during a program run. An expression or
variable with a particular static type may have any value whose dynamic type is compatible
with that static type; see Chapter 7.3.
(of a programming language:) having a type system that does not specify different static types
for the parts of source code, instead checking only values’ dynamic types (at runtime) ¶ For
instance, in a dynamically typed language, variables don’t have different types and any value
be can assigned to any variable. Cf. statically typed. Dynamically typed languages include Python,
used in that way, too.
strict and occurring at an early stage ¶ Eager evaluation is the opposite of lazy evaluation
and differs markedly from other forms of non-strict evaluation, too. In Scala and many other
programming languages, eager evaluation is the default: variables aren’t lazy unless otherwise
specified, and a variable gets its values from an evaluated expression as soon as a value is
assigned (rather than when or if that value is later needed). Similarly, regular (i.e., by-value)
parameters are eagerly evaluated already before each function call starts and irrespective of
whether the function actually uses their values.
an integrated development environment (IDE) ¶ Eclipse
was used in early versions of O1.
an application for writing and modifying text
a function that never has an effect on program state ¶ See Chapters 1.6, 1.7, and 11.2
and cf. effectful function. Such functions are also called “side effects”.
The reason to call an effect-free function is to obtain its return value. Effect-free functions
resemble the functions that feature in school mathematics. Some of them are pure.
See also referential transparency.
a function that has (or may have) an effect on the program’s state ¶ See Chapters 1.6,
1.7, and 11.2 and cf. effect-free function. Effects include modifying the contents of a
buffer, updating the value of an object’s instance variable, and printing out characters
onscreen, among other things. In contrast, evaluating expressions, time passing during
computation, and events on the call stack are usually not considered to be effects. More generally,
a function is effectful in case calling it is significant beyond the fact that it returns a
value. An effectful function can be useful even if it doesn’t return a meaningful value; on
the other hand, an effectful function isn’t referentially transparent.
(Outside of O1, terminology varies. Effects in the sense described here are often referred to
as “side effects”. Some programmers use the term “effect” differently in
pure functional programming; see, e.g., “What do “effect” and “effectful”
mean in functional programming?”.)
the extent to which a program fulfills its purpose without wasting resources ¶ The word especially
often refers to how much time running a program takes and how much memory the program requires.
Efficiency is not a focus in O1 (but is in various follow-on courses); nevertheless see, e.g.,
Chapters 5.5, 12.1, 12.2, and 7.2.
1) a data item in a collection; 2) a GUI element
a computer system that has a limited, relatively narrow purpose ¶ Automated teller machines (ATMs)
and many robots are embedded systems, for instance, as are modern cars. Cf. general-purpose computer
and see Chapter 1.1.
a string that contains zero characters and whose length is therefore zero ¶ An empty string
is nevertheless an actual string (in Scala, it’s an object of type String) unlike a null
reference. See Chapters 1.4 and 4.1.
a word that refers to one or both of: 1) hiding information behind an interface
using access modifiers; 2) bundling subprograms together with the data that they operate on
(as in an object)
a marker written at the end of a section of code to signal that it ends there ¶ Scala’s end markers
use the reserved word end, as in end if or end myMethod. End markers aren’t obligatory in
Scala, but it is customary to write them in certain contexts so that the code is easier for humans
to read; see, e.g., Chapters 1.7 and 2.2 and the style guide.
a reserved word used in Scala (and other languages) for defining an enumerated type
a class that has only certain, predetermined instances, which have been recorded in program
code alongside the class itself ¶ For instance, the four cardinal compass directions can be
represented by a CompassDir enumeration that has precisely four instances: North, East,
South, and West — other instances of the class do not and cannot exist. Some programming
languages provide a special notation for defining enumerations, an example of which are Scala’s
enums; see Chapter 7.4. A similar goal can be achieved by means of a sealed class,
but enum is more succinct where each specific instance of a class is known in advance and can
be specified in detail.
see enumerated type
1) a defect in a program; a bug; a invalid, unintended, and/or problematic aspect of a program;
2) a shorter term for a runtime error ¶ Errors can be classified into compile-time errors,
runtime-errors, and logical errors. In some technical contexts, the word refers
specifically to runtime errors.
to determine the value of an expression ¶ See, e.g., Chapter 1.3. What the computer does
to evaluate an expression depends on the expression. For instance, to evaluate the arithmetic
expression 1 + 1, the computer needs to sum two integers; to evaluate an expression that
consists of a variable’s name, it needs to access the value stored in that variable.
A function-calling expression is evaluated by executing the function; the
expression’s value is the function’s return value. Expressions may be evaluated strictly
1 + 1
a part of memory (within a frame) that the computer uses as it evaluates expressions ¶
See, e.g., Chapters 1.3 and 1.7. This term is seldom used outside of O1. The evaluation area
plays a key role in this ebook’s animations of program execution; it’s a graphical simplification
of what the virtual machine does.
an action or occurrence that a program may react to ¶ Events that occur while the program is
running may be passed on to the appropriate event listeners. Such event-driven design is common
in graphical user interfaces, for instance. See also GUI event.
a program component, such as a function, that determines how the program should behave when a
particular sort of event occurs ¶ For instance, an event handler may contain the program code
that is executed whenever a user presses a key in an application’s graphical user interface.
An event handler is typically part of an event listener; see Chapters 3.1 and 12.4.
a program component that is notified whenever a particular sort of event occurs ¶ In O1,
we use this term to mean an object that is notified of events and that determines which
event handler should be executed in response to such occurrences; ee Chapters 3.1 and 12.4.
In some other contexts, “event listener” and “event handler” are effectively synonymous.
a term used of some runtime errors
detecting runtime errors and reacting to them ¶ See Chapter 11.3 and try, catch, and
to run (a program)
specifically stated; expressly written in program code ¶ Antonym: implicit.
a piece of program code that has a value ¶ See, e.g., Chapter 1.3. Examples of expressions
include literals, arithmetic expressions such as 1 + 1, the names of variables, and
function calls written into program code. Determining the value of an expression is known as
evaluating the expression. Cf. statement.
to mark a class or trait as being a subtype of another; to inherit; to mix
in ¶ See Chapters 7.3, 7.4, and 7.5. A subtype’s definition can be thought of
as an extension of the supertype’s.
memory that retains its contents even when powered off ¶ Hard drives are a typical example of
external memory; solid-state drives (SSDs) are another. Information in external memory is typically
organized in files. External memory is relatively inexpensive, and most computers have far more
external memory than main memory. Before a program can operate on the contents of external memory,
the relevant contents must be copied into main memory, which is a relatively slow operation.
Secondary storage and mass storage mean largely the same thing as external memory.
see member variable
a resource where a computer stores data; especially: a data resource stored on the computer’s
hard drive or in some other external memory ¶ See also text file.
(in digital imaging:) an operation that transforms an image or a part of an image ¶ For instance,
a grayscale filter takes in a color image and generates a variant of it where all the pixels
are various shades of gray. The word “filter” has further meanings in computing; as one example,
Scala’s collections have a higher-order method named filter.
a reserved word that 1) completely prohibits inheritance from a class, when used in front of
a class definition; 2) prevents overriding a method, when used in front of a method
definition ¶ See Chapter 7.5. Cf. sealed and open.
a reserved word used in exception handling to start a block that follows a try block
and is executed after the try block (and a possible catch block) irrespective of whether
a runtime error occurred while running the try block
ensimmäisen asteen funktio
a function that is not a higher-order function
a variable whose value the program never updates once the variable has been initialized ¶ This
is one of the roles of variables. See Chapter 2.6 and cf. constant
and val variable.
a variable or comparable data item that a program uses to indicate whether or not something is
the case ¶ See Chapter 5.6 and one-way flag. A Boolean variable can serve as a flag.
a way of approximating decimal numbers using a limited number of bits ¶ Common in digital
technology. A floating-point number is a combination of a sign bit, a multiplicative factor known
as a mantissa, a base number, and an exponent. The number two is usually used as the base; the
other components depend on the number to be represented. Floating-point numbers are briefly
discussed in Chapter 5.4.
a loop formed using the for keyword ¶ The for loops in O1’s examples are
for–do loops that traverse a particular collection and repeat an operation on each of
that collection’s elements in turn; see Chapters 5.5 and 5.6. for loops are often applied to
strictly evaluated collections, in which case the number of repetitions and the targeted
elements are known in advance; however, it’s possible to use a for on a non-strict collection
as well. In addition to for–do loops, Scala has for–yield expression and the for
keyword is otherwise versatile as well; for more information, see our Scala Reference, O1’s follow-on courses, or other resources.
another term for parameter variable ¶ Contrasts with actual parameter.
a part of computer memory that is reserved for keeping track of how a particular
function call proceeds during a program run ¶ See Chapters 1.7 and 1.8. Typical contents of
a frame include local variables, a memory area for evaluting expressions, and
information about where in the program’s the function was called and where execution should thus
resume once the function call is done. Each frame persists in memory while the function call is
ongoing. Together, frames form a call stack.
see solution stack
a program component’s full name, which includes the name of the containing package ¶ For instance,
the fully qualified name of Scala’s Int type is scala.Int, and the fully qualified name of the
sqrt function is scala.math.sqrt.
a subprogram; a part of a program that takes care of a specific task and that is executed whenever
a program calls it ¶ See Chapters 1.6, 1.7, and 1.8. To define a function, the programmer
defines its signature and its body. Where a function definition is available, it can
be called, causing its program code to be executed. Functions can be effectful
or effect-free. A method is a function associated with an object. See also
higher-order function and anonymous function.
the part of a function’s definition that defines which instructions are to be executed
when the function is called ¶ See Chapter 1.7. In Scala code, the body follows the
signature and an equals sign in a function definition.
1) an expression that is evaluated by executing the program code of a particular function;
2) the process generated by evaluating such an expression; the execution of a function’s program
code ¶ See Chapters 1.6 and 1.7. Many functions take parameters; the parameter expressions
are written into the function-calling expression. When a function call is executed, the computer
(in most cases) creates a frame to track the function activation and executes the instructions in
the function’s body. The value of a function-calling expression is the return value
produced by executing the function. In Scala, functions always return a value, although that value
may be just Unit to indicate the absence of a meaningful return value.
a literal that defines an anonymous function ¶ Scala has several alternative notations for
writing function literals; see Chapter 6.2.
a programming paradigm that relies on effect-free functions and immutable data and
that tends to make extensive use of higher-order functions ¶ See Chapter 11.2 and cf.
imperative programming. Functional programming is one of the main forms of declarative programming.
data stored in the computer’s memory that is inaccessible to the program that stored it ¶
For example, an object that no reference points to is garbage. In a correctly written program,
only data that the program no longer needs should become garbage. Memory allocated to garbage
should be released for other use via garbage collection.
the act of releasing memory taken up by garbage for other use ¶ Garbage collection can be
automatized, and many modern programming platforms do automatize it, the Java Virtual Machine
included. This prevents some memory leaks from happening.
a variable that is used for gradually combining multiple individual values into a result of some
kind ¶ For instance, a gatherer may store the accumulating sum of a sequence of numbers. This is one
of the roles of variables. See Chapters 2.6 and 5.5.
artificial intelligence that combines information broadly and is not tied to a specific application
like narrow AI is. ¶ This term is closely related to strong AI. General AI is a fantastically
ambitious goal; the existing practical applications that are currently referred to AI are narrow AI
a computer that is not tied to a particular application domain and that is designed to be used for
a variety of purposes ¶ For instance, the desktop and laptop computers that people commonly use are
general-purpose computers. People make a general-purpose computer do specific things by having it
run diverse applications. Cf. embedded system and see Chapter 1.1.
A variable that is visible all over the program. ¶ This term typically refers only to
variables defined outside of any class or object (even though, say, an object’s member variables
can also be public). Overuse of globals easily leads to spaghetti code.
a user interface that is based on not just text but also on graphical elements such as
windows and buttons ¶ See Chapters 2.7, 3.1, and 12.4. Commonly abbreviated as GUI. Graphical
user interfaces are common in modern applications; they are especially common in applications
whose users aren’t programmers themselves. See also command line.
short for graphical user interface
an element of a graphical user interface; especially: an element that appears within a GUI
window ¶ Buttons and text fields, for instance, are GUI components. The term is often used
synonymously with GUI element to mean any piece of a GUI, but in some contexts, the “component”
only applies to those elements that compose the actual contents of a GUI window (excluding,
e.g., dialogs and other windows).
a constituent part of a graphical user interface ¶ See GUI component.
an event associated with a graphical user interface ¶ Examples: a mouse movement or a press of a
key on the keyboard. See Chapters 3.1 and 12.4.
see hard drive
external memory implemented with a rotating magnetic disk ¶ Hard drives have been extremely common
during the past few decades, and continue to be common despite being increasingly displaced by
solid-state drives (SSDs).
the physical parts of computers and related devices ¶ Constrasts with software.
see class hierarchy
korkean tason kieli
a programming language that has a high level of abstraction and is independent of the specific
characteristics of the computers that run programs written in the language ¶ The “level” of a
language is a fuzzy term, but languages such as Scala are generally thought of as being quite high
up in abstraction. Cf. low-level language and machine language. High-level languages tend to be
more usable by humans than low-level ones.
korkeamman asteen funktio
a function that operates on other functions: takes them as parameters or returns them ¶ See
Chapter 6.1. Functions that aren’t higher-order functions may be referred to as first-order functions.
communication between a program and the world external to it; reading input and writing
output ¶ For instance, a program may interact with files (see Chapter 11.3), peripheral devices
(e.g., a keyboard, a display), and other computers on a network. I/O is short for “Input/Output”.
short for integrated development environment
a name given to a part of a program ¶ For instance, the names of variables, functions, and
classes are sometimes called identifiers.
a command that makes the computer select between two alternatives on the basis of what a Boolean
expression’s value is ¶ See Chapter 3.4. See also match.
a class that inherits directly from another class, with no intermediary classes in
between; a class that is a single “generation” below another in a type hierarchy ¶ Cf. indirect
subclasses, which are subclasses of a class’s immediate subclass.
a superclass that another class inherits directly, with no intermediary classes in
between; a class that is a single “generation” below another in a type hierarchy ¶ Cf. indirect
superclasses, which are superclasses of a class’s immediate superclass.
(of a collection or other object or data structure:) one whose state never changes during a
program run ¶ Vectors, for instance, are immutable collections: a vector, once created, always
stores the same elements. In contrast, buffers are an example of mutable collections. See
Chapters 4.2 and 11.2.
a common programming paradigm that relies on the manipulation of mutable data using ordered
sequences of commands (statements) and effectful subprograms and where
loops are the primary means of repetition ¶ See Chapter 11.2 and cf. functional programming.
1) the way an abstract model, plan, or algorithm works in practice; 2) the part of a program
component or other entity that the component’s users do not need to know in order to use it ¶
The word has a number of related meanings in programming. Examples: 1) a program or a subprogram
can be an implementation of a generic algorithm; 2) a program component such as a class can
have a public interface, which specifies how the component may be used, as well as a
hidden implementation that specifies what the computer does when the component
is used; 3) a function has a signature that outlines its usage and a body that serves as the
function’s implementation and that the function’s caller doesn’t need to know. Of course, the verb
“implement” has common meanings that also apply to programming (as in “I planned what my program
would be like and then implemented the plan.”).
unexpressed; not specifically stated; only indirectly deducible; not explicit
a circumstance where modifying one part of program code necessitates changes elsewhere in the
program, but this necessity is not obvious ¶ As one example, magic numbers often result in
implicit coupling. Programs with implicit coupling are generally harder to modify and prone to
(in Scala and some other languages:) a convenience command with which the programmer specifies,
in advance, that they are going to use tools from certain packages (or similar “toolkits”) in
the program code that follows. ¶ With the appropriate import command in force, it’s possible to
refer to a package’s contents succinctly, without having to type fully qualified names.
See Chapters 1.6 and 5.3. The REPL environment that we use runs certain import commands
automatically; see Chapter 1.6.
to set a line of text in from the margin ¶ Consistent indentation is a cornerstone of good
programming style; see Chapters 1.7, and 3.4 and O1’s style guide.
In some programming languages, indentations are purely a matter of style. In
others, indentations affect programs’ behavior: the programmer defines the structure of their
code by indenting it appropriately. Python is an example of a language in the latter group and,
since its version 3 (released in 2021), so is Scala.
the ordinal number of an element in a collection that numbers its elements ¶ Vectors, buffers,
and arrays are examples of numerically indexed collections. An element of such a collection is
accessible via its index; see Chapter 1.5. In some programming languages, indices run from one
upwards; that is, the first element is at index #1. In many other languages, including Scala,
indices start at zero.
a more precise term for operator notation
a principle of program design that seeks to separate interfaces from the underlying
implementations ¶ “Hiding” refers to the notion that the user of a program component (such as
a class) only needs to know about a “visible” interface. The user is allowed to “forget” about
the underlying implementation or be wholly ignorant of it. When implementation details are hidden
behind an interface, the implementor is free to change them as the program develops (e.g., to
improve efficiency): as long as the interface remains constant, no changes are needed to other
program components that use the changed component. See Chapter 3.2.
an object-oriented technique in which the relationship between a
supertype and its subtypes is represented by defining a superclass for the subclasses
that extend it ¶ See Chapter 7.5. Depending on one’s definition of inheritance, traits may
be viewed as a form of inheritance or as form of subtyping that is an alternative to inheritance.
data that a program receives from an external source; especially: input that the program receives
from its user (e.g., via a keyboard) ¶ See Chapters 2.7 and 11.3 and I/O. Data provided by an
application’s user via their keyboard is one kind of input, for instance. Some programs read input
from a file. GUI events can be a sort of input, too.
an object created using a class as a template; an individual occurrence of the general concept
that the class represents ¶ See Chapter 2.3. The concrete attributes of an instance are usually
not detailed in program code like those of a singleton object. Instead, the attribute values are
set when instantiating a class.
1) a class’s member variable; 2) an instance-specific copy of a class’s member variable, stored
in computer memory ¶ Instances’ attributes are stored in instance variables; see Chapter 2.4.
to create an object as an instance of a class ¶ See Chapter 2.3. Upon instantiation, some
memory is allocated for the new object, which is then initialized using the class’s constructor.
An instantiation command is effectively a special kind of function call.
an auxiliary program that provides a collection of programming tools, which may include an editor,
a compiler, or a virtual machine, for example ¶ See Chapters 1.2 and 5.4. Commonly abbreviated
as IDE. IntelliJ, which we use in O1, is an example of an IDE. As the name suggests,
programmers use IDEs to develop new programs.
an integrated development environment (IDE) ¶ Also known
as just IntelliJ or IJ. The free, open-source version of IntelliJ (Community Edition) is O1’s
official programming environment. It is supported by the A+ Courses plugin that makes it easier to
download and submit O1’s programming assignments.
1) the “façade” through which a program component or some other service is used; 2) (in some programming
languages:) a programming construct similar to a trait; see separate entry ¶
In O1, only the first meaning is important. For example, one can say that a class has an interface
that comprises its public aspects. To use a component, it’s necessary to know its interface but
unnecessary to know its implementation. See Chapter 3.2 and cf. user interface.
a construct that resembles abstract classes and especially traits ¶ This construct
is not present in Scala but in some other languages, most prominently Java.
a language that source code is compiled to but that is not actual machine language;
especially: a language used as the “machine language” of a virtual machine ¶ See Chapter 5.4.
an auxiliary program that runs a given program, translating it into machine language as needed ¶
For instance, a bytecode interpreter is one of the key components of the Java Virtual Machine.
See Chapter 5.4 and cf. compiler.
to instruct the computer to execute a function ¶ See function call. Synonyms: call, invoke.
1) repetition in which each cycle continues where the previous one left off; 2) the use of such
repetition to implement programs; especially: using a loop to repeat commands ¶ Cf. recursion
and see Chapter 12.2.
an object that enables its user to traverse the contents of a collection non-strictly
in a particular order ¶ See Chapter 11.3.
1) a programming language; 2) the so-called Java platform: a set of programming tools that includes
the Java Virtual Machine and that was originally designed for use with the Java language ¶ Java the
language is primarily designed for imperative object-oriented programming.
Java programs are normally run in the Java Virtual Machine, as Scala programs often are too. It is
easy for a Scala program to use libraries written in Java; see Chapters 5.4, 11.3, and 12.4.
a virtual machine ¶ See Chapter 5.4. Commonly abbreviated as the JVM. The Java Virtual Machine
was originally designed for use with the Java programming language, but it has since become
common to compile various other programming languages into bytecode that the JVM can run.
Scala is one such language.
is in widespread use in programs embedded in web pages. It has become common to compile
the Java Virtual Machine
a data item that can be used to locate or identify another data item; especially: a data item
used in a map for accessing the corresponding value ¶ See Chapter 9.2 and cf. index.
a pair formed by a key and a value ¶ Maps have key–value pairs as elements; see Chapter 9.2.
a simple GUI component whose purpose is to display some text and/or an image ¶ See Chapter 12.4.
a function literal ¶ This term is common in languages where function literals are formed using
the word “lambda” or the Greek letter of that name. Chapter 6.2 explains the term’s history.
an anonymous function ¶ This term is common in languages where anonymous functions are defined
using the word “lambda” or the Greek letter of that name. Chapter 6.2 explains the term’s history.
used as a synonym for dynamic binding (among other things)
non-strict and avoiding of repeated evaluation ¶ See Chapter 7.2. This adjective describes
a policy for evaluating expressions. A lazy variable gets a value from the assigned
expression non-strictly: only when or if the variable’s value is actually used. Once
that happens, the value is stored in the lazy variable and accessible to the program without
re-evaluating the expression. In Scala, the keyword combination lazy val defines a lazy
variable. The elements of a lazy collection, such as a lazy-list, aren’t necessarily formed
at all; only those elements that are actually accessed are formed, after which the collection
stores them in memory. See also call by need. Eager means the opposite.
an immutable, lazy collection, implemented as a linked chain of elements and suitable
for traversing in element order ¶ Lazy-lists are indeed lists that are evaluated lazily.
In Scala, they are represented by class LazyList. Since lazy-lists aren’t evaluated
strictly, they may be infinite and a higher-order method or
loop may traverse through an indefinite number of lazy-list elements. See Chapters 7.2
and 9.1. In older versions of Scala, a nearly identical collection type — Streams —
was used instead, and that old name still appears in some sources.
program code that has been developed by someone else in the past and that present-day programmers
have to live with — perhaps reluctantly — as they develop the software further ¶ This is
the term’s usual meaning programmer jargon nowadays. Originally, it referred to code that was
incompatible with current systems as it had been developed for systems that had since become
(in O1 means especially:) the extent to which a solution is independent from implementation
details ¶ General-purpose programming tools such as the while loop or the foldLeft method are
abstract in that they can be applied to different kinds of problems; they abstract over many more
use cases than, say, the size method, which does the specific job of returning a collection’s
size. However, from its user’s point of view, size is at a higher level of abstraction than the
general-purpose tools: its caller doesn’t need to know how it’s been implemented (with a loop, with
foldLeft, or in some other way); it abstracts over different implementations. This ebook uses
“level of abstraction” in the latter sense in several chapters, including 6.3, 7.1, and 9.1. See
also high-level language and low level language.
a collection of subprograms, classes, or other program components that can be used for
building different programs ¶ Some libraries, such as the Scala API, are deeply linked to a
particular programming language. Some libraries are very generic while others are tailored to
more specific needs.
a function that is defined in a library ¶ Describing something as a library function emphasizes
that the function isn’t custom-made for a particular application but comes from a general-purpose
a principle obeyed by stacks, according to which only the element that has been in the collection
for the shortest time may be removed ¶ Short for “last in, first out”. See Chapter 10.3.
a principle for defining data types, according to which it must be reasonable to use values
of a subtype (e.g., instances of a subclass) in any context that calls for a value of a supertype
(e.g., an instance of a superclass) ¶ See Chapter 7.5.
1) (generally:) any series or listing of items; 2) (in Scala and various other languages:) an
immutable collection implemented as a linked chain of elements and suitable for traversing in
element order ¶ In Scala, lists are represented by class List; see Chapter 7.2 and O1’s
follow-on courses. Lazy-lists are lists that are lazy. Different programming languages use
the name “list” for different kinds of collections.
a simple expression whose value is written directly into program code ¶ For instance, 10 is an
integer literal and "llama" is a string literal. See also function literal.
a species of mammal largely irrelevant to programming
a function that is defined within the body of another function and that can be used only by that
containing function ¶ See, e.g., Chapters 7.1 and 12.2 and cf. local variable. See also closure.
a variable defined within a function for the use of that containing function alone ¶ A programmer
can define local variables within a function’s body (see, e.g., Chapters 1.7 and
5.5); parameter variables can also be considered a kind of local variable. The values of local
variables are stored within frames on the call-stack, so they only exist temporarily while a
function call is running; however, see closure. See also scope.
an error that manifests itself as undesirable program behavior but not as a technical error ¶
Examples: a program that uses the wrong formula to compute results; a program that greets the user
with the wrong message; a program that fails to perform all the operations that it was designed to
perform. Cf. compile-time error and runtime error.
logiikkaoperaattori, looginen operaattori
an operator whose operands are truth values and that produces a truth value ¶ For instance,
&& (“and”) and || (“or”) are logical operators; see Chapter 5.1.
1) a part of a program that is executed repeatedly; 2) a programming-language command that defines
such a repeating section of program code ¶ See Chapters 5.5, 5.6, and 9.1. In Scala, loops can
be defined using the for and while keywords. Depending on the programming
language, it may also be possible to use a jump command such as goto to form a loop (see
Chapter 10.3). Loops are a common implementation technique for iterative algorithms.
matalan tason kieli
a programming language that has a low level of abstraction and depends on the specific
characteristics of the computers that run programs written in the language ¶ Machine languages,
especially, are referred to as low-level languages. It’s possible to program in low-level
languages and doing so may lead to improved program efficiency under the right circumstances,
but high-level languages are much more practical for many purposes.
see machine language
a programming language that processors (of a particular sort) can execute without modification ¶
See Chapter 5.4. Machine languages generally operate at a very low level and
are dependent on specific hardware. The machine-language instructions executed by the processor are
(binary) numbers, but a machine-language program can also be expressed in symbolic form.
These days, programs are usually written in a high-level language that is translated into machine
language before being run. The term “machine language” is sometimes used in a broad sense that also
encompasses symbolic machine code a.k.a. assembly and/or the virtual
machine languages used in virtual machines.
a subdiscipline of computing in which a piece of software or a computer system uses input data
to learn to make decisions, predictions, or other assessments about scenarios that resemble (but are
not identical to) those in the training data and that the programmer has not explicitly detailed as
code ¶ These days, many applications of machine learning impress people, so those applications are
often labeled artificial intelligence.
a (numerical) literal whose purpose in program code is not obvious ¶ Magic numbers (and other
“magic values”) can make a program harder to read, and repeated use of a magic number often creates
implicit dependencies. One way to avoid magic numbers is to define constants
instead; see, e.g., Chapter 2.6.
a function within an application that defines what the computer should do when the application is
launched ¶ The most convenient way to mark a Scala function as an app’s main function is to write
@main in front of its definition; see Chapter 2.7. An alternative to defining a main_function is
to define an app object.
memory whose contents a computer’s processor operates on ¶ Generally speaking, the contents of
main memory are lost when the computer is powered off; main memory thus differs from hard drives
and other forms of persistent external memory. When programmers speak of “memory”, they often
mean main memory. Primary storage means largely the same thing as main memory.
see app object
a collection whose elements are key–value pairs and that provide access to the values via
its key ¶ See Chapters 9.2 and 10.1. Maps come in mutable and immutable varieties; in Scala,
they are implemented as Map. Maps go by a variety of names in different languages, including
“dictionary”, “dict”, and “associative array”. This collection type is not to be confused with the
lower-case map, which is a method on various collections.
a Scala-command that makes the computer select between two or more alternatives by inspecting
which of the cases written into the program corresponds to the value of a particular expression ¶
Each of the cases written into a match command defines a so-called pattern, that the computer
attempts to match the expression’s value to. This pattern matching relies on the value’s
dynamic type. See Chapters 4.3 and 4.4 and contrast with if. See also case.
a constituent part of a class or a singleton object ¶ Especially: methods and member variables
a variable that is a member of a class or singleton object ¶ The member variables of a class
are called instance variables, since a copy of them is created in memory for each instance of
the class; see Chapter 2.4.
a computer’s component or auxiliary device that can store data either temporarily or persistently
(which depends on the memory hardware) ¶ The data that programs process is stored in memory,
usually in the form of bits. Each part of memory has its own address, a unique number that
identifies that specific memory location. In O1, the way programs use memory is depicted as
abstract, animated diagrams from Chapter 1.3 onwards. In this course and elsewhere, “memory”
often refers to main memory unless otherwise specified; cf. also external memory.
a defect that causes a program not to release some of the memory that it reserves even after it
no longer needs what is stored in that part of memory ¶ A program that leaks memory keeps reserving
more and more memory (perhaps little by little), which can eventually lead to errors
and program crashes once there is no more memory available. Failure to properly deal with garbage
causes memory leaks.
an instruction sent to an object; an invocation of an object’s method ¶ Object-oriented programming
is based on the notion that each object is capable of receiving a limited set of messages and
reacting to them; an object can also send such messages to other objects as it reacts to messages
that it itself received. See Chapter 2.1.
a function attached to an object ¶ What methods an object has determines what messages it can
receive and how it behaves when it receives them; see Chapter 2.1. Methods are defined as part of
a singleton object or class’s (or trait’s) definition. When reading other resources on Scala,
it’s good to be aware that all Scala programmers don’t delimit this term precisely like we do
in O1 and as the official Scala glossary does.
see function body ¶ Methods are functions, too.
a function call where the function is a method ¶ See Chapter 2.1. In Scala, method calls can be
written using the dot notation or the operator notation.
Musical Instrument Digital Interface, a standard for communicating with electronic musical instruments
and programming them ¶ See Chapter 1.4.
to mark a class or trait (or singleton) as being a subtype of a trait; to extend
a trait ¶ See Chapter 7.3. Multiple traits can be mixed in at once (cf. there may be only a single
1) a representation; (especially:) a representation of a program’s domain; 2) the part of an
application program that represents domain concepts (independently of any user interface) ¶
Programmers develop models of domains using the constructs available in the programming language,
such as classes. An application has a domain model and a user interface that provides a
view to that model; see Chapters 1.2, 2.7, 3.1, and 9.3.
(in IntelliJ:) a body of files and settings that forms a logical whole and helps
programmers manage multiple programs or program components ¶ A module (in this sense) is a concept
of the IntelliJ programming environment, whereas a package is a programming-language construct.
See Chapter 1.2. Some other IDEs use a different term for what
is essentially the same concept. The word “module” also has other meanings in other programming
an operator for computing the remainder of a division ¶ In Scala and many other programming
languages, the modulo operator is written as %. See Chapter 1.7.
a variable that is used for storing the latest value in a sequence of values ¶ This is one of the
roles of variables. For instance, a most-recent holder can be used for
tracking the latest value assigned to an object’s attribute (Chapter 2.6) or the latest collection
element that is being processed (Chapter 5.5).
a variable that is used for tracking which value best matches a particular criterion ¶ This is
one of the roles of variables. See Chapters 4.2 and 5.5.
inheritance from multiple immediate superclasses ¶ Scala doesn’t support
multiple inheritance from superclasses, but a class may extend multiple traits.
(of a collection or other object or data structure:) one whose state may change during a
program run ¶ Buffers, for instance, are mutable collections: a single buffer may have different
contents at different times. In constrast, vectors are an example of immutable collections. See
Chapters 4.2 and 11.2.
artificial intelligence that is limited to a specific application area ¶ For instance, a narrow
AI may be specialized in translating text, improving search results, driving a car, or recognizing
faces in an image. Antonym: general AI. Weak AI means almost the same.
such that parameter expressions are evaluated selectively ¶ See Chapter 7.2. This adjective
describes a policy for evaluating expressions. A non-strict parameter gets its value
from a parameter expression that is evaluated only in case its value is actually needed during
the program run; by-name -parameters are often non-strict. A non-strict collection
is a collection whose elements are only formed in case they are actually used; Scala’s lazy-lists
are an example of a non-strict collection type. Antonym: strict. See also lazy evaluation.
an Option-typed singleton object that does not contain a data item ¶ See Chapter 4.3 and cf.
Some. A reference to the None object cannot be assigned to just any variable, but it can be
assigned to a variable of type Option. This is one of the ways in which None is different from
the null reference, which can technically appear as the value of (almost) any variable.
a value that may be used to indicate the absence of data; a reference that does not specify any
actual location in the computer’s memory ¶ For instance, in Scala, the null reference is type compatible
with nearly all data types (cf. Option, which isn’t). Use of the null reference, although
technically possible, is a common cause of bugs. Many Scala programmers steer clear of null
altogether. See Chapters 4.2, 4.3, and 12.2.
a type of runtime errors that occur when a program attempts to follow a null reference to
access data that it points to (which data does not exist for null) ¶ For instance, if a Scala
program attempts to invoke a method on a variable that stores a null reference rather than a
reference to an existing object, a NullPointerException occurs; see Chapters 4.2 and 4.3. This
sort of error has this name in several programming languages, including Scala and Java; other
programming languages use other names for the same phenomenon.
the nickname of this course, CS-A1110 Programming 1 ¶ An abbreviation of the Finnish name
a software library developed for the purposes of this course, O1 ¶ Many of O1’s example
programs use this library. The library contains tools for building simple picture-based GUIs and
generating MIDI sound, among other things. The chapters of this ebook introduce selected parts of
O1Library. The library has documentation as Scaladocs, and there’s a short summary of
O1Library’s main GUI tools in O1’s Scala Reference.
(in Scala:) an alternative name of class AnyRef when using Scala on the JVM
an abstraction that represents a single “thing” or entity; a program component that is capable
of receiving messages and reacting to them as specified by the programmer ¶ Objects are key to
object-oriented programming; see Chapter 2.1. The programmer defines what functionality an object
has by associating it with functions; functions associated with an object are known as methods.
Some objects have mutable state, others don’t. See also singleton object and class.
a common programming paradigm in which a program’s domain is represented as objects and
message-passing between those objects ¶ See, e.g., Chapters 2.1 and 11.2. Often
abbreviated as OOP. Scala is a pure object-oriented language: all information is represented
as objects (see Chapters 5.2 and 5.3). Object-oriented programming is commonly associated with
additional constructs such as classes and inheritance, but not all forms of OOP feature
a variable that has exactly two possible values and never changes in value once its been changed
from its initial value to the other one ¶ This is one of the roles of variables,
a sort of flag. See Chapter 5.6.
short for object-oriented programming
a class that can be freely extended ¶ In Scala, the open keyword opens up a class for
extension; see Chapter 7.5. Traits and abstract classes are always open but regular
classes aren’t. Cf. sealed class, and see also final.
1) an expression that an operator is applied to; 2) the value of such an expression ¶ For
instance, in the expression 2 * (1 + 10) the multiply operator’s operands are the literal 2
and the arithmetic expression (1 + 10).
2 * (1 + 10)
(1 + 10)
a software system that governs the use of computing devices, provides certain services to
programmers, and lets end users launch applications ¶ Among its other responsibilities, an
operating system takes are of devices (including memory, processors, files, networks, and
various peripherals) and provides abstractions through which a programmer may use them.
a written character or combination of characters that, when used in source code, instructs
the computer to perform a particular operation ¶ For instance, + is an addition operator in
many programming languages and <= one of several relational operators. Like operators,
function calls also instruct the computer to perform operations, and the line between what counts
as an operator and what doesn’t is not always clear-cut. Usually, when people speak of “operators”,
they mean characters or short combinations of characters that are applied using a simple syntax
that differs from typical function calls. In Scala, operators aren’t a truly distinct language
construct; instead, one may use either the operator notation or the dot notation when calling
a method (Chapter 5.2). Methods such as +, on which it’s common to use operator notation, are
often called “operators” in Scala, too.
a notation for calling methods that is characterized by the absence of punctuation
in the method-calling expression ¶ Examples: myObject myMethod myParam and 1 + 1. In Scala,
operator notation can be used as an alternative to dot notation if the method is suitable; see
Chapter 5.2 and O1’s style guide. See also operator.
myObject myMethod myParam
a class whose purpose is to represent the possible absence — optionality — of a data item ¶
Each value of type Option is an object that either contains a single element of data (Some)
or is empty (None); see Chapter 4.3. Using Option makes the possible absence of a value
explicit in program code. Moreover, it helps programming tools provide error messages at compile-time
in many situations that would result in a runtime failure if Option’s alternative,
the null reference, was used instead. An Option is a simple kind of collection; see Chapter 8.4.
to define, within a single program component (e.g., a single class), multiple functions that
have the same name but that take different parameters and thus have different signatures ¶
See Chapters 1.6 and 4.1.
to re-implement a member (a method or a variable) rather than relying on an existing, more generic
definition ¶ A subtype may override a supertype’s method implementation with another that is
appropriate for that specific subtype’s instances; see, e.g., Chapter 7.3. Overriding can also
be done on just a single object to make it behave differently than other instances of a type; see,
e.g., Chapter 2.4.
a named bundle of program components ¶ For instance, a Scala program’s components are grouped into
one or more packages; see Chapters 1.2 and 1.7. A single package cannot contain multiple components
(e.g., multiple classes) that have the same name, but different packages can. Packages’
contents are often imported so that they can be used conveniently (without fully qualified names);
see Chapter 1.6. A single IntelliJ module may contain components that belong to several
packages. See also Scala API.
a tuple that has exactly two members ¶ Pairs are useful as key–value-pairs in maps. Another
common use case is to return two values from a function: even though a (Scala)
function can return only a single value, that value can be a pair. See Chapter 1.8 and especially
a GUI component that may contain various other components and that is used for grouping and
laying out the other components ¶ See Chapter 12.4.
a piece of information passed to a program component; especially: additional information that is
passed to a function and that elaborates on what the function call should do ¶ See Chapters 1.3,
1.6, 1.7, and 2.1. The parameters that a function takes (zero or more) are defined as part of
the function’s signature. When a function is executed, parameter expressions are evaluated,
producing parameter values, which are then passed into parameter variables that are located
within a frame that tracks the function call. (That applies to the usual case of strict
evaluation. In non-strict evaluation, parameter expressions are evaluated later or not at all.)
Different sources use different terminology about parameters; see argument for a discussion. See
also parameter list and type parameter.
an expression that is written into a longer function-calling expression and that
is evaluated to produce a parameter value ¶ See Chapters 1.3, 1.6, 1.7, and 7.2. Some others
use the term argument or actual parameter for what we call “parameter expressions” in O1; see
argument for a terminological discussion.
1) a listing of parameter variables that is part of a function definition; 2) a listing of
parameter expressions in a function-calling expression ¶ In Scala, parameter lists
go in round brackets. A function may have one parameter list (see Chapters 1.6 and 1.7), or none
(see Chapters 1.8 and 2.6), or several (see Chapter 6.1).
a value that is obtained by evaluating a parameter expression ¶ Under normal (strict) evaluation,
parameter values are passed into parameter variables that are located within a frame that tracks
the function call; see Chapters 1.3, 1.6, and 1.7. Some others use the term argument or
actual parameter for what we call “parameter values” in O1; see argument for a terminological
a local variable that is defined within a signature ¶ See Chapter 1.7. Also known as a
formal parameter or simply parameter. A parameter variable receives a parameter value when a
function call begins and stores it during the function’s execution. (At least that’s what usually
happens, but cf. call-by-name.) In Scala, parameter variables are always val:gl:s <val variable>.
(In Scala’s official terminology parameter variables are
actually parallel to local variables rather than a subordinate concept, but in O1 we use the term
as described here.)
a programming technique where a given expression’s value is compared to patterns, which are
descriptions of what that value’s type, structure, or other attributes might be ¶ In case the
expression’s value matches a particular pattern, some code associated with the expression is
executed. Not all programming languages support pattern matching, but quite a few do support at
least a limited form of it. In Scala, one of the main tools available for pattern matching is the
match command; see also case.
a class for representing images, defined in O1Library ¶ See, e.g., Chapters 1.3, 2.3, and 2.5
and the class’s documentation.
a point in a digital image ¶ What you see on a computer monitor is composed of pixels. Images,
written characters, etc. can be represented as combinations of differently colored pixels. Short
for “picture element”.
see text file
a class representing two-dimensional coordinates, defined in O1Library ¶ See, e.g., Chapters 2.5
and 3.1 and the class’s documentation.
(of a computer:) to write text ¶ In a programming context, the word often doesn’t refer to sending
documents to a printer device. A program may print text onscreen or in a text file, for example.
inaccessible to the outside; meant for internal use only; belonging to the implementation rather
than the interface ¶ See Chapter 3.2 and contrast with public. Scala and various other languages
use private as an access modifier. See also protected.
a common programming paradigm in which a program’s domain is represented as subprograms that
call further subprograms ¶ See Chapter 11.2 and cf. object-oriented programming, in which the
domain is structured in terms of objects and subprograms (methods) are associated with those
objects. Procedural programming is one of the main forms of imperative programming.
1) an effectful function; 2) (sometimes specifically:) an effectful function that does not return
a value or returns only a contentless unit value
a component of a computer that performs operations on data stored in memory or other inputs ¶
A processor executes machine-code instructions and thus enables programs to work. In addition to
a main processor (central processing unit; CPU), many computers have a separate graphics processor
(GPU), and other kinds of processors exist as well.
1) a combination of instructions meant for a computer to execute; 2) the dynamic process that
arises as a computer follows such instructions ¶ Applications, operating systems, and drivers
are different kinds of programs; see Chapter 1.2. Programs and their auxiliary resources are often
referred to as software.
1) a program text, source code; 2) a program encoded in machine language ¶ In O1, “program code”
generally refers to source code written in Scala; machine language comes up briefly in Chapter 5.4.
the development of computer programs: their design and implementation ¶ See Chapter 1.2.
an artificial language for writing or otherwise expressing programs ¶ Most programming languages
are written as text, but other media are also possible; for instance, there are visual programming
languages in which the program, or parts of it, are expressed as diagrams or other graphics.
a way of programming; a general approach to thinking about programs and solving programming
problems ¶ See Chapters 2.1 and 11.2. O1 touches on object-oriented programming,
imperative programming, functional programming, and (very briefly) procedural programming.
a way of writing programs that follows certain practices, principles, or policies; (often in
particular:) a way of formatting source code ¶ A good programming style helps people read and
modify programs; see O1’s style guide. Programming styles can be set
down as style conventions.
an access modifier that limits access to a member of a class ¶ Protected means something between
private and public: the member can accessed within the class itself and in any subtype definitions
(e.g., subclasses), but not elsewhere.
a textual description of an algorithm or a program that is meant for human readers and more or
less resembles programming language ¶ See, e.g., Chapter 2.5. Pseudocode is often less detailed
than concrete program code. It is generally not suitable for execution by a computer. Pseudocode
is used when planning programs and documenting them, among other things.
a number produced by an algorithm that mimics true randomness ¶ See Chapter 3.6 and random seed.
externally visible; accessible to the entire program; belonging to an interface ¶ See Chapter 3.2
and cf. private. In Scala, members of classes and objects are public unless their
visibility is adjusted with access modifiers.
a function that is effect-free and, moreover, independent of
program state and thus returns the same value every time it is called on the same
parameter values ¶ It’s possible for a function to be effect-free but not pure: for example,
consider an effect-free method whose return value depends on the state of a mutable object. If a
function is pure, an expression that calls it is referentially transparent.
a parameter that is passed to an algorithm that generates pseudorandom numbers and that the
algorithm uses to initialize itself ¶ Each run of a pseudorandom algorithm on the same seed produces
the same sequence of “random” numbers. See Chapter 3.6.
1) to receive data into a program from an external source (as part of I/O); 2) to access a
variable in order to obtain its value (when evaluating an expression that uses the
variable) ¶ See Chapter 11.3; see also input.
1) defining, describing, or implementing something in terms of itself; (especially:) defining a
a function so that it calls itself; 2) the use of such self-reference as an implementation
strategy for programs ¶ A recursive program reduces the problem at hand to a simple base case
by repeatedly solving a part of it with a recursive call. See especially Chapter 12.2; there’s
a small additional example in Chapter 7.2. See also structural recursion and cf. iteration.
a function call where the calling function and the called function are the same ¶ See recursion
and Chapter 12.2.
to edit a program or program component without changing what functionality it provides ¶ See,
e.g., Chapters 3.1, 7.3, and 9.3. The purpose of refactoring is to improve program quality.
It may result in the program being easier to extend and modify, for example.
a value that indicates where in the computer’s memory a particular piece of data is
located ¶ See, e.g., Chapters 1.5, 2.3, and 5.4. In Scala programs, references point to
objects that are stored in the computer’s memory.
arvon läpinäkyvyys, referentin läpinäkyvyys
a property that some expressions have: such an expression can be replaced by its value without
changing the program’s meaning ¶ As far as program correctness is concerned, it’s irrelevant whether
a referentially transparent expression is evaluated once, several times, or not at all, as
long as the program obtains the expression’s value. In order to be referentially transparent, any
functions that the expression invokes must be effect-free and otherwise
pure. This property can make programs easier to read and modify and is particularly
central to functional programming. See Chapter 11.2.
a programming environment where the user types instructions in a programming language, those
instructions get executed one by one as soon as they are entered, and the value of each
expression entered by the user is immediately reported onscreen ¶ REPL is short for “read–eval–print
loop”. Using a REPL is common in Scala programming (and various other languages as well); see
Chapter 1.3. A REPL is sometimes referred to as an “interpreter” or “interactive interpreter”;
the Scala REPL is also known as “Scala Interpreter”.
a word that has a specific meaning in a programming language or that is for other reasons
prohibited as an identifier in the language ¶ Scala has about fifty reserved words, including
val, def, import, true, this, object, class, private, if, match, case, and
for; see the end of O1’s Scala Reference for the whole list. The names
of common types, such as Int and String, aren’t reserved words as such, but to avoid
confusion, it’s nevertheless better to avoid them as identifiers.
1) to end the ongoing function call, produce a return value, and convey it to the function’s
caller; 2) a command (return) that, when executed, terminates a function call and
returns a value ¶ In Scala, the return command is infrequently used; see
Chapter 9.1. In some other programming languages, the corresponding command is used in all
functions that return a value.
the static type of a function’s return value ¶ May be marked explicitly in Scala code with a
type annotation or may (in most cases) be left implicit due to type inference.
the value that, upon completion of a function call, is conveyed to the function’s caller and
that becomes the value of the function-calling expression ¶ A function may use its return value
to communicate the result of a computation, for instance, or to signal whether an operation was
successful. Some functions have no meaningful return value; in Scala programs, such functions
return the Unit value. A Scala function’s return value is the value of the expression
that was evaluated last during the function call (assuming the call wasn’t terminated
due to a runtime error before a return value could be produced). See also return.
a representation for colors in which each color is specified as a combination of red, green, and
blue light ¶ Each of the three components is a number that indicates how much of that color there is
in the combination. See Chapter 5.4.
an operator that compares two values and forms a Boolean value that indicates the result of
the comparison ¶ For instance, the relational operator < can be used to construct the expression
10 < 100, whose value is true. Also known as a comparison operator. See Chapter 3.3; see also
10 < 100
a typical way of using a variable in programs; a brief decription of the way a variable is used in
a program ¶ See, e.g., Chapters 2.6 and 5.5. Roles include fixed value, temporary, gatherer,
most-recent holder, container, most-wanted holder, and one-way flag. Roles aren’t a technical
feature of a variable; a role’s purpose is to summarize, to a human, how a variable is used in a
a subprogram; in O1 and Scala’s terminology, a function
1) to make a computer act as specified in a program; 2) to act as specified by a program ¶
Examples: “Aurora ran the program and discovered that there was a bug.”, “The computer runs the
program, processing each instruction in turn.” Synonym: to execute.
an error that manifests itself only when the program is executed, typically because the computer
fails to perform some operation ¶ See Chapters 1.8, 4.2, and 4.3 and cf. compile-time error and
logical error. For example, in many programming languages, dividing an integer by zero produces a
runtime error, as does the computer running out of available memory. Unless successfully prevented
or handled, a runtime error usually causes the program run to “crash” and terminate.
ajonaikainen tyyppi, dynaaminen tyyppi
see dynamic type
a programming language ¶ Scala is designed to be a language that supports multiple
programming paradigms and combines them in a particular way. The language emphasizes the
object-oriented paradigm and lets the programmer combine OOP with
imperative and/or functional; Scala’s design
particularly encourages the latter. Please see O1’s FAQ for the reasons
behind Scala’s adoption in this course. Programs written in Scala are often executed on the
Scala.js and run in a browser.
an extensive multi-purpose API associated with the Scala programming language ¶ Consists
of packages whose names begin with scala. The contents of these packages are described as
Scaladocs; see Chapter 3.2. A part of the Scala API — the package known simply as scala —
is an inseparable part of the programming language; see Chapter 1.6.
for the JVM) ¶ Scala.js enables Scala programs to be run in a web browser.
Chapter 5.4 tells a little bit more about Scala implementations.
1) an auxiliary program that takes in source code written in Scala and annotated with
documentation comments and that generates documentation from that
input; 2) documentation generated by that tool ¶ See Chapters 3.2 and 3.5. Scaladoc documents
usually focus on detailing each program component’s public interface. The Scala API has
been documented as Scaladocs. Many programming languages come with a similar tool, such as Javadoc
(for Java) and Pydoc (for Python).
the part of the program within which an identifier (name) can be legally used to access a
program component ¶ For instance, in Scala, the scope of a class’s public method is the entire
program, whereas a private method’s scope is limited to the class itself (plus its possible
companion object), and a parameter variable’s scope to the function body. The block structure
of a program impacts on scope; see Chapter 5.6. See also Chapter 7.1.
a program written in a high-level language that meets one or more of the following criteria:
1) its code is relatively short;
2) its code consists of a sequence of consecutive commands;
3) it is interpreted rather than compiled;
4) its primary purpose is to produce an output of some kind from given input data;
5) it is an external auxiliary to some existing program or system;
6) it is used for automating a batch of commands that might be otherwise entered manually;
7) it is written in a scripting language ¶
This term has many entangled connotations that have evolved over time. As things stand, it’s
ambiguous enough that it might be best to avoid using it except where the intended meaning is
clear from the context.
a high-level language that is suitable for writing scripts ¶ PHP, Python, and Lua are examples
of programming languages that are often called scripting languages. Scala, too, can be used as a
describing a class or trait that cannot be directly extended except by code that is in
the same source-code file ¶ In Scala, classes are sealed unless otherwise specified.
Traits and abstract classes are open by default but may be marked as sealed.
See Chapter 7.4. Cf. open, and see also final and enumeration.
see random seed
the meanings of expressions in a programming language ¶ Commonly contrasted with syntax. For
instance, the Scala commands x = x + 1 and x += 1 differ syntactically but their semantics
is the same: each increments the variable x by one.
x = x + 1
x += 1
a logical operator whose second operand is not evaluated if the first operand is enough to
determine the value of the logical expression ¶ See Chapter 5.1. In other words, a short-circuited
operator is evaluated non-strictly.
an operation that modifies state; in O1’s terminology, an effect on program state ¶
This term is common among functional programmers who seek to avoid effects.
1) the part of a function’s definition that defines how the function may be called; 2) a similar
definition for a program component other than a function ¶ A Scala function’s signature consists of
its name, its parameter variables, and its return type. (Anonymous functions are an exception
to this, since they have no name.) A function’s body isn’t part of its signature. Some
other programming languages define signatures somewhat differently than Scala, but the basic idea
is the same. In addition to knowing a function’s signature, any user of a function should of course
know the function’s purpose. See also overloading.
1) an object that is defined as an individual case rather than as an instance of a class;
2) the definition of such an object in program code ¶ See Chapters 2.1, 2.2, and 5.3 and cf.
instance. In Scala, a singleton object may be either a class’s companion
or a standalone object.
a program or combination of programs, which may include auxiliary files in addition to the actual
runnable program(s) ¶ Contrasts with hardware.
a chosen combination of tools that a particular company, community, or individual programmer uses
as a platform for building applications ¶ This is software-business jargon. A company’s solution
stack may include, among other things, an operating system, one or more programming languages,
databases, web server software, etc. The fashionable expression full stack refers to programming
that takes place on “multiple levels of the stack” using a variety of tools; in particular, it often
refers to programmers who work on a web application’s browser-based user interface as well as its
internal implementation on a server computer. The word “stack” has various meanings,
this being just one.
a class that represents Option objects that do contain a single data item ¶ See Chapter 4.3
and cf. None. Some is a subclass of Option; see Chapter 7.5.
placing the elements of a collection in order by some criterion ¶ For instance, one may sort
a collection of numbers in ascending or descending numerical order; see Chapter 10.1. The sorted
elements may be placed in an entirely new collection or, if the unsorted collection is mutable,
sorting may also happen “in place”.
textual, uncompiled program code that is meant for a human to work with ¶ See Chapter 5.4.
In O1, we work with source code that’s written in Scala.
messy, poor-quality program code whose parts depend on each other in a complex way ¶ Spaghetti code
is difficult to reason about. It may also be difficult to develop further, as changes to one part of
the program impact on various other parts. This kind of code is particularly problematic in large
1) a collection that follows the LIFO principle; 2) call stack; 3) solution stack ¶ The
term has still more meanings in various subfields of computing.
a report, typically produced when a runtime error occurs, that details which calls
were active when the report was generated ¶ Stack traces help programmers debug their programs.
See Chapter 4.2. Also known as a traceback.
a singleton object that is not a companion object
a body of data stored at a given moment of time ¶ In programming, the term refers especially to
data stored in the computer’s memory. A program execution, as a whole, has a state; effects such
as assigning to var-variables mutate that state, causing the program to be in a
different state at different times while it executes. Functions can be classified as being
either effectful or effect-free on the basis of whether
they impact on state. In object-oriented programming, each object has a state (see, e.g.,
Chapter 2.1), which may be either immutable or mutable; objects’ states are part of the program’s
overall state. Some programming paradigms differ from each other in how they represent state and
a command that orders the computer to perform a particular operation ¶ For instance, the print
command println(1 + 1) and the assignment a = 10 may be referred to as statements. A statement
doesn’t necessarily have a meaninful value; a Scala statement, for instance, may evaluate to just
Unit and nevertheless be useful. A statement may contain expressions that are evaluated when
the statement is executed: the statement println(1 + 1) contains the expression 1 + 1, for
instance. Even an individual expression may form a statement. Statements put in a sequence are
executed one after the other, in order. In Scala, function and method definitions and import
commands are officially considered statements, too; on the other hand, they aren’t expressions
since they don’t evaluate to a value. (Cf. a print command is not only a statement but also an
expression, since it evaluates to a value, even if that value is just Unit.) The concept of
statement is associated mainly with imperative programming; in pure functional programming,
the concept of expression usually suffices. In O1’s materials, this term is seldom used.
println(1 + 1)
a = 10
1) involving, or present in, program code; determinable from program code without running it;
defined fully by program code; non-dynamic, unchanging; 2) associated with a class rather than
its individual instances ¶ There is a duality to computer programs: you can think of them as both
static and dynamic; see, e.g., Chapters 1.2 and 2.1. Things that happen at runtime, such as the
inputs the program receives from its user, cannot impact on the program’s static aspect. See also
the data type of a piece of program code, which can be determined and checked statically,
without running the program ¶ In statically typed languages such as Scala, expressions and
variables have static types. For instance, the static type of a Scala variable constrains the
values that can be assigned to a variable: an attempted assignment produces a compile-time error message
if the source expression is not type compatible with the variable. See Chapter 7.3 and cf. dynamic type.
(of a programming language:) having a type system that attaches a data type to parts of
source code (i.e., the parts of the program’s static form; expressions and variables in
particular), which type can be checked statically ¶ Scala is statically typed: variables
and expressions have static types (in addition to their values having dynamic types). Scala
is also typesafe, so an attempt to assign a String value to an Int variable produces
a compile-time error message. Other statically typed languages include Java, C#,
and Haskell, among many others. Cf. dynamically typed.
a variable used for tracking the latest value while advancing along a sequence of known values ¶
This is one of the roles of variables. See Chapters 3.1 and 5.5.
For instance, a stepper may keep track of a steadily incrementing ordinal number: 0, 1, 2, etc.
(in Scala:) a collection very similar to a lazy-list, used in earlier versions of the language ¶
Since Scala version 2.13, the Stream class has been superseded by LazyList, but the old name
still appears in some sources. The word “stream” also has other more or less related meanings
such that expressions are evaluated at least once ¶ See Chapter 7.2. This adjective describes a
policy for evaluating expressions. A strict parameter gets its value from a parameter expression
that is evaluated at least once irrespective of whether the value is actually used by the program.
A strict collection is a collection whose every element is formed in memory irrespective of whether
all of them will be actually used. Most programming languages rely on strict evaluation. Scala is
primarily strict, too: function parameters are strictly evaluated by value unless
otherwise specified, and most common collections (vectors, lists, maps, etc.) are strict.
(These tools can be additionally described as eager, since evaluation takes place at an early
stage rather than when each value is needed.) Antonym: non-strict.
an sequence of (written) characters ¶ For instance, the string llama consists of five characters
in a specific order. Strings are one of the most common types of data that appear in
computer programs. In Scala, the primary representation of strings is the type known simply as
String (Chapter 1.3), but there are alternative representations, too (see, e.g., Chapter 11.2).
Many programming languages’ standard libraries provide subprograms for manipulating
strings in various ways (see, e.g., Chapter 5.2 and O1’s Scala Reference).
A string is a sort of collection with individual characters as elements (Chapter 5.6).
a programming technique where expressions are embedded into string literals in order to
create a string that contains descriptions of the embedded expressions’ values ¶ Introduced in
Chapter 1.4; chapters with further examples include 1.6, 2.4, and 2.5.
artificial intelligence that combines information broadly and is not tied to a specific application
are like weak AI is. ¶ This term means almost the same as general AI. It often carries a further
connotation of human-like consciousness, and perhaps feelings. Strong AI is a fantastically
ambitious goal; the existing practical applications that are currently referred to AI are weak
a form of recursion in which the definition of a data structure (such as a class) refers to
itself ¶ See Chapters 2.6 and 12.2. For instance, the definition of a person class might include
the person’s parents, which are of that same person type. Often, a good way to process structurally
recursive data is to use recursive calls that apply to ever smaller parts of the original data.
a set of recommendations on programming style ¶ Style conventions seek to promote better
readability and otherwise improve code quality. Different programming languages are associated
with their own style conventions, and even a single language will often have several alternative
conventions; a commercial company may specify its particular recommendations or requirements, for
instance. O1’s style guide describes one set of conventions for Scala.
a class that inherits another class and represents a subordinate concept of what that
superclass represents ¶ A subclass inherits the characteristics of its superclass; see Chapter 7.5.
A subclass’s instances have the type defined by the superclass in addition to the type defined by
the subclass. In many programming languages, Scala included, a subclass is defined by writing a class
definition that specifies the class’s immediate superclass; in Scala, a class can have only a single
immediate superclass. Cf. mixing in a trait and see multiple inheritance.
a class that one or more classes inherit from and that represents a superordinate
concept of what those subclasses represent ¶ The characteristics of the superclass are
inherited by its subclasses; see Chapter 7.5. A class may have multiple immediate
subclasses but (in Scala) only a single immediate superclass. Cf. trait.
a library for programming graphical user interfaces ¶ There’s more than one Swing: a library of
this name was originally developed for the Java programming language, but Scala has an identically
named library (which is built on the Java one). See Chapter 12.4. See also O1Library.
a programming language whose instructions directly correspond to machine code
but are represented symbolically (as text) rather than in binary ¶ Also known as “symbolic machine
code”, “assembly language”, or just “assembly”.
a syntactical feature of a programming language that does not make the language more
expressive, and is in that sense unnecessary, but that is intended to make program code easier
to read or write ¶ See Chapter 4.1. Examples of syntactic sugar in Scala include: the option of
defining instance variables and constructor parameters together (Chapter 2.4); operators such as
+=, which combine arithmetic with assignment (Chapter 4.1); various kinds of function literals
(Chapter 6.2); and for loops (Chapters 5.5 and 6.3).
rules that govern how things are expressed in a programming language ¶ Syntax defines what pieces
program code consists of and how the programmer may combine those pieces. Syntax is commonly
constrasted with the semantics of what those expressions mean.
an error that arises from a violation of the programming language’s syntax in source code ¶ See
Chapters 1.8 and 3.5. Syntax errors are often detected at compile time.
a variable that plays an interim role within the implementation of an algorithm ¶ This is one of
the roles of variables. See Chapter 2.6.
the assessment of a program in order to detect errors and other problems; especially:
assessing a program or program component by running it so as to detect runtime errors and
logical errors ¶ A simple form of testing is to run a program, function, or class on selected
parameters or other inputs. A more sophisticated strategy is to write so-called unit tests,
which can be run to check a program’s components systematically, repeatedly, and at least
semi-automically; unit-testing tools are discussed in O1’s follow-on courses.
a GUI component where the user can enter and edit textual input; especially: a GUI
component with that purpose that supports multi-line input ¶ Cf. text field.
an environment where a program’s output appears in text form and where some programs read
keyboard input ¶ Many programming environments include a text console; IntelliJ,
for one, does. The output of a Scala program’s println commands typically shows up in the
console. Some programs have a user interface that operates fully in a text console and isn’t
graphical; see, e.g., Chapter 2.7.
a GUI component where the user can enter and edit textual input; especially: a
single-line GUI component with that purpose ¶ Cf. text area.
a file whose data is meant to be interpreted (purely) as a sequence of written characters ¶ See
Chapters 5.4 and 11.3.
(in Scala and other languages:) a special parameter variable that all methods implicitly
have and that refers to the object whose method has been called ¶ See Chapter 2.2.
(in Scala:) a method whose purpose is to return a description of an object as a String ¶
See Chapter 2.5. All Scala objects have some sort of toString method, which is used by other
functions; for instance, the command println(myObject) prints out a string representation of
the object, which it obtains by calling the object’s toString method (as if we had written
println(myObject.toString)). toString methods are helpful in the REPL and when debugging
and have other uses as well.
another name for stack trace
(in Scala:) a type-defining construct similar to a class, which 1) may have
abstract methods and variables; 2) cannot be instantiated directly but only
through its subtypes; 3) can be “mixed in” to a class that defines a
subtype of the trait, perhaps among other traits that are also mixed in to the same class; and
4) may not pass constructor parameters to its supertype ¶ See Chapters 7.3, 7.4, and 7.5.
Trait definitions resemble class definitions but begin (in Scala) with the trait keyword rather than
class. Traits are conceptually similar to superclasses (abstract superclasses
especially), but differ from them in certain respects. In particular, a class may mix in multiple
traits but can have only one immediate superclass. Apart from the differences listed above and in
Chapter 7.5, what this ebook says about classes usually applies to traits, too.
a value that concerns the truthfulness of a proposition; especially: a value that indicates whether
a proposition is true or false ¶ In programming, it’s common to use Boolean logic, in which any
proposition is unambiguously either true or untrue; see Chapter 3.3 and Boolean.
(in Scala:) a reserved word used in exception handling to start a block whose execution
may fail due to a runtime error
a combination of a fixed number of values in a specific order ¶ See Chapter 9.2. A tuple with
two members is known as a pair. A tuple can be thought of as a collection, albeit an unusual
one: each member of a tuple has its own static type, unlike the elements of other collections,
which share a type. For this reason, you cannot iterate over the contents of a tuple as simply
as you can iterate over a collection’s elements, and tuples have a more limited selection of
methods availaible. In Scala, tuples are immutable.
(in a programming context usually:) data type
an indication of a static type written explicitly into source code ¶ Type annotations may
make a program text easier to read; sometimes they also indirectly boost a program’s efficiency. On
the other hand, some type annotations are unnecessary and can make it inconvenient to write and read
code. In many statically typed programming languages (e.g., Java), the types of each variable
and return value must be expressly written in the source code. In contrast, in
dynamically typed languages (e.g., Python), type annotations aren’t (normally) written at all.
In Scala, you may always add an explicit type annotation but many annotations may be omitted
because of type inference; see Chapter 1.8. There are contexts where Scala requires an explicit
type; these commonly involve parameter variables; empty collections (see Chapter 1.5);
overloaded methods; or recursive functions. In some cases, type annotations can
help the Scala compiler produce clearer error messages. It’s often a good idea to annotate the
public members of Scala classes.
(of data types:) compatible in such a way that a value of one type can be used where a value of
the other type is expected ¶ Example: if the Scala class Student is a subclass of class Human,
the Student type that it defines is type compatible with type Human and it’s valid to assign
a reference that points to a Student instance in a variable of type Human. All types in Scala
are type compatible with the Any type. See also Liskov substitution principle.
a whole formed by classes and/or traits that describe super- and subordinate types;
a “family tree” of classes ¶ We use this term both for trait-based subtyping as well as class-based
subtyping (i.e., inheritance); see Chapters 7.3 and 7.5.
the automatic and static detection of the types of expressions and variables in a
program ¶ Type inference is an integral part of the Scala language. See Chapter 1.8. Chapters 3.5
and 7.3 also touch on the topic.
a piece of type information that is needed by some classes and some methods and
that further specifies a data type ¶ For instance, many Scala collections take a type parameter
that specifies the type of a collection’s elements; see, e.g., Chapters 1.5, 4.3, and 8.1. In
Scala, type parameters, like many static types, can be automatically inferred.
the extent to which a programming language enforces the constraints of each data type on what one
may do with values of that type ¶ See Chapter 1.8. A type-safe language only lets the programmer
use a value for operations that are expressly allowed for the value’s type. Scala is a particularly
type-safe language, and Scala tools alert the programmer to most type errors with compile-time error messages.
See also static typing.
a set of rules that governs the use of data types in a particular programming language ¶ See
static and dynamic typing and type safety.
a character set and an associated set of standards ¶ See Chapters 5.4 and 5.6. The Unicode
standard defines, among other things, a unique number for each different character in a vast
character set. Unicode is common in many contexts, including Scala programs.
käyttötavan yhtevyys, yhtenäinen osoitusperiaate
a design principle for programming-language syntax that states that a programmer who uses a
particular program component should be able to use the same notation for accessing all of that
component’s functionality irrespective of how that functionality has been implemented ¶ In
particular: the user of an object should be able use the same notation for calling a parameterless method
that they use for accessing the value of a member variable. See Chapters 2.6 and 7.3.
1) the name of the unit type in some languages, Scala included; 2) a Scala literal whose value
is the unit type’s one and only value ¶ See Chapters 1.6 and 4.3. A common use for Unit is to
signal the fact that a function has no meaningful return value. Scala’s Unit literal is written
as a pair of empty brackets: ().
a data type that permits only a single value and that therefore cannot represent information ¶ See
Chapter 1.6. There is exactly one value of the unit type. In some languages, Scala included, that
value is named Unit.
the part of a program or device that users interact with ¶ An application’s user interface may
be textual and run in a text console, for instance, or it may be graphical.
See also view and cf. model.
(in Scala:) a variable whose value cannot be replaced by another ¶ See Chapter 1.4 and cf.
var variable. In Scala, most val variables are defined using the val keyword, but there
are some exceptions: parameter variables and the most-recent holders defined as part of a
for loop are vals, too. One use for vals is to define constants, but not all vals
1) a single “granule of data” that cannot be simplified further; the result of evaluating
an expression completely; 2) the second member of a key–value pair in a map ¶ For instance,
the value of the arithmetic expression 1 + 1 is the integer two (Chapter 1.3), the value of the
function call min(10, 5) is five (Chapter 1.6), and the value of the expression Buffer(10, 2, 3)
is a reference to a buffer (Chapter 1.5). In O1, we use the term “value” in a subtly
different sense than some other sources that refer to any (Scala) object as a value.
Buffer(10, 2, 3)
(in Scala:) a variable that is defined using the var keyword and whose value may be
modified by assigning a new value that replaces the earlier one ¶ See Chapter 1.4 and
cf. val variable.
a named storage for a single value in the computer’s memory ¶ See Chapters 1.4 and 2.6.
an immutable collection that associates each element with a numerical index and enables
efficient access to the elements by index ¶ See Chapter 4.2. Cf., e.g., array and buffer.
1) the part of an application that is visible to the user; user interface; 2) (especially:) the
part of a user interface that presents a domain model to the user ¶ The second, narrower
meaning distinguishes the view not only from the model but also from those parts of the user
interface that react to the user’s actions and update the model; see Model–View–Controller on Wikipedia. O1Library
contains a a class of the same name.
a class for creating graphical user interfaces, defined in O1Library ¶ A View object provides
a view to same object that serves a domain model. Various event handlers can be defined on
a View. See Chapters 2.7, 3.1, and 3.6 and the class’s documentation; there’s
an example on O1’s Scala Reference page, too. (Quite separately from O1’s
View class, the standard Scala API provides a different type
that is also called View and that enables non-strict access to a collection. You won’t need it
artificial, simulated, mimicked; real (only) in appearance; akin to something despite not actually
or officially being that thing ¶ See also virtual machine.
a computer that is virtual rather than physical ¶ In computing, this term is used for a variety
of loosely similar purposes. For O1 and Scala programming, the most relevant virtual machines are
program that behave like a computer and that help execute other program; see Chapters 5.4 and
10.3. Such a virtual machine takes programs in a particular language as input; that language is
effectively the virtual machine’s machine language. A virtual machine contains an interpreter
(or is an interpreter, depending on how you define that term) that it uses to translate the given
programs into actual machine code.
1) scope; 2) (more specifically:) the part of an identifier’s scope where the identifier is
not “hidden” by another identifier of the same name (that is defined in an inner block)
another term for access modifier
a notification from a programming environment or tool that alerts the programmer to a suspected
problem in their program that may or may not be an actual error ¶ See Chapter 3.5.
artificial intelligence applied to a narrow speciality ¶ This term means almost the same as
narrow AI. It’s often used when contrasting specialized applications with strong AI that has
a human-like consciousness.
violation of the DRY principle ¶ Short for “write everything twice write everything twice”.
a loop that has been formed using the while keyword at the top and that repeats
an operation zero or more times ¶ See Chapter 9.1.
“invisible” characters that create horizontal or vertical space in a text ¶ Examples include space,
tabulator, and newline characters.
1) to output text or binary data from a program to an external destination (as part of I/O);
2) to assign to a variable ¶ See Chapter 11.3. See also print.
You can use this form to report errors, request additions to the page,
or send other feedback.
Thousands of students have given feedback and so contributed to this ebook’s design.
The ebook’s chapters, programming assignments, and weekly bulletins have been written in
Finnish and translated into English by Juha Sorva.
The appendices (glossary, Scala reference,
FAQ, etc.) are by Juha Sorva unless otherwise specified on the page.
The automatic assessment of the assignments has been developed by: (in alphabetical order)
Riku Autio, Nikolas Drosdek, Joonatan Honkamaa, Antti Immonen, Jaakko Kantojärvi, Niklas
Kröger, Kalle Laitinen, Teemu Lehtinen, Jaakko Nakaza, Strasdosky Otewa, Timi Seppälä,
Teemu Sirkiä, Anna Valldeoriola Cardó, and Aleksi Vartiainen.
The illustrations at the top of each chapter, and the similar drawings elsewhere in the
ebook, are the work of Christina Lassheikki.
The animations that detail the execution Scala programs have been designed by Juha
Sorva and Teemu Sirkiä. Teemu Sirkiä and Riku Autio did the technical implementation,
relying on Teemu’s Jsvee and Kelmu toolkits.
The other diagrams and interactive presentations in the ebook are by Juha Sorva.
The O1Library software
has been developed by Aleksi Lukkarinen and Juha Sorva. Several of its key components
are built upon Aleksi’s SMCL
The pedagogy of using O1Library for simple graphical programming (such as Pic) is
inspired by the textbooks How to Design Programs by Flatt, Felleisen, Findler, and
Krishnamurthi and Picturing Programs by Stephen Bloch.
The course platform A+ was originally created at Aalto’s LeTech
research group as a student project. The open-source project
is now shepherded by the Computer Science department’s edu-tech team and hosted by the department’s IT
Markku Riekkinen is the current lead developer; dozens of Aalto students and others have also contributed.
The A+ Courses plugin,
which supports A+ and O1 in IntelliJ IDEA, is another open-source project. It has been designed and
implemented by various students
in collaboration with O1’s teachers.
For O1’s current teaching staff, please see Chapter 1.1.
Additional credits appear at the ends of some chapters.