You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: data/osa-3/1-virheiden-etsimisesta.md
+9-13Lines changed: 9 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
path: '/osa-3/1-virheiden-etsimisesta'
2
+
path: "/osa-3/1-virheiden-etsimisesta"
3
3
# title: 'Virheiden etsimisestä'
4
-
title: 'On searching errors'
4
+
title: "On searching errors"
5
5
hidden: false
6
6
---
7
7
@@ -12,12 +12,12 @@ hidden: false
12
12
13
13
</text-box>
14
14
15
-
16
15
<!-- Olemme tähän mennessä harjoitelleet ohjelmointikielen perusrakenteiden kuten muuttujien, ehtolauseiden, toistolauseiden ja metodien käyttöä. Tutustutaan seuraavaksi lyhyesti ohjelmien ymmärrettävyyteen vaikuttaviin tekijöihin sekä virheiden etsimiseen. -->
17
16
18
17
We've so far been practicing the fundamentals of the language, such as variables, conditionals, loops, and methods. Let's now move on to look at some of the factors affecting the understandability of programs, and how errors are found.
19
18
20
19
<!-- ## Ohjelmoija sokeutuu koodilleen -->
20
+
21
21
## A programmer becomes blind to their own code
22
22
23
23
<!-- Ohjelmoija sokeutuu omalle koodilleen. Tutustutaan tähän efektiin alla olevan lyhyen videon avulla. Laske alla olevalta videolta kuinka monta kertaa valkopaitaiset pelaajat syöttävät palloa toisilleen. Videossa on mukana englanninkieliset ohjeistukset. -->
@@ -36,13 +36,11 @@ Fortunately, however, applying oneself to a given task lessens the occurrence of
36
36
37
37
<!-- Ohjelmoinnin harjoittelun kannalta tahaton sokeus näkyy muunmuassa siinä, että tiettyyn ohjelman osaan keskittyminen vie huomiota muista osista, jotka saattavat mielessä tällöin näyttää oikeellisilta vaikka niissä olisi virhe. Esimerkiksi ohjelman tulostuksen oikeellisuutta tarkasteltaessa ohjelmoija saattaa keskittyä tulostuslauseisiin ja vahingossa jättää osan logiikasta huomioimatta. -->
38
38
39
-
40
39
One way in which perceptual blindness manifests itself in programming practice is when concentrating on a specific part of a program draws attention away from seemingly correct, yet erroneous parts. For instance, while inspecting the correctness of a program's output, a programmer may fixate on print statements, and mistakenly neglect aspects of the program's logic.
41
40
42
41
<!--
43
42
Vastaavasti toistolauseen sisältävässä ohjelmassa olevaa virhettä etsiessä ohjelmoija saattaa keskittyä monimutkaisimpaan asiaan ensin, vaikka virhe on täysin muualla. Esimerkkinä alla oleva käyttäjän syötteiden keskiarvon laskemiseen tarkoitettu ohjelma, jossa on virhe -- virheen etsinnässä tyypillisesti keskitytään ensin toistolauseeseen. -->
44
43
45
-
46
44
Likewise, a programmer may focus on the most complicated aspect of a program featuring a loop, although the error lies somewhere else completely. An example of this is the program below used to calculate the average of user-inputted values. It contains an error, and focus is typically first placed on the loop when searching for it.
<!-- Tahaton sokeus on asia, jota ei voi varsinaisesti kytkeä pois päältä. Ohjelmoija voi kuitenkin muutamien kikkojen avulla vähentää sen esiintymistä -- näistä ensimmäinen on taukojen pitäminen, joka luonnollisesti vaatii työn ajoissa aloittamisen. Lisäksi esimerkiksi koodin kommentointi, nimentä ja "debug"-tulosteet auttavat myös. -->
98
95
99
-
Perceptual blindness is something that cannot be switched off completely. However, there are ways by which a programmer can lessen its effect - the first one being taking breaks. This, of course, requires that work is begun early. Additionally, commenting code, the naming of things, and "debugging" prints are examples of things that help too.
100
-
96
+
Perceptual blindness is something that cannot be switched off completely. However, there are ways by which a programmer can lessen its effect - the first one being taking breaks. This, of course, requires that work is begun early. Additionally, commenting code, the naming of things, and "debugging" prints are examples of things that help too.
101
97
102
98
<!-- ## Lähdekoodin kommentointi -->
103
-
## Commenting the source code
104
99
100
+
## Commenting the source code
105
101
106
102
<!-- Kommenteilla on useita käyttötarkoituksia, joista yksi on ohjelman toiminnallisuuden itselleen selittämiseen esimerkiksi virhettä etsittäessä. Alla melko yksinkertaisen ohjelman suoritus on kuvattu auki kommentein. -->
107
103
@@ -131,7 +127,6 @@ while (luku > 0) {
131
127
}
132
128
``` -->
133
129
134
-
135
130
```java
136
131
137
132
/*
@@ -161,7 +156,6 @@ while (value > 0) {
161
156
162
157
Comments have no impact on the execution of the program, i.e., the program works in the same way with the comments as it does without them.
163
158
164
-
165
159
<!-- Edellä käytetty ohjelmoinnin opetteluun tarkoitettu kommentointityyli on toistaalta ohjelmistokehityksene kelpaamaton hyvin raskas. Ohjelmistoja rakennettaessa pyritään siihen, että **lähdekoodi kommentoi itse itsensä**. Tämä tarkoittaa sitä, että ohjelman toiminnallisuus tulee ilmi luokkien, metodien ja muuttujien nimistä. -->
166
160
167
161
The commenting style used above for learning programming is, however, quite burdensome in real development, where the goal instead is for the source code to be **self documenting**. This means that the functionality of the program should be evident from the way classes, methods, and variables are named.
@@ -189,6 +183,7 @@ public static void tulostaLuvutIsoimmastaPienimpaan(int mista, int mihin) {
189
183
}
190
184
}
191
185
``` -->
186
+
192
187
```java
193
188
publicstaticvoid printValuesFromTenToOne() {
194
189
int value =10;
@@ -209,9 +204,8 @@ public static void printValuesFromLargestToSmallest(int start, int end) {
<!-- Eräs ohjelmoinnissa tarvittava taito on testaus- ja debuggaustaito, jota käytetään virheiden etsimisessä. Yksinkertaisin tapa ohjelmissa olevien virheiden etsimiseen on ns. print-debuggaus, joka käytännössä tarkoittaa rivikohtaista viestien lisäämistä. Viestejä käytetään ohjelman suorituksen seuraamiseen, ja viestit voivat sisältää myös ohjelmassa olevien muuttujien arvot. -->
217
211
@@ -243,6 +237,7 @@ if (summa == 0) {
243
237
System.out.println("Lukujen keskiarvo: " + (1.0 * summa / lukuja));
244
238
}
245
239
``` -->
240
+
246
241
```java
247
242
Scanner scanner =newScanner(System.in);
248
243
int values =0;
@@ -333,4 +328,5 @@ if (sum == 0) {
333
328
<!-- Kun ohjelman suorittaa useampaan otteeseen sopivilla syötteillä, ohjelmasta löytynee siinä piilevä virhe. Sopivien syötteiden keksiminen on myös oma taitonsa -- tärkeää on pyrkiä tarkastelemaan ns. corner caseja, eli tilanteita, joissa ohjelman suoritus voisi olla poikkeava. Tällaisia tilanteita ovat esimerkiksi tilanne, missä käyttäjä ei syötä yhtään hyväksyttävää lukua, käyttäjä syöttää pelkkiä nollia, tai käyttäjä syöttää hyvin isoja lukuja. -->
334
329
335
330
When a program is executed multiple times with the appropriate inputs, the hidden error is most likely found. Coming up with suitable inputs is a skill in its own right. It's essential to test the so-called corner cases, i.e., circumstances where the program execution could be exceptional. An example scenario is one where the user only inputs unacceptable numbers, or zeros, or very large numbers.
0 commit comments