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.
Chapter 1.2: Introduction to Programming

Before you proceed
Did you already complete your O1 enrollment here in A+? (Not just in Sisu.)
If you did, great. Go ahead and get started with this chapter.
If you didn’t, please visit our front page and click the enrollment link near the top. You need to do that before you can make progress on O1’s assignments.
Creating and Running Programs
A traditional way to describe programming is to compare it to cooking. Here’s that comparison in interactive form:
Running a program

The programmer defines how they want the computer to act when it runs a program. For instance, if the programmer is writing an application for handling course enrollments at a university, they might include an instruction like this: “Whenever the user clicks this particular button, add the user to the list of people enrolled in the course.”
The user of an application program has access to a copy of the program, perhaps stored on their own computer. When the user starts up the program, the program is run (or executed; ajaa, suorittaa) and the computer follows the instructions set down in the program.
Consider an example. A user clicks an icon to tell the operating system they wish to launch a word-processing application. The computer will now act as defined in the chosen application program. Assuming the programmers who created the application have done their job well, what happens next is what the user wants: a new window pops up onscreen and offers useful word-processing features.
Does the user really have a copy of each application?
The description above is based on a traditional view of how computers run programs. It still applies in many present-day contexts, and it’s sufficient for our purposes in O1. However, developments in computing have affected how some programs are run.
Optional exercise: look up the following terms online: web application (web-sovellus), cloud computing (pilvilaskenta), Software as a Service.
Programming languages
The processor, which controls the computer’s behavior, does exactly what it’s instructed to do — nothing more, nothing less. It executes commands one by one, in order. Unlike the knowledgeable cook who reads a recipe, the processor understands nothing about the purpose of each command within the overall program. It doesn’t know how to interpret meanings from context, how to conjecture, or how to adjust to new situations. Ultimately, the computer is stupid. It is, however, fast and precise and has a reliable memory.
When you write a program, you need to describe, literally and in great detail, what you want the computer to do when the program is run. For that, you need instructions that are precise and unambiguous. Natural human language is imprecise and ambiguous, so it isn’t well suited to programming: consider expressions such as “add salt to taste” or “until it has a beautiful brown crust”.
To write a program, you use a programming language (ohjelmointikieli). Programming languages are formal and allow only specific, well-defined words and expressions. Any acceptable expression in a programming language has a precise meaning. If you know any chemistry, a useful point of comparison is molecular formulas, which are likewise governed by precise rules; those formulas are, however, rather simpler than most programming languages.
A huge number of programming languages have been developed over the past decades. Wikipedia, for instance, has a list thiis long, and even that is by no means comprehensive.
Some programming languages are better suited for some purposes, others for other purposes. Some are intended as general-purpose tools; others have a more specific raison d’etre. Some have been consigned to the trash heap of history; others march on from one decade to the next. New languages continue to be created, as do new versions of existing languages.

The names of some programming languages. We’ll be using one of them.

The Scala logo. In Italian, a staircase is called scala.
Scala, a programming language
In this course, we’ll use a modern and versatile programming language called Scala. As you work with Scala, you’ll learn general programming concepts that apply to many other languages. An experienced programmer can pick up new programming languages relatively quickly.
As a quick example of what the language looks like, here are three commands written in Scala. The theme for these commands is a simple (and imaginary) accounting application that keeps track of employment information.
val hiredPerson = Employee("Sophie Student", 1992, 3200.0)
hiredPerson.workingTime = 0.5
hiredPerson.raiseSalary(1.2)
At this point, you don’t have to know what this example code means precisely. But you can read a short commentary on it. Move the mouse cursor over the explanations in the green boxes. You’ll notice that the associated bits of the Scala example get highlighted. Try it! You can also click the explanations to “lock” a highlight.
The first line tells the computer to store information about a new employee in memory. An employee has a name, a year of birth, and a monthly salary.
The second line marks the person as a part-time employee: their working time is set to 0.5, 50 percent.
The third line records a 20-percent raise for the employee.
Programmers are free to name many of the elements in their programs. Some of the words in this example are specific to this program and were chosen by the programmer, using English as a basis. The programmer could just as well have used Finnish or Latin here — it wouldn’t change what the program does.
Some of the words belong to the Scala language itself and weren’t
chosen by the programmer. Scala’s vocabulary is based on English
words: val
is short for “value”.
You’ll keep learning more Scala throughout O1. Nevertheless, we won’t be covering all aspects of this rich language in one course. Scala is also used in several other courses at Aalto and in many contexts outside the academic world.
We use version 3 of the language. (More precisely, we use Scala 3’s subversion 3.7.) Scala 3 was released in 2021 and differs from the older Scala 2, so if you study from other websites or external sources, keep an eye on version numbers.
A program — is what exactly?
Right from the start, it’s good to know that the word “program” refers to two separate things:
the program text, known as the program code (ohjelmakoodi): a sequence of instructions for a computer to follow
a program run: the things that happen as a computer executes the instructions in the program code.
This is why you can say things like “My program has 15,000 lines of program code.” as well as “If you click that button, and my program will send the results to the printer.”
In other words, a program is, on the one hand, static (staattinen): a passive piece of writing about what a computer should do. On the other hand, a program is dynamic (dynaaminen): an active process that acts within a computer and may interact with its users. Many other programming concepts also have a similar static/dynamic duality, so we’ll be returning to this theme many times as we go.
Inside and Outside an Application Program

An end user and an app’s components.
Application programs have two main components:
A user interface or UI (käyttöliittymä), which is the part of the program that the user sees and interacts with. Many modern applications have a graphical user interface (GUI) that consists of windows, buttons, and similar components.
A model of the program’s domain: what the program is about. This is the program’s “guts”; it’s what defines the program’s internal logic. For instance, the domain model of a word-processing application defines how proofreading works and how documents are internally structured — into paragraphs, headings, and the like.
An application’s user will usually be familiar only with how to use the app. In contrast, the programmer must be able to describe both the user interface´and the program’s internals. Moreover, unlike the user, the programmer needs to manipulate both the program’s dynamic behavior and its static representation as program code.
In the remainder of this chapter, we’ll explore two existing application programs. We’ll look at them from the inside as well as the outside. As we do so, you’ll get to grab your programmer’s toolbox.
The Tools of Programming
Programmers routinely use tools — auxiliary programs created by other programmers — to help them create new programs. For instance:
Program code is written and saved using an editor program. (More about that shortly.)
A compiler (kääntäjä) is a program that automatically converts program code written by a human into a form that’s more readily executable by a computer. (More on that in Chapter 5.4.)
A debugger helps the programmer monitor a program’s behavior while the program is running. This is particularly useful for finding errors and when learning to program.
Version control (versionhallinta) makes it easier to develop complex software, especially in teams. (More on that in O1’s follow-up courses.)
Virtual machines are commonly used to assist in running programs. (More on that in Chapter 5.4.)
Integrated Development Environments (IDEs)
Compiler
Virtual Machine
Debugger
Version Control
Integrated or separated?
A programmer may use separate tools for different tasks, such as editing or debugging. Alternatively, they may use an integrated development environment (IDE). An IDE combines several tools for creating software and helps the programmer organize their work into modules, which is often convenient.
In O1, we recommend that you use an IDE. This ebook assumes that you use one particular IDE:
IntelliJ IDEA

The IntelliJ logo
O1’s official programming toolkit is an IDE called IntelliJ IDEA, or just IntelliJ or IJ for short.
Experienced programmers can do all sorts of things IntelliJ; taken as a whole, IntelliJ is pretty complex, as IDEs tend to be. However, we’ll be using a simpler subset of IntelliJ’s features that suits our purposes.
IntelliJ can be further extended with various plugins. We will use its Scala plugin and a custom plugin named A+ Courses, which makes it easier for you to access our programming assignments and submit them to A+ (among other conveniences).
We use Community Edition 2025.2 version of IntelliJ. The Community Edition and the plugins are free to install and use.
Local students at Aalto may use IntelliJ on Aalto IT’s Linux workstations, which have the right version of IntelliJ installed.
This isn’t the only way
Some students in O1 already know programming tools that they’d prefer to keep using. Even though we officially use IntelliJ, you’re free to use other tools instead. You're free to do so, but at your own risk — you'll need to rely on your own ability to work out any kinks that arise. O1’s staff is unlikely to be able to assist you with unofficial tools. Also, if you don’t use the A+ Courses plugin for IntelliJ, it will be less convenient to access and submit assignments.
IntelliJ at Aalto
The correct version of IntelliJ has been installed on Aalto IT’s Linux workstations. These workstations serve as O1’s official working environment.
Please note that Aalto’s Windows workstations generally do not have the necessary tools installed. (If you do wish to use IntelliJ on Aalto’s Windows computers, you can try the OOD environment that works in a web browser; see below.)
Installing IntelliJ on Your Own Computer
If you plan to use your own computer for programming, you’ll need to install IntelliJ and the plugins. We have a separate page that explains how to do that. To make sure you install the right versions, follow the instructions on that page.
You should read the rest of this ebook on a computer with IntelliJ installed.
If you’re using IntelliJ on your own computer and have already followed the installation instructions, you can skip the section immediately below and continue from Programs in This Ebook, further below.
An alternative: IntelliJ in your browser, no installation
Aalto is experimenting with a virtual environment called Open OnDemand (OOD), which you can access with your web browser and which comes with IntelliJ pre-installed. This lets you to use IntelliJ over the net instead of installing it on your own computer.
Our first experiences with the OOD environment suggest that IntelliJ runs surprisingly smoothly there, assuming you have a good internet connection. However, please note that OOD is still in a testing phase, and we cannot guarantee it works perfectly. If you use it, please do drop us some feedback about your experiences!
(Note: In some O1 assignments, especially in the first few weeks, we’ll use the computer to produce sounds. However, OOD does not support this, so you won’t hear anything. It’s nevertheless possible to complete those assignments in OOD, but it will be less fun.)
Here’s how you to use OOD:
Log in at https://ood.cs.aalto.fi/ with your Aalto account.
In the menu at the top, select Interactive Apps and then the server named IntelliJ IDEA (O1). There’s a session length setting that defaults to one hour, but feel free to change that.
Press Launch to set up a session. (This may take a while.)
When the session is ready, press Connect to the Container. IntelliJ should show up in a separate browser tab.
Launching IntelliJ for the First Time
When you launch IntelliJ for the first time, you’ll need to adjust a few settings. Here’s how.
Launch IntelliJ
On Aalto IT’s Linuxes, you’ll find IntelliJ in the menu as IntelliJ IDEA. (If not, launch IntelliJ by opening a Terminal window and entering idea at the prompt. Launching IntelliJ like this once should make IntelliJ appear in the menu in the future.)
In other environments, you can launch IntelliJ from the Start menu or by clicking
the executable file (named Idea
, idea64.exe
, or similar) within the installation folder.

On first launch, IntelliJ may ask you about sharing usage data and importing old settings. If so, pick Do not import settings and click OK.
IntelliJ welcomes you with view that looks like this:

The A+ Courses plugin
Install the A+ Courses plugin in IntelliJ as follows.
In IntelliJ’s welcome screen, select Plugins from the list on the left.
A list of available plugins appears. Type A+ Courses in the search field at the top, and the plugin of that name shows up in the list. Click Install.

IntelliJ notifies you about installing a third-party plugin. Click Accept.
Click Restart IDE to finish up the installation.
If that button fails to show up, close IntelliJ yourself and relaunch it.
When restarting, you may see a message about “indexing” not being finished. Don’t worry about it.
Setting up a course project
IntelliJ suggests that you create or select a project to store your work. Select New Project.
A New Project window pops up, with a list of project types on the left. Let’s set it up as an A+ Courses project. Pick that on the left, then choose O1 2025 from the list of available courses. Click Next.

Language selection and the JDK toolkit
You should now see a view where you can select the language you use in O1 and install a toolkit known as the JDK, which you’ll need for programming:
At the top, select a language to use in O1. If you do not know Finnish, pick English.
In the same view, you’ll see a drop-down menu labeled JDK. In that menu, is there an option with the version number 17?
If it happens that yes, there is, pick that option.
If not, do as illustrated in the two pictures below: Choose Download JDK in the drop-down menu. For Version, pick 17, and for Vendor pick Amazon Corretto (for example). You’re free to choose where to download the JDK; the default folder should do fine. Finally, click Select, and IntelliJ will fetch the toolkit.
Click Next to continue.


Choosing a project folder
At the final screen, under Project Name, enter a suitable name for your course project,
such as o1
or o1assignments
. Under Location, you can pick which
folder you’d like IntelliJ to store your files in; the suggested default is fine, unless
you want to change it. Finally, click Create.

Setting an A+ passcode
Before you can submit assignments to A+ from IntelliJ, you’ll need to give IntelliJ permission to act in your name in A+. You do that by giving IntelliJ a “passcode” (technically known as an API Access Token):
Open up your profile page in A+.
There’s a long string of characters under API Access Token. Copy the entire string to the clipboard. That’s your personal code, similar to a password. Do not share it with other people.
Now return to IntelliJ and do the following:
On the right-hand side, in the A+ Courses tab, you’ll see a field labeled A+ Token. Paste the token there.

Click Set.
You’ll see tabs appear next to the A+ Courses tab: Assignments, Modules, and News. You’ll be accessing them throughout the course.
Programs in This Ebook
This is going to happen frequently in O1: we take a more or less complete program and discuss it in the text, then have you extend or modify it in an assignment.
One reason we do this is to help you learn from examples. Another is that professional programmers often do something similar, too. Programmers often don’t start from scratch; instead, they modify an existing systems or use existing program code as part of a new program.
Here’s one:
The GoodStuff application
Let’s take a look at GoodStuff, an example program designed for the purposes of this course. GoodStuff is an “experience diary” application: it lets the user record their experiences and the ratings they’ve given to those experiences. For instance, an experience could be a stay at a hotel.
In its current form, GoodStuff is quite basic and lacking in many ways. It does contain the core of a better application, however, and most importantly, it’s well suited for introducing many programming concepts. We’ll be returning to GoodStuff repeatedly in the chapters to come.
We haven’t yet taught you enough about programming to understand the code that defines GoodStuff, but you can already explore the program. This will give you an overview of what an application looks like in IntelliJ and how you can manipulate it as a programmer. This is what we’ll do next in this chapter:
Fetch the GoodStuff application into IntelliJ.
Paint a broad-brush picture of the app’s main components.
Run the app in IntelliJ and see how it looks from the user’s perspective.
Take a peek at the program code and fix a tiny error in it.
A Program in IntelliJ

The A+ Courses button on the top right toggles whether O1’s lists of contents are visible or hidden. Try it.
In IntelliJ, a programming project consists of modules. Modules are IntelliJ’s way of bundling together related files and settings. Each of O1’s example programs and programming assignments comes within a module. Larger programs may consist of many modules.
Fetching an O1 module into IntelliJ
Notice the vertical A+ Courses button near IntelliJ’s top-right
corner. It brings up lists of O1’s program modules and assignments, as well as a tab
with course news. The same button hides the lists when you don’t want to look at them.

The Project button toggles whether the contents of your personal course project are visible or hidden. Try it.
Look at the Modules list and find the GoodStuff module there. (Note: make sure you’re looking at Modules, not Assignments.) Click the GoodStuff module, select Install, and IntelliJ downloads the module to your computer.
Downloading the GoodStuff module did not accomplish anything very obvious, but let’s take a closer look.
The Project tab in IntelliJ
On the other side of IntelliJ, near the top left-hand corner, is another important button
. It controls the Project tab, which lists the contents of your personal
course project: the programs that you’ll work on in O1. Make the Project tab visible
now. (We recommend that you keep it visible at most times.)

Two modules in IntelliJ’s Project tab.
Modules and packages
You should now see the GoodStuff module on the left-hand side of IntelliJ’s user interface, in the Project tab.

The GoodStuff application’s program code is divided in four files.
You’ll also see another module in your course project, O1Library. You'll need that one throughout the course. Many of our example programs, GoodStuff included, don’t work without the toolkit that comes in O1Library. Apart from that, you don’t have to pay it any mind now.
Browse the GoodStuff module’s files in the Project tab. Four files define the
GoodStuff app: CategoryDisplayWindow.scala
, GoodStuff.scala
, Category.scala
, and
Experience.scala
. (IntelliJ shows the names without the .scala
suffix.)
These files are divided into packages (pakkaus). You may think of packages as a Scala’s version of file folders. The main use for packages is to group related pieces of a program together, which is particularly helpful when the program is large. For instance, we can define one package for a program’s user interface and a separate package for its internal domain model.
The GoodStuff program has four parts. Of these, Experience
and Category
model the
program’s “guts”, namely the experiences that are recorded in the diary and the categories
that those experiences fall into. These parts are located directly in package o1.goodstuff
.
The other two parts implement the program’s user interface and are located in package
o1.goodstuff.gui
.
Together, those two packages define the GoodStuff app. A module may also contain other
files. For instance, GoodStuff and many other O1 modules have a doc
folder that contains
the module’s documentation. We’ll return to documentation later (in Chapter 3.2).
Let’s run it already, please
Every Scala application has a file that serves as the app’s launch file. In GoodStuff,
the launch file is GoodStuff
, located in the o1.goodstuff.gui
package. Find this file
in the Project tab and right-click it to bring up a menu. In the menu, select
Run 'GoodStuff'.
The app’s GUI will open in a separate window and looks like this:
This example application will show up multiple times in forthcoming chapters, so take a moment to get familiar with it, starting with what the app’s user sees. Spend a bit of time using GoodStuff: click Add new hotel and try entering some made-up data into the program. Notice the following:
This simple application supports only a single category of experiences: accommodation in hotels.
The application computes a value-for-money figure for each experience by dividing its rating by its price.
The user’s favorite experience grins at you. The experience with the highest rating is considered the favorite.
Finally, close the GoodStuff window. The program run ends.
A Peek at Program Code
Double-click the names of code files to load up the files’ contents in IntelliJ’s editor.
Try it!
Open one or more of GoodStuff’s code files by double-clicking
their names in the Project tab, under the o1.goodstuff
packag.
Marking comments in Scala
In the Scala language, text between the markers /*
and */
is a comment and has no
effect on program execution. You’ll find examples throughout the GoodStuff application.
An alternative is to use the double-slash //
, which marks the start of a comment that
runs until the end of the line. IntelliJ’s Scala editor, like many other program editors,
automatically highlight comments in color so that they stand out from the rest of the code.
In O1, you usually won’t be required to include comments in the programs that you write. It can be a good idea to write them nevertheless. In any case, you’ll be reading a lot of example code that contains comments.
Take a look around
Spend a few minutes browsing GoodStuff’s code. Even though most of it is likely to be incomprehensible — even the comments contain unfamiliar programming terms — you’ll get a sense of how a Scala program looks. Perhaps you’ll also find bits of code that make sense to you or whose meaning you can guess. But if nothing makes any sense yet, that’s totally fine, too.
In the next chapter, 1.3, we’ll start to get familiar with specific programming concepts, and the related Scala commands. Well do that gradually, little by little. Eventually, you’ll be able to understand GoodStuff’s code, and more complicated programs — and, of course, you’ll learn to write programs of your own.
Let’s Do Some Editing
Did you notice the typo in the title of the window that hosts the GoodStuff GUI? It says GodStuff!
It doesn’t take a master programmer to fix that. Let’s apply the fix and, while we’re at it, try submitting a program for automatic assessment.
The window title is defined as part of the GoodStuff GUI. If you want to locate the line of code yourself, go ahead, but it’s also fine to just see here for the answer:
Where is the title defined?
It’s on line 34 of CategoryDisplayWindow.scala
,
which is in the package o1.goodstuff.gui
.
Do the following:
Add the letter o where appropriate on that line.
See if it worked: relaunch the program (via the right-click menu on
GoodStuff
). The window title should be okay now.Are you working alone or with a partner? If the latter, make sure to form the pair using the menu here in A+.
You’re now all set to submit your solution:
Go back to the A+ Courses tab at IntelliJ’s right-hand edge and find the Assignments list.
In the list, locate the GoodStuff assignment under Week 1. Select it. Click the submit button
above the list. (Or double-click New submission; that works, too.)
A little dialog window pops up. Choose to submit alone or with a pair. You’ll also see that IntelliJ is about to submit
CategoryDisplayWindow.scala
for grading. Press OK.IntelliJ notifies you that the assigment has been submitted and that you’ll get the feedback later. After a short wait, another notification tells you that the feedback is available.
You can view the feedback by clicking the link in the notification, which opens the appropriate A+ page in the browser. A+ will have given you some automatic feedback and assignment points.
Saving and restoring files in IntelliJ
IntelliJ saves your files automatically as needed and keeps a history of changes. If you want to be extra-sure, you can press Ctrl+S (Cmd+S on a Mac) to save all unsaved changes across all files, but that is rarely necessary in practice.
If you ever need to restore an earlier version of a file (and Undo isn’t enough), you can right-click the file or folder and select Local History.
A+ presents the exercise submission form here.
Another Editing Task: The Game of Pong
Preparations
Explore another application: a version of the classic video game Pong. Find the program in the Pong module and try it out, just like you did with GoodStuff. Here are the steps:
In the A+ Courses tab, locate the Pong module in the Modules list. Double-click to install it in your O1 project.
Run the program: In the Project tab, find
PongApp.scala
in theo1.pong.gui
package. Right-click and select Run 'runPong'.Use W or S to move the left paddle and the arrow keys to move the right paddle.
Your assignment, part 1 of 2
In the package o1.pong
, there’s a file called package.scala
. Among other things,
this file defines some numerical values that shape how the game behaves. Open this
file in the editor.
Near the top, one of the lines defines something called BallRadius
. On that line,
replace the number 10 with 50.
Relaunch the game. You’ll see that something changed.
Your assignment, part 2 of 2
In the same package, there’s a file called Ball.scala
, which defines the rules
that the ball follows as it moves. One of the lines says this:
this.velocity = this.velocity.switchY
This command causes the ball to change direction as it bounces off the top or bottom.
Comment out this line. That is to say, write two slash characters (/
) at the beginning
of the line. This turns the line into a comment. That being so, the line is no longer an
executable part of the program.
Relaunch the game.
Does our game now have a bug, an error in how it behaves? Well, we did intend to make that change, so it’s not a bug, it’s a feature.
Submit your solution.
A+ presents the exercise submission form here.
Fooling around with Pong
If you want, you can experiment further. Here are some ideas:
What happens if you change
Size
andThickness
inpackage.scala
to have different numeric values?Can you find the part in
package.scala
that defines how fast each paddle moves?Can you find where the code defines the colors of the GUI? See if you can change the colors.
Looking at
PongApp.scala
, can you figure out how to change the keys that control the paddles?What if
PongApp.scala
saidpush(Right)
instead ofpush(Up)
?
Addendum
If you enjoyed messing about with Pong and seeing what happens, you might also enjoy the following quote. It makes an exciting point about programs’ static-and-dynamic duality:
One of the first items covered in an introductory physics course is the difference between potential and kinetic energy. You can think of potential energy as the energy stored in, say, a battery or a rock placed on top of a hill. Kinetic energy is energy that is in the process of being converted, as when the stored electricity in a battery drives a motor and when a rock rolls down a hill.
Similarly, when a human designs a program, there exists a potential computation that is unleashed when the program executes within a computer. Thus, one can think of the computation as being kinetic and in motion.
Moreover, just as a child with a firecracker can be surprised by the difference between potential and kinetic energy, so computer programmers are often surprised (even pleasantly) by the difference between potential and kinetic computation.
—Gary Flake (in his book The Computational Beauty of Nature)
Tip: Other Ways to Launch an App
As mentioned earlier, you can run an app via the right-click menu of its launch file
(such as GoodStuff
or PongApp
). Another way to do the same thing is to select that
file in the Project tab and press Ctrl+Shift+F10.
If you already have the start file open in the editor, you can alternatively press
the little icon in the left margin (on the line that starts with
object
).
During O1, you’ll be launching apps a lot. Do it whichever way you prefer.
The above methods require you to first select or open the launch file. Alternatively, you can press Shift+F10 to relaunch whichever app you most recently launched (without selecting it). This shortcut is often convenient.
You may also want to take a look at the little menu in IntelliJ’s top-right corner,
next to a button. It lets you pick from your most recently launched programs.
Programming as an Activity
To finish the chapter, let’s take a moment to reflect on what programming is like.
Programming as problem-solving
Typically, a programmer’s work begins with a problem or need that calls for a solution. Here are some examples of problems that can be tackled through computing.
One wishes to speak to people on the other side of the planet over the internet.
One needs a novel accounting application for a company.
One wants to know the best route for a car to reach its destination. Or for a spaceship.
One seeks a model that describes or predicts people’s behavior in a social network, the spread of diseases, climate change, or historical trends in how common different words are.
One wants to determine which additional products to recommend whenever customers make purchases in an online store.
One needs a tool that converts scientific measurement data into a format that is convenient for analysis.
One wishes to simulate the movement of subatomic particles in order to predict phenomena.
One wishes to simulate the movement of emotional avians as they accelerate through a gravitational field toward hoofed mammals.
And so on. And so on.
Interesting problems are constantly being invented, both by programmers themselves and by others. Even when a problem is familiar, we may still look for better solutions than what we already have.
Algorithms
Programmers often talk about algorithms (algoritmi). Roughly speaking, an algorithm is a step-by-step method for solving a problem.
Baking, too, involves algorithms, even if bakers don’t usually call them that. In our example, the master baker’s notion of how to make the cake is essentially an algorithm that she invented. The baker wrote the method down as a recipe. In much the same way, a programmer implements algorithms — solutions to problems — as program code.
Different parts of a problem may require different algorithms. For instance, a word processor will use one algorithm for proofreading and another for find-and-replace.
As a programmer, you will create some the algorithms you use for some subproblems. For other subproblems, you’ll apply algorithms that other people previously created. In any case, you’ll need to implement the algorithms and combine the implementations into a complete program.
A mini-assignment: algorithms and programs
What programming is like
We’ve established that programming is one form of problem-solving. A programmer must to determine what algorithm solves a problem and how to express that algorithm as a program for computers to run. There is practically never just a single correct solution, so programmers must compare alternatives and think about how to create a high-quality program. High quality might mean that the program is fast, user-friendly, secure, or easy to extend, for instance.
Programming calls for systematic thinking, creativity, and attention to detail. Many people consider programming to be fun aerobics for the brain. Nearly everyone agrees it’s a way to create useful tools and products.
Contrary to what some people think, creating programs often revolves around humans at least as much as it revolves around machines. For instance, ease of use and extensibility must be judged from a human point of view. And of course programs are created to meet human needs.
Programs come in many sizes, and so do teams that develop programs. Some programs are created by individuals, others by large international organizations. In day-to-day programming work, human communication often plays a large role.
Some people who program are full-time software developers that seek to produce high-quality software for commercial or other purposes. A still larger group consists of the varied professionals who use programming as a tool in their field: financial analysts, social scientists, researchers in medicine and genomics, physicists, graphic designers, linguists, climatologists, engineers, etc. Some harness programming as an instrument for art.
People with programming skills can build tools that make them more productive — whether they are working with spreadsheets, playing games, or solving everyday problem. Skill in programming helps us benefit from the enormous power of computing and to understand the computerized systems that surround us.
Can you think of a program that you wish existed? That you would like to create yourself? What kind of program would make the world a better place?
Summary of Key Points
As a computer executes a program, it follows a set of instructions written by a programmer. It follows them step by step, to the letter.
Programming is a creative activity aimed at solving problems that matter to people.
Programs are written in a programming language. In this course, we use a language called Scala.
We use an integrated development environment (IDE) named IntelliJ. An IDE brings together various tools that assist the programmer:
In IntelliJ, you can edit code and run programs to examine how your edits affect program behavior.
The parts of a Scala program can be organized into packages. A package may contain multiple files, each of which defines one or more program components.
In IntelliJ, programs can be grouped into modules. A module may contain multiple packages.
Many chapters in this ebook come with given programs that are more or less complete. They are provided to you as IntelliJ modules.
Program code isn’t for just computers. One indication of this is the use of comments that help human readers understand what the code does.
Links to the glossary: programming, program; application, user interface; domain, algorithm; dynamic, static; program code, programming language, Scala; comment; integrated development environment or IDE.
Feedback
Please note that this section must be completed individually. Even if you worked on this chapter with a pair, each of you should submit the form separately.
Credits
Thousands of students have given feedback and so contributed to this ebook’s design. Thank you!
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, Kai Bukharenko, Nikolas Drosdek, Kaisa Ek, Rasmus Fyhrqvist, Joonatan Honkamaa, Antti Immonen, Jaakko Kantojärvi, Onni Komulainen, Niklas Kröger, Kalle Laitinen, Teemu Lehtinen, Mikael Lenander, Ilona Ma, Jaakko Nakaza, Strasdosky Otewa, Kaappo Raivio, Timi Seppälä, Teemu Sirkiä, Onni Tammi, Joel Toppinen, 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, Juha Sorva, and Jaakko Nakaza. Several of its key components are built upon Aleksi’s SMCL library.
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 services; 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 for this page
Niklas Kröger contributed to the section on launching IntelliJ, and Ilona Ma to the section on the Open OnDemand environment.
Niklas Kröger contributed to the section on launching IntelliJ.
Comments
You’ll soon notice that the code doesn’t consist of just Scala commands. There’s also quite a bit of text in English, which IntelliJ colors in gray or green.
It’s common for program code to include such explanatory text, known as comments (kommentti). Comments help other programmers understand the purpose of the program’s components and how to use them. Even the programmer who originally wrote the program may benefit from comments when they return to work on code that isn’t fresh in memory.
Program code isn’t just for computers!
In comments, we’ve come across something general and important: even though programs are written for computers to execute, we also need to take human readers into consideration. When used sensibly, comments can be a cornerstone of good programming style.