1 00:00:00,000 --> 00:00:18,090 *35C3 preroll music* 2 00:00:18,090 --> 00:00:20,899 Herald Angel: Do you remember some days ago, where you sit together with your 3 00:00:20,899 --> 00:00:26,680 loved ones and you had to fix their computers? And told them how things work – 4 00:00:26,680 --> 00:00:31,519 and why they are working the strange way they are working? Imagine you have to do 5 00:00:31,519 --> 00:00:35,970 this for teaching them how to program and give them the passion and the love that 6 00:00:35,970 --> 00:00:41,960 you have for programming! So please let's give Mike Sperber a great applause for his 7 00:00:41,960 --> 00:00:45,540 talk "How to Teach Programming to Our Loved Ones". 8 00:00:45,540 --> 00:00:52,205 *Applause* 9 00:00:52,205 --> 00:00:53,330 Mike Sperber: Thanks so much for that 10 00:00:53,330 --> 00:01:00,220 introduction. Let's switch slides back. Speaking of passion. So if you're teaching 11 00:01:00,220 --> 00:01:05,009 programming, that's a great ego booster, right? You know that. If your audience is 12 00:01:05,009 --> 00:01:09,890 large enough or if you've got super gifted children – like you probably all do – then 13 00:01:09,890 --> 00:01:13,270 you know, you could teach them just about anything and they will say, they will tell 14 00:01:13,270 --> 00:01:16,600 you and they will give you feedback telling you how wonderful that was. So for 15 00:01:16,600 --> 00:01:21,119 example I like functional programming, so that's a lambda which stands for 16 00:01:21,119 --> 00:01:25,579 functional programming. And you know whenever I teach that to a sufficiently 17 00:01:25,579 --> 00:01:31,020 large audience somebody typically looking like that would come up to me and tell me: 18 00:01:31,020 --> 00:01:34,929 "Oh this lambda stuff, this functional programming stuff that's the most 19 00:01:34,929 --> 00:01:41,689 wonderfullest thing I've ever heard. And you're a great teacher." And so in the 20 00:01:41,689 --> 00:01:45,109 introduction it said something about a couple of days. So I think I've been 21 00:01:45,109 --> 00:01:51,060 teaching for 30 years now; in various contexts: to high school students, to 22 00:01:51,060 --> 00:01:55,179 university students, to kids, to humanities majors, to computer science 23 00:01:55,179 --> 00:02:01,529 majors, to computer science minors, in professional training to co-workers. But 24 00:02:01,529 --> 00:02:06,029 if I take the totality of my teaching experience, most of that overall looking 25 00:02:06,029 --> 00:02:10,090 back was a failure. And I want to talk about those failures more about the 26 00:02:10,090 --> 00:02:15,990 successes that come from the passion. So if you look at initiatives that aim at 27 00:02:15,990 --> 00:02:20,510 fostering programming skills among children for example, they always talk 28 00:02:20,510 --> 00:02:26,310 about getting people excited and sort of exciting their passion for programming. 29 00:02:26,310 --> 00:02:29,590 And you hear politicians talk like that a lot, too. We need to get young people into 30 00:02:29,590 --> 00:02:34,250 technology because that is the future. I'm not sure about that personally, but it 31 00:02:34,250 --> 00:02:38,130 always seems to end up in classrooms that look like this: That typically have a 32 00:02:38,130 --> 00:02:44,060 bunch of robots in there, sold by some company. And that are supposed to, because 33 00:02:44,060 --> 00:02:48,380 robots are for some reason inherently interesting. They're supposed to get kids 34 00:02:48,380 --> 00:02:52,261 or whomever interested in programming, excited about programming. And that's all 35 00:02:52,261 --> 00:02:57,320 good and well. Also I think there's this underlying assumption that only if we 36 00:02:57,320 --> 00:03:01,880 would get people excited and interested in programming, they would sort of acquire 37 00:03:01,880 --> 00:03:06,850 the required skills by themselves and some process of trial and error or osmosis or 38 00:03:06,850 --> 00:03:10,930 something like that. And I think the most prominent project that propagated that 39 00:03:10,930 --> 00:03:14,960 notion – some of you may remember – was this One Laptop Per Child initiative a 40 00:03:14,960 --> 00:03:18,360 couple of years ago. And you don't … I haven't seen many of those at this 41 00:03:18,360 --> 00:03:24,120 conference. And the reason for that is that the educational concepts around One 42 00:03:24,120 --> 00:03:27,940 Laptop Per Child were based on this idea of – I think – what's called 43 00:03:27,940 --> 00:03:32,040 constructivism. This idea that only if you give children enough material and access 44 00:03:32,040 --> 00:03:36,470 to whatever the Internet and teaching materials, then they will all figure it 45 00:03:36,470 --> 00:03:40,350 all out themselves and they will figure out how to build programs by themselves. 46 00:03:40,350 --> 00:03:44,240 And I think one of the underlying problems – I mean there were many problems with 47 00:03:44,240 --> 00:03:48,430 OLPC. But one of the problems was certainly that just this approach to 48 00:03:48,430 --> 00:03:53,530 didactics and pedagogy doesn't work particularly well. And you find variations 49 00:03:53,530 --> 00:03:57,540 of that pretty much every year. There's an educational initiative built on this 50 00:03:57,540 --> 00:04:02,319 notion of inspiring – you know – passion for programming. You know, last year you 51 00:04:02,319 --> 00:04:08,530 would hear about a project called Bob which essentially is about programming a 52 00:04:08,530 --> 00:04:11,670 little robot-like device, that has blinking lights and things like that. And 53 00:04:11,670 --> 00:04:16,709 it's certainly very interesting and you program it by – I think you can see that 54 00:04:16,709 --> 00:04:22,510 here – you program it by essentially downloading already … someone already 55 00:04:22,510 --> 00:04:26,320 programmed some C++ code for you, and you take some line in the middle and change it 56 00:04:26,320 --> 00:04:30,100 to change the blinking through frequency or something like that. And again all that 57 00:04:30,100 --> 00:04:33,720 is good and well; and I don't want to denigrate that, but it's all good and well 58 00:04:33,720 --> 00:04:39,150 for inspiring passion. But all of these projects have in common is that they are 59 00:04:39,150 --> 00:04:44,090 not really about teaching the methodology of programming. And so this is, you know, 60 00:04:44,090 --> 00:04:46,680 this is what this talk is about and it's probably going to be the most boring talk 61 00:04:46,680 --> 00:04:54,320 you've ever heard. If you want to inspire passion for programming and for computers, 62 00:04:54,320 --> 00:04:57,420 there's lots of projects right outside this door – specifically today on the 63 00:04:57,420 --> 00:05:01,620 Junghackertag – that will tell you how to do that. The problem is that if you want 64 00:05:01,620 --> 00:05:05,580 to transition from these projects to actually serious substantial programming 65 00:05:05,580 --> 00:05:10,430 projects that your learners want to undertake by themselves … and if you look 66 00:05:10,430 --> 00:05:15,020 closely enough, you will find that a lot of people get frustrated by that 67 00:05:15,020 --> 00:05:19,430 experience of writing more complex programs. And even if they do not get 68 00:05:19,430 --> 00:05:24,900 frustrated, their code often ends up looking like that on the right hand side. 69 00:05:24,900 --> 00:05:30,160 And so of course this entire conference is in the spirit of tinkering and building 70 00:05:30,160 --> 00:05:34,370 things by trial and error; and you see a lot of things that look like this. But, 71 00:05:34,370 --> 00:05:38,900 you know, in the upcoming IOT apocalypse maybe we want to have a little bit 72 00:05:38,900 --> 00:05:44,169 slightly more methodical approach. So the problem is really that most didactic 73 00:05:44,169 --> 00:05:48,820 approaches to programming do not work very well. For the longest time I really didn't 74 00:05:48,820 --> 00:05:52,760 have a good explanation as to why that was and why maybe the stuff that I was doing 75 00:05:52,760 --> 00:05:57,260 or that I learned how to do over the years worked better. And so finally I found a 76 00:05:57,260 --> 00:06:02,880 great book that confirms some of my biases, that I read just the day before 77 00:06:02,880 --> 00:06:08,220 yesterday – as I was preparing this talk. And it has a couple of … It's written by a 78 00:06:08,220 --> 00:06:14,740 cognitive scientist – Daniel Willingham – and he lists a couple of principles that 79 00:06:14,740 --> 00:06:19,260 are active when students learn, right? And I think one of the things that's really 80 00:06:19,260 --> 00:06:24,490 important is that we all have this idealistic notion that everybody loves to 81 00:06:24,490 --> 00:06:28,570 learn, right? But in fact learning is quite a difficult activity and it's quite 82 00:06:28,570 --> 00:06:33,780 straining. And – so even though people are curious about things and they love to look 83 00:06:33,780 --> 00:06:37,350 at things and they like to have successful learning experiences – if that learning 84 00:06:37,350 --> 00:06:42,650 experience means they have to think hard, then at least some people shun those same 85 00:06:42,650 --> 00:06:48,801 experiences. Another problem is … so and that's of course a problem when you 86 00:06:48,801 --> 00:06:52,690 transition from a primitive programming environment, like Scratch or Bob or 87 00:06:52,690 --> 00:06:57,050 something, to more complicated things that you can easily get frustrated, and then 88 00:06:57,050 --> 00:07:02,600 shun away from the learning experiences that are required to take the next step. 89 00:07:02,600 --> 00:07:05,270 Another one that I found interesting is – so these are just all the cognitive 90 00:07:05,270 --> 00:07:09,940 principles in that book – so it's kind of very textual and boring, but I liked it so 91 00:07:09,940 --> 00:07:14,530 much. So it says: "Factual knowledge precedes skill." But if you think, so what 92 00:07:14,530 --> 00:07:19,560 it means is really that you need to have … that if you want to learn a particular 93 00:07:19,560 --> 00:07:23,140 skill, you need to associate that with factual knowledge. But if you think about 94 00:07:23,140 --> 00:07:27,120 the factual knowledge that is associated with programming, then a lot of the 95 00:07:27,120 --> 00:07:31,229 principles underlying our everyday programming skills are usually unnamed. 96 00:07:31,229 --> 00:07:35,090 And they're not really put in specific words, and so they're not in the form of 97 00:07:35,090 --> 00:07:38,750 factual knowledge. And which is why a lot of people have trouble with the skill 98 00:07:38,750 --> 00:07:44,510 part. I love this bit which says: "Memory is the residue of thought." Which is that 99 00:07:44,510 --> 00:07:47,381 we don't always remember the things that we should be remembering, but that we 100 00:07:47,381 --> 00:07:51,240 remember things that we spend a lot of thought on. And that means in particular 101 00:07:51,240 --> 00:07:54,470 for educational initiatives that are centered around robots – or something 102 00:07:54,470 --> 00:07:58,810 that's really … that is supposed to take over the passion part of programming but 103 00:07:58,810 --> 00:08:02,610 not really central to the activity of programming – people tend to think about 104 00:08:02,610 --> 00:08:06,330 the robots: They tend to think about the motors and actuators and things like that; 105 00:08:06,330 --> 00:08:10,060 and those are worthy skills in and of themselves, but they don't contribute much 106 00:08:10,060 --> 00:08:14,580 to the actual skill of programming. I remember asking a proponent of such an 107 00:08:14,580 --> 00:08:18,750 educational initiative a number of years back, you know what is it? What is the 108 00:08:18,750 --> 00:08:23,030 skill that students take away from your robot class? And he said "well, after that 109 00:08:23,030 --> 00:08:26,440 class where they spend all their free time for a semester or a year, they really know 110 00:08:26,440 --> 00:08:34,820 what pi is. And I don't know for me that is not enough. So another thing is that … 111 00:08:34,820 --> 00:08:39,080 maybe that doesn't go so much towards computer science or programming experience 112 00:08:39,080 --> 00:08:44,320 but also to the way that we do math education: Is we understand new things in 113 00:08:44,320 --> 00:08:48,820 the context of things we already know. In particular we find it easier to understand 114 00:08:48,820 --> 00:08:56,190 concrete things. And I think both in math and computer science a lot of explanations 115 00:08:56,190 --> 00:09:00,240 are in the form of explaining some abstract thing rather than showing how to 116 00:09:00,240 --> 00:09:04,440 do a concrete thing. And so we'll get back. So this is going to be a major point 117 00:09:04,440 --> 00:09:09,960 later on. Something that didn't really need saying in that book: "Proficiency 118 00:09:09,960 --> 00:09:12,880 requires practice." If you want to get better at programming, you'll need to 119 00:09:12,880 --> 00:09:17,010 practice it with the goal of getting better at it. So in the classroom or in a 120 00:09:17,010 --> 00:09:22,260 teaching environment you really need to create situations that foster successful 121 00:09:22,260 --> 00:09:27,180 practice, the successful solution of problems. So that, you know, this natural 122 00:09:27,180 --> 00:09:32,130 curious part in the beginning. So student, so people generally derive a dopamine rush 123 00:09:32,130 --> 00:09:37,450 from successfully solving problems. So we really need to put … we really need to put 124 00:09:37,450 --> 00:09:41,740 our students in a situation where they can successfully solve problems – that are not 125 00:09:41,740 --> 00:09:45,210 too hard and also not too easy, because if they're too easy, the dopamine rush will 126 00:09:45,210 --> 00:09:51,550 not be big enough. Here's a trap I think that most people who teach programming 127 00:09:51,550 --> 00:09:54,430 know about is that "cognition is fundamentally different early and late in 128 00:09:54,430 --> 00:09:57,950 training". And if you're here, most people in this room are late in training. So 129 00:09:57,950 --> 00:10:02,220 we've been in touch with computers for a long time, so our cognitive processes when 130 00:10:02,220 --> 00:10:05,550 we think about programming are different than the cognitive processes of beginning 131 00:10:05,550 --> 00:10:10,070 students. Sometimes that's also called the curse of knowledge. So just because we 132 00:10:10,070 --> 00:10:14,350 find some piece of material inspiring or interesting – or some technique of 133 00:10:14,350 --> 00:10:18,410 explaining something very persuasive – that does not mean that our students find 134 00:10:18,410 --> 00:10:23,070 it similarly persuasive and find it similarly easy to follow along our 135 00:10:23,070 --> 00:10:28,020 teaching. If you're teaching big classrooms I think there's being have been 136 00:10:28,020 --> 00:10:33,620 a big push towards individualistic learning. And of course that's wonderful. 137 00:10:33,620 --> 00:10:38,120 On the other hand our children tend to be quite alike in their style of learning. 138 00:10:38,120 --> 00:10:42,209 And so I'm not going be talking about that much that very much today but there's 139 00:10:42,209 --> 00:10:46,500 still great value in having a classroom with several students that are all being 140 00:10:46,500 --> 00:10:53,960 taught the same thing. Not a subject today but I could also … that that also has been 141 00:10:53,960 --> 00:10:58,860 confirmed by my experience. Generally, some people think that you know some 142 00:10:58,860 --> 00:11:01,760 people are good at math and some people are bad at math. You know girls are always 143 00:11:01,760 --> 00:11:05,959 bad at math for some reason and it turns out that this is … Well first of all it's 144 00:11:05,959 --> 00:11:10,580 not true. And even if you feel you're bad at something then usually what we call 145 00:11:10,580 --> 00:11:15,440 intelligence can be changed through sustained hard work. I think you know 10 146 00:11:15,440 --> 00:11:20,030 or 20 years ago a lot of people believed in IQ that an innate ability to learn 147 00:11:20,030 --> 00:11:24,880 things. But it turns out that that most of the effects of IQ on your ability do 148 00:11:24,880 --> 00:11:28,740 things well are quite indirect and through the environment rather than through some 149 00:11:28,740 --> 00:11:34,740 structure in your brain that you were born with. And so that's something that you 150 00:11:34,740 --> 00:11:39,510 really learn when you do 30 years of teaching is really that your teaching can 151 00:11:39,510 --> 00:11:43,779 improve over time. But in order to improve you really must get feedback and you must 152 00:11:43,779 --> 00:11:48,890 practice it and get feedback the same way that the skill itself must be practiced. 153 00:11:48,890 --> 00:11:53,710 And that sometimes gets you feedback that is surprising sometimes and also it's 154 00:11:53,710 --> 00:11:58,649 often quite quite painful because sometimes you get the feedback that you're 155 00:11:58,649 --> 00:12:04,339 teaching just did not work. So really, I want to aim a programming education at a 156 00:12:04,339 --> 00:12:08,850 diverse audience and not just I mean if you look at the Robot class if you're 157 00:12:08,850 --> 00:12:12,560 student population that ends up being in that robot class is really as diverse as 158 00:12:12,560 --> 00:12:16,670 you like it as you'd like it to be. I think often that is not the case. So the 159 00:12:16,670 --> 00:12:19,709 stuff that I'm going to talk about and then I'm going to talk about has been 160 00:12:19,709 --> 00:12:23,600 applied not always by me but to children, to high school students, to university 161 00:12:23,600 --> 00:12:28,410 students, professional developers and works quite well. And what it is based on 162 00:12:28,410 --> 00:12:33,660 is a set of systematic methods and I'll try to show you in great and painstaking 163 00:12:33,660 --> 00:12:40,200 detail what that means. And so here are some references that you can look at. In 164 00:12:40,200 --> 00:12:44,350 particular we built on the work of the PLT group in the U .S. led by Matthias 165 00:12:44,350 --> 00:12:47,610 Felleisen, who have a great book out now. I'll give you a reference to that later. 166 00:12:47,610 --> 00:12:53,410 There is a there's a significant project for teaching high school students in the 167 00:12:53,410 --> 00:12:56,140 U.S. and there's also a project that I'm involved with what's called which is 168 00:12:56,140 --> 00:13:00,660 called "Dein Programm", which tries to be sort of the little German sister of that 169 00:13:00,660 --> 00:13:08,730 stuff. So one aspect that's important to this method of teaching is that all the 170 00:13:08,730 --> 00:13:13,670 tools that we use are geared towards learners in particular that means that 171 00:13:13,670 --> 00:13:17,180 there is a specific programming environment that was made specifically for 172 00:13:17,180 --> 00:13:23,100 learners rather than your Emacs or VI or whatever your favorite thing is that you 173 00:13:23,100 --> 00:13:27,430 want to, that you want to inflict on your learners. I don't think you should. I'm an 174 00:13:27,430 --> 00:13:33,980 Emacs person myself. So also what it means is that we have … that we use specific 175 00:13:33,980 --> 00:13:38,080 programming languages that are derived from real programming languages but that 176 00:13:38,080 --> 00:13:44,251 have been modified to be especially suitable for learners. And also then we 177 00:13:44,251 --> 00:13:50,160 have something called the design recipes which are a set of methods for systematic 178 00:13:50,160 --> 00:13:55,230 program construction that try to provide this factual basis for the methodology of 179 00:13:55,230 --> 00:13:58,860 programming. And so there's programming environment … All of this stuff by the way 180 00:13:58,860 --> 00:14:04,899 can be downloaded for free. And so there's a great system called racket developed by 181 00:14:04,899 --> 00:14:08,920 the PLT group but there's a tiny corner in there that I'm going to refer to today 182 00:14:08,920 --> 00:14:12,960 which is great for many things but it was originally designed and still is great for 183 00:14:12,960 --> 00:14:22,740 teaching so. So let me try to switch to that. I hope that works out. This moment 184 00:14:22,740 --> 00:14:30,830 always scares me. So here is the system called Doctor racket and you can see it 185 00:14:30,830 --> 00:14:35,399 has not very many buttons it does not look like Eclipse or Visual Studio or something 186 00:14:35,399 --> 00:14:38,660 like that does not look like a professional programming environment. And 187 00:14:38,660 --> 00:14:43,740 the way this works is I'm going to try to show you how it works is in the upper part 188 00:14:43,740 --> 00:14:47,360 of that window there's just the program that's a text editor with a couple of 189 00:14:47,360 --> 00:14:51,800 special features - not very many. And down here is the REPL, which you can use to 190 00:14:51,800 --> 00:14:55,930 interact with the program that you've written. I'm not gonna use that very much. 191 00:14:55,930 --> 00:15:00,600 But what you can do in the REPL - in the beginning at least - is you can just type 192 00:15:00,600 --> 00:15:04,910 something and it will give you … it will then immediately tell you the result of 193 00:15:04,910 --> 00:15:10,560 the evaluation of what you typed in. And now you have to remember … This is gonna 194 00:15:10,560 --> 00:15:15,650 be alien and strange to you. But the way this works is these languages are based on 195 00:15:15,650 --> 00:15:20,440 Lisp. So they use round parentheses a lot and specifically when … always when you 196 00:15:20,440 --> 00:15:23,209 want to put something together they have around parentheses and they have the 197 00:15:23,209 --> 00:15:26,760 operator in front and - especially if you've been programming for a long time - 198 00:15:26,760 --> 00:15:30,300 you think "Oh no, this is … Never gonna get used to that!" but I can promise you, 199 00:15:30,300 --> 00:15:35,930 your children will have a very easy time dealing with this. So you could go and say 200 00:15:35,930 --> 00:15:39,889 you know you could just type a number and it will give you the result. You would 201 00:15:39,889 --> 00:15:48,200 type a string, you know, "Mike". It will give you the result. It … you could go and 202 00:15:48,200 --> 00:15:52,930 you could you know, you could combine numbers, right, by adding them together. 203 00:15:52,930 --> 00:15:57,480 You could let's do away with that. Looks like this. So that's what it what it looks 204 00:15:57,480 --> 00:16:00,970 like a compound expression has always parens around it and the operator in 205 00:16:00,970 --> 00:16:04,960 front. So you don't really say you know this number plus that number you say the 206 00:16:04,960 --> 00:16:11,550 sum of those two numbers. OK. And so gives me the result of that. What's kind of fun 207 00:16:11,550 --> 00:16:15,980 if you're a C programmer or Java programmer this is kind of fun, but 208 00:16:15,980 --> 00:16:23,899 children love this for some reason I know. So what you can also do is the same way 209 00:16:23,899 --> 00:16:28,279 that you're used to having numbers and strings and whatever and booleans be 210 00:16:28,279 --> 00:16:33,329 values. Pictures are also values so that sometimes helps when you're trying to drum 211 00:16:33,329 --> 00:16:37,250 up that little piece of motivation that you need. So you could do like a rectangle 212 00:16:37,250 --> 00:16:44,829 that is solid blue and that's a value. And whatever whenever there is a value you can 213 00:16:44,829 --> 00:16:51,270 write a program that binds that value to a name by writing "define". So you could do 214 00:16:51,270 --> 00:16:57,980 something really exciting like this. You would define "pi" for something. We could 215 00:16:57,980 --> 00:17:03,940 run that program and then we could put top pi here but we could also do you know "r" 216 00:17:03,940 --> 00:17:13,740 that rectangle and whatever 50 solid red and we can run that program. And here's 217 00:17:13,740 --> 00:17:20,060 that rectangle. What's maybe more interesting is that we can maybe do 218 00:17:20,060 --> 00:17:25,599 another rectangle that's solid blue and you can also see here's the same principle 219 00:17:25,599 --> 00:17:29,880 at work right. Parentheses around the define so "define" says it's a definition 220 00:17:29,880 --> 00:17:33,980 and the rectangle is just a call to a function that comes with Dr. Racket and 221 00:17:33,980 --> 00:17:40,320 it's also in front. And so I could do that. Now I have "r" I have "f2" and I 222 00:17:40,320 --> 00:17:43,990 could also do things, things like you know there's for example a function that takes 223 00:17:43,990 --> 00:17:49,830 two pictures and puts them beside each other so there's a little jumping ahead a 224 00:17:49,830 --> 00:17:52,750 little bit there's a little algebra of pictures in here that you can use to 225 00:17:52,750 --> 00:17:56,180 program video games for example later in the class if that's something that you 226 00:17:56,180 --> 00:18:03,799 want to do. So this is not entirely without motivational examples. So there's 227 00:18:03,799 --> 00:18:14,059 that. Yeah. Let's see how far we can go from there. OK. So but getting away from 228 00:18:14,059 --> 00:18:21,200 those motivational examples. In German we are very big on traffic rules. Right. 229 00:18:21,200 --> 00:18:24,530 Straßenverkehrsordnung. So there are many rules, right, and we'll try to model that. 230 00:18:24,530 --> 00:18:28,580 This is going to make this the most boring talk you've ever heard. So we're gonna 231 00:18:28,580 --> 00:18:34,480 categorise German traffic violations. So in particular there's two kinds of traffic 232 00:18:34,480 --> 00:18:38,660 violations. There's red light violations where it's important where they happen and 233 00:18:38,660 --> 00:18:43,110 it's also important what the duration is. How long after the light has turned red 234 00:18:43,110 --> 00:18:48,370 passes before you actually cross the intersection or the red light. And then 235 00:18:48,370 --> 00:18:52,140 there's a speeding violation where you also have a place and you just have how 236 00:18:52,140 --> 00:18:56,150 many kilometres per hour did you go over the limit. And we want to write functions 237 00:18:56,150 --> 00:19:00,850 and I'll tell you how to do that for yielding the place of a violation and 238 00:19:00,850 --> 00:19:07,250 classifying a violation as serious or not. And for that purpose we're going to do … 239 00:19:07,250 --> 00:19:12,580 use something called the design recipe or rather as there's we're going to use 240 00:19:12,580 --> 00:19:15,919 several design design recipes and first of all there's an overall design recipes, 241 00:19:15,919 --> 00:19:20,540 which says how you write a function. And please don't fall asleep. There's one, 242 00:19:20,540 --> 00:19:24,760 two, three, four, five, six, eight, eight steps to this. And we always ask our 243 00:19:24,760 --> 00:19:30,010 students to always go through those eight steps and you think: this is off. I mean I 244 00:19:30,010 --> 00:19:33,940 hope you do right. You feel this is this already looks like the most boringest, you 245 00:19:33,940 --> 00:19:37,910 know, exposition to programming ever. This is like the German bureaucracy approach to 246 00:19:37,910 --> 00:19:45,799 teaching how to program. On the other hand, so, but, you know, it works. That is 247 00:19:45,799 --> 00:19:50,919 the point. Specifically each of those steps is something that is small enough so 248 00:19:50,919 --> 00:19:54,230 that students can usually successfully do it. And if you can reward it with credit 249 00:19:54,230 --> 00:19:58,840 or candy or whatever then you know students will be motivated to get to the 250 00:19:58,840 --> 00:20:03,910 next step. You know if you've ever taught unsuccessfully and probably most of you 251 00:20:03,910 --> 00:20:08,169 have always taught successfully but what always happened to me is then when my 252 00:20:08,169 --> 00:20:14,049 teaching would be unsuccessful my students would be staring at a blank screen. Right. 253 00:20:14,049 --> 00:20:17,320 And that would give them this problem and I felt this problem was really solvable 254 00:20:17,320 --> 00:20:22,539 and they would give up before typing the first key. Right. They wouldn't know where 255 00:20:22,539 --> 00:20:26,510 to begin because there's usually most approaches to teaching how to program are 256 00:20:26,510 --> 00:20:31,120 example based. They give you some example. You know, here's that program solves that 257 00:20:31,120 --> 00:20:34,240 problem. How here's a different problem, now solve that. And you already saw how 258 00:20:34,240 --> 00:20:39,669 that's done. And that process usually or often does not work. And so this fixed 259 00:20:39,669 --> 00:20:44,020 sequence of steps gets students over that hump and I'm gonna try to explain that 260 00:20:44,020 --> 00:20:47,320 really in painstaking detail because the books don't really do justice to a how 261 00:20:47,320 --> 00:20:52,570 bureaucratic and painstaking it is. So you all have the benefit of that. So there's 262 00:20:52,570 --> 00:20:55,990 always these eight steps and then there's more instructions that come with each of 263 00:20:55,990 --> 00:21:01,600 those steps. Right. But these instructions are eminently learnable and that's the 264 00:21:01,600 --> 00:21:07,890 important aspect here. So in particular. So I'm gonna, sort of, jump in right 265 00:21:07,890 --> 00:21:20,120 ahead. Oops, oops. Ah. You see something that I don't see. There we go. So if you 266 00:21:20,120 --> 00:21:26,890 look at this problem statement. So let me go back one more. So it says the first 267 00:21:26,890 --> 00:21:30,000 thing that you do is well you draw a short description of a function we already have 268 00:21:30,000 --> 00:21:33,850 two short descriptions of the functions you know find the place of a traffic 269 00:21:33,850 --> 00:21:37,120 violation and find out if it's serious or not. And then it says please conduct a 270 00:21:37,120 --> 00:21:43,390 data analysis and data analysis means that you look at the entities in your problem 271 00:21:43,390 --> 00:21:48,350 and and analyze them. And here it says while this is all about traffic 272 00:21:48,350 --> 00:21:52,720 violations. And it says something of the sort. That there's for example a red light 273 00:21:52,720 --> 00:21:57,180 violation. And it says that red light violation has place and duration and that 274 00:21:57,180 --> 00:22:01,730 duration is in seconds. So one thing that you can do is you can look at the wording 275 00:22:01,730 --> 00:22:05,929 of how that data is described and if you discover wording that says you know this 276 00:22:05,929 --> 00:22:11,520 thing consists of these pieces. Right. Or this thing has several different 277 00:22:11,520 --> 00:22:18,419 properties. This is a phenomenon that we call compound data and that has a special 278 00:22:18,419 --> 00:22:27,690 design recipe that PowerPoint somehow threw away. See OK it comes up again. So 279 00:22:27,690 --> 00:22:32,340 it says well you recognize compound data by a description of your data that uses 280 00:22:32,340 --> 00:22:36,880 words like "consists of" or "has". And then you write a data definition of that 281 00:22:36,880 --> 00:22:41,510 form and I will show you how that works. Then, something really trivial comes you 282 00:22:41,510 --> 00:22:44,480 count the ingredients and you write a what's called a record definition that's 283 00:22:44,480 --> 00:22:49,620 actual code and then you ensure that the counts match and these are instructions in 284 00:22:49,620 --> 00:22:57,059 the textbook. Right. And students learn to memorize those instructions and you all 285 00:22:57,059 --> 00:23:04,020 going asleep. You know you're all falling asleep. Sorry about that. So let's see 286 00:23:04,020 --> 00:23:09,620 where is the right window. Here's the right window. So that's what we were 287 00:23:09,620 --> 00:23:16,380 doing. Right. I'm going to leave that here for your entertainment. It says well a red 288 00:23:16,380 --> 00:23:22,810 light violation… So excited, I need to talk. And we said it has this formulation 289 00:23:22,810 --> 00:23:26,789 that says "has". We're just going to write it down in a slightly more systematic way. 290 00:23:26,789 --> 00:23:34,169 So, it has a place and it has a duration in seconds. Right. And that's just a piece 291 00:23:34,169 --> 00:23:39,730 of natural language and those semicolons, they make this a comment. OK. So we didn't 292 00:23:39,730 --> 00:23:44,250 do much except writing each component of our compound data in a separate line. And 293 00:23:44,250 --> 00:23:47,090 then it said - I can't really display it at the same time - then it said, write a 294 00:23:47,090 --> 00:23:52,750 record definition and a record definition has this form. It is, it really it looks a 295 00:23:52,750 --> 00:24:01,230 little tedious. But it's actually quite valuable. So it says we're talking about 296 00:24:01,230 --> 00:24:06,270 red light violations so we give our thing a name. So that's called "red-light- 297 00:24:06,270 --> 00:24:12,770 violation" then we will need to create "red-light-violation" objects. So we will 298 00:24:12,770 --> 00:24:15,679 need a constructor so I'm going to write down the name of that constructor. 299 00:24:15,679 --> 00:24:19,820 Eventually we will need to distinguish red light violations from other things. So I'm 300 00:24:19,820 --> 00:24:24,231 going to write something it's a predicate that we'll use a little later and then we 301 00:24:24,231 --> 00:24:28,770 have two parts. And I can't emphasize enough how important it is that you sort 302 00:24:28,770 --> 00:24:31,961 of remember: two. Right? It has two parts, because it says that there's a place and a 303 00:24:31,961 --> 00:24:37,820 duration in seconds and we write the names of things that will extract those pieces. 304 00:24:37,820 --> 00:24:42,980 So we go here it says "red-light- violation-place" and "red-light-violation- 305 00:24:42,980 --> 00:24:50,419 duration". Or we could, let's call it seconds, so we always know what that is. 306 00:24:50,419 --> 00:24:59,120 And now what that does is when I run it is well it doesn't do anything. But what we 307 00:24:59,120 --> 00:25:05,570 can do is. We can now create objects that represent red light violations. And so 308 00:25:05,570 --> 00:25:10,530 what we could do is… Well let me first show you how it's done. We do "make-red- 309 00:25:10,530 --> 00:25:16,130 light-violation". You know there's one in Borg. Somebody who, you know, had a red 310 00:25:16,130 --> 00:25:20,190 light violation for four seconds in Borg. Right. And then it will display a record 311 00:25:20,190 --> 00:25:28,590 value that shows what the parts are that we had. And so I can copy this up here and 312 00:25:28,590 --> 00:25:37,190 call it and make an example out of that. And so like this. So now we have "rv1" 313 00:25:37,190 --> 00:25:43,770 here. So this is what's called a constructor and this constructor when we 314 00:25:43,770 --> 00:25:48,500 call it creates this object and this object really creates data that is 315 00:25:48,500 --> 00:25:52,620 associated with information. So that's an important aspect to explain. And so 316 00:25:52,620 --> 00:25:58,440 usually we ask students and I can't I'm not writing this down to explain it to you 317 00:25:58,440 --> 00:26:04,110 I'm writing it down to show to you what to expect from students. And so you go "Oh", 318 00:26:04,110 --> 00:26:21,030 make them do it. So this is a red light violation in Borg, 4 seconds. So it seems 319 00:26:21,030 --> 00:26:28,659 really trivial to you but it's important to really … to link the program to the 320 00:26:28,659 --> 00:26:36,459 problem domain that we're in, right. So we have a minor red light violation here. 321 00:26:42,259 --> 00:26:50,820 Am I spelling this right? Anyway, so here we go. And one way to talk about this new 322 00:26:50,820 --> 00:26:54,299 function that we created "make-red-light- violation" is writing down something that 323 00:26:54,299 --> 00:27:00,350 we call a signature. It looks like, sort of like a type signature but isn't quite. 324 00:27:00,350 --> 00:27:04,020 That's something that we did specifically for teaching. So you do "make-red-light- 325 00:27:04,020 --> 00:27:12,340 violation" and remember in math you would sometimes write f Doppelpunkt, f colon to 326 00:27:12,340 --> 00:27:16,020 denote a type. And here we just put the colon in front. So it says "make-red- 327 00:27:16,020 --> 00:27:20,530 light-violation". Well it takes a string, that says what the places is, it takes 328 00:27:20,530 --> 00:27:25,450 some rational number, that says how long it went, how long the red light violation 329 00:27:25,450 --> 00:27:36,039 was over the limit, and it creates a red light violation object. So that's not 330 00:27:36,039 --> 00:27:43,000 gonna do much, unless, well let me let me show you something. If I wrote something 331 00:27:43,000 --> 00:27:58,790 else here I wrote a number here. Something… Where'd it go? So it's, so it 332 00:27:58,790 --> 00:28:02,429 says it gives an error message here. And it's I think it's due to this full screen 333 00:28:02,429 --> 00:28:18,090 mode for some reason. Let me see if we can do this again. No, not quite. OK, now we 334 00:28:18,090 --> 00:28:23,150 know what it is so. So. Yeah it was. So, when you. Unfortunately it is in German so 335 00:28:23,150 --> 00:28:26,080 I hope some of you read German I'll try to translate it says well this program still 336 00:28:26,080 --> 00:28:30,570 has to be tested but it says there was a… It says here "Signaturverletzung", which 337 00:28:30,570 --> 00:28:38,039 means signature violation. And it says I got five in this line here. And really, so 338 00:28:38,039 --> 00:28:44,010 this is the five. Oops, right here in this line. And it violated the signature here. 339 00:28:44,010 --> 00:28:47,279 So it gives you… So the system. That's one aspect of what makes the system 340 00:28:47,279 --> 00:28:52,771 specifically designed for learners is that it gives you very specific feedback as you 341 00:28:52,771 --> 00:29:02,909 run the program. OK. So let's do away with this. Let's get this down here. So now one 342 00:29:02,909 --> 00:29:06,370 of the challenges or one of the problems in the problem statement was to write a 343 00:29:06,370 --> 00:29:11,779 function that determines whether a red light violation is serious or not. And so 344 00:29:11,779 --> 00:29:15,830 when we do that, it said, well, you put a short description in front. And so here's 345 00:29:15,830 --> 00:29:19,929 a short description. And there's lots of religious wars about how many comments you 346 00:29:19,929 --> 00:29:24,409 should put in a program but to our learners we say put one line not more not 347 00:29:24,409 --> 00:29:29,760 less in front of every function. And that's usually about the right level. So 348 00:29:29,760 --> 00:29:37,500 is a red light violation serious? So the next thing is. Well if you remember that 349 00:29:37,500 --> 00:29:41,270 slide it says, well, if you're writing a function, if you're implementing a piece 350 00:29:41,270 --> 00:29:43,429 of functionality, that always ends up being a function in functional 351 00:29:43,429 --> 00:29:47,270 programming, you write a signature for that function that talks about what goes 352 00:29:47,270 --> 00:29:53,070 in and out of that function. So in this case. Well we have to make up a name for 353 00:29:53,070 --> 00:30:02,460 that. So it practically writes itself here and so we just put so in this language you 354 00:30:02,460 --> 00:30:05,360 can put a question mark in the middle of a name and you can also put hyphens in the 355 00:30:05,360 --> 00:30:10,950 middle of a name. And what we want is we want a red light violation to go in and we 356 00:30:10,950 --> 00:30:16,390 want a boolean to come out that says whether that violation was serious or not. 357 00:30:16,390 --> 00:30:20,340 So those are already steps in that design recipe that you saw. And so if you're in a 358 00:30:20,340 --> 00:30:23,710 classroom situation or whatever you can give credit for each immediate step and 359 00:30:23,710 --> 00:30:29,029 you should, because those are already those are all small successes in your 360 00:30:29,029 --> 00:30:33,390 programming endeavor. So the next thing that you should do is, you should write 361 00:30:33,390 --> 00:30:39,140 examples or tests. Those are almost the same thing here. And so, fortunately we 362 00:30:39,140 --> 00:30:43,080 already have examples of red light violations. So we just have to write down 363 00:30:43,080 --> 00:30:49,370 how we expect our function to behave with respect to those examples. So there's 364 00:30:49,370 --> 00:30:53,970 something called "check-expect" and I hope you recognize that principle that we're, 365 00:30:53,970 --> 00:30:59,610 that things are always named in the front. So we could say "red-light-violation- 366 00:30:59,610 --> 00:31:03,960 serious?". With children you might want to pick shorter names if they can't type that 367 00:31:03,960 --> 00:31:12,090 fast yet, but with grown ups this works. So the first one is four seconds over, so 368 00:31:12,090 --> 00:31:17,750 that's pretty serious. So we expect that to be true and that "#t" means true. And 369 00:31:17,750 --> 00:31:29,900 so. And you. And the other one is half a second over and that's not so serious 370 00:31:29,900 --> 00:31:35,289 under German law. That's fine. OK. So the next step. So now we've written. So let me 371 00:31:35,289 --> 00:31:40,320 let me label those things right. This is the short description. This is the 372 00:31:40,320 --> 00:31:47,390 signature. These are the tests. And now you write something called the skeleton 373 00:31:47,390 --> 00:31:50,900 and the skeleton is just you start writing the function but you already have some 374 00:31:50,900 --> 00:31:53,720 information about that function you know the name of that function and you know how 375 00:31:53,720 --> 00:32:08,150 many things come in and out. So you write - oops typo here - so and, well, this is a 376 00:32:08,150 --> 00:32:11,640 functional language so somebody always has to write lambda somewhere. So when we make 377 00:32:11,640 --> 00:32:15,010 a function in these languages we always write lambda. So we want to make a 378 00:32:15,010 --> 00:32:19,370 function that accepts one thing and that is a red light violation a red light and 379 00:32:19,370 --> 00:32:27,520 we'll just call it "rlv" and we'll just put three dots here. So the three dots I 380 00:32:27,520 --> 00:32:31,179 don't mean to say we're gonna fill in the rest later. It means in class when I do 381 00:32:31,179 --> 00:32:35,850 this I actually type three dots and in class especially at the beginning we 382 00:32:35,850 --> 00:32:39,960 actually ask our students to type the three dots because this is the skeleton. 383 00:32:39,960 --> 00:32:47,120 This already gives you credit and it's, you know since this is so easy to do, it 384 00:32:47,120 --> 00:32:52,480 really means that there's, you're not staring at a white piece of paper and 385 00:32:52,480 --> 00:32:57,289 maybe you feel encouraged to do that next step. Now the next step says you have to 386 00:32:57,289 --> 00:33:01,320 fill in what's called a template. And those are elements of the function that 387 00:33:01,320 --> 00:33:07,270 you're writing that derive from the data that goes in and sometimes from the data 388 00:33:07,270 --> 00:33:11,420 that goes out. In this case the data that goes in is one of those red light 389 00:33:11,420 --> 00:33:15,341 violation objects and that red light violation object if you may remember is a 390 00:33:15,341 --> 00:33:19,159 compound object it has two pieces. And whenever you write a function that accepts 391 00:33:19,159 --> 00:33:23,570 compound data with two pieces you probably need to look at those pieces. So, what you 392 00:33:23,570 --> 00:33:31,179 do is, you write you have to write something that will tell you what those 393 00:33:31,179 --> 00:33:38,350 pieces are and remember. So I haven't actually told you how that works. But 394 00:33:38,350 --> 00:33:42,600 remember here was the record definition, up here, and it told us and we have a 395 00:33:42,600 --> 00:33:46,559 signature there that tells us how to construct a red light violation object. 396 00:33:46,559 --> 00:33:50,710 And so what we also need is we need a way to get the components out of a red light 397 00:33:50,710 --> 00:33:54,420 violation object. So we need what's called selectors or assessors. And those are the 398 00:33:54,420 --> 00:33:58,850 things in parentheses here and here and you can also describe them with 399 00:33:58,850 --> 00:34:06,690 signatures. And strangely enough so and here a red light violation thing goes in 400 00:34:06,690 --> 00:34:20,889 and a string comes out. And in this case, a red light violation goes in and a - what 401 00:34:20,889 --> 00:34:24,498 do we say - a rational comes out. So those are of course… Those signature 402 00:34:24,498 --> 00:34:27,119 declarations are redundant. You don't have to put them in there. Redundant with a 403 00:34:27,119 --> 00:34:29,840 constructor declaration and you're going asleep, you're going asleep 404 00:34:29,840 --> 00:34:30,900 anymore... Even 405 00:34:30,900 --> 00:34:35,109 more probably than you were. But I had an epiphany in class where I would only write 406 00:34:35,109 --> 00:34:39,800 the constructor signature and the students would ask me to also write the excessive 407 00:34:39,800 --> 00:34:46,018 signatures. And so they made me even more bureaucratic than I was already by then I 408 00:34:46,018 --> 00:34:50,690 already was by nature. So now here what we do is we want to get access to the 409 00:34:50,690 --> 00:34:58,650 different parts. So we write "red-light- violation-place" of "rlv". So that's one 410 00:34:58,650 --> 00:35:05,609 piece. "-violation-seconds" of "rlv". That's the second part. And those are 411 00:35:05,609 --> 00:35:08,579 building blocks. So really if you're really strict about it you might have 412 00:35:08,579 --> 00:35:16,829 people type three dots in here also. So these just say, these are building blocks 413 00:35:16,829 --> 00:35:20,559 for your function. And so you think about how those parts contribute to the answer 414 00:35:20,559 --> 00:35:25,270 to your questions. The question was is the red light cycle violation serious or not. 415 00:35:25,270 --> 00:35:29,119 Then you can think about. Well is the place relevant whether it was serious or 416 00:35:29,119 --> 00:35:33,119 not. And in Germany I think it's not. But it is relevant how many seconds you went 417 00:35:33,119 --> 00:35:39,349 over. So, you then have– then you go through this conscious act of: you've 418 00:35:39,349 --> 00:35:43,670 written it down but now you delete it again because you've done a little bit of 419 00:35:43,670 --> 00:35:51,279 thinking. And you go and, well, then you look up– I look this up on the Internet. 420 00:35:51,279 --> 00:35:56,039 If it's over one second then – or if it's one second or over – then it's serious, 421 00:35:56,039 --> 00:36:03,359 and then you delete all the ellipses and make sure all the parentheses close and 422 00:36:03,359 --> 00:36:10,209 then you run the program. And here's still the signature violation that we need to 423 00:36:10,209 --> 00:36:21,099 fix. So it says here again there's a little German sentence because these 424 00:36:21,099 --> 00:36:24,869 languages were designed for Germans and it says: both tests were successful, because 425 00:36:24,869 --> 00:36:31,030 we wrote two test cases here. OK. So this bureaucratic approach just goes on and on. 426 00:36:31,030 --> 00:36:38,430 So I'm just going to go through the second iteration more quickly. So it said you 427 00:36:38,430 --> 00:36:45,099 know what did it say. It said, it said this. We also have a speeding violation. 428 00:36:45,099 --> 00:36:50,710 So let's go through the motions of that: a speeding violation has– again, it also has 429 00:36:50,710 --> 00:36:59,099 a place and it has, you know, how many kilometers per hour over. And we write a 430 00:36:59,099 --> 00:37:01,429 record definition 431 00:37:22,299 --> 00:37:25,869 something like this, and we could do, you know, two speeding 432 00:37:25,869 --> 00:37:31,509 vio- so now we have a data definition that says: oh we've got two components, we've 433 00:37:31,509 --> 00:37:36,640 got a record definition that needs to match that. You all think this is trivial 434 00:37:36,640 --> 00:37:40,719 but with compound data our students often have trouble. So it serves you well to 435 00:37:40,719 --> 00:37:45,069 remind them that there's two pieces, and those two pieces need to be selectors in 436 00:37:45,069 --> 00:37:52,269 the record definition. So we have speeding violation one, speeding violation on Main 437 00:37:52,269 --> 00:37:59,890 Street. You know what, 20 kilometers over, and we have another one, you know low 438 00:37:59,890 --> 00:38:13,469 street or whatever, that is 25 kilometers over. So that is two examples right. And 439 00:38:13,469 --> 00:38:23,769 we have one on low street, 25 kilometers per hour over limit. So once again the 440 00:38:23,769 --> 00:38:30,999 speeding violation constructor has a little signature that says well a natural 441 00:38:30,999 --> 00:38:39,619 number goes in, speeding violation object comes out. And so we go through those same 442 00:38:39,619 --> 00:38:43,460 notions. I need two things in order to demonstrate one more thing. So then again 443 00:38:43,460 --> 00:38:59,480 the question was: When is a speeding violation serious? And of course a 444 00:38:59,480 --> 00:39:08,089 speeding violation goes in and a boolean comes out. And so we will write two tests. 445 00:39:08,089 --> 00:39:11,829 So speeding violation in Germany is serious when it's 21 kilometres an hour 446 00:39:11,829 --> 00:39:15,309 over the limit, or over that. Right. And it gets progressively more serious after 447 00:39:15,309 --> 00:39:22,269 that. So. So the first one is not too serious. We'll not get you any points in 448 00:39:22,269 --> 00:39:38,210 Flensburg. But the second one is. And once again we go right, speeding violation 449 00:39:38,210 --> 00:39:50,100 serious, we write the skeleton. So then we write the skeleton, then we fill in the 450 00:39:50,100 --> 00:39:57,029 gaps and says we really should be writing calls to the accessors. So we have the 451 00:39:57,029 --> 00:40:03,739 place of the speeding violation and we have the kilometers over of the speeding 452 00:40:03,739 --> 00:40:10,299 violations. And then we think a little bit and then we realize: oh the place does not 453 00:40:10,299 --> 00:40:14,589 matter. So I'm skipping. Of course this all goes on usually over a longer period 454 00:40:14,589 --> 00:40:19,949 of time that you're teaching. I'm going I'm going pretty fast here. So we do away 455 00:40:19,949 --> 00:40:28,300 with that and we go well this really if this is over 21 then that's bad. Okay. So 456 00:40:28,300 --> 00:40:38,150 let's see if that works. It says km per hour over– So then it says all four tests 457 00:40:38,150 --> 00:40:43,579 are passed. So that's good. So you know there is primitive data, there's compound 458 00:40:43,579 --> 00:40:48,459 data. You may have noticed that on the slide it said: a traffic violation is 459 00:40:48,459 --> 00:40:53,089 either a red light violation or a speeding violation. So that's not compound data. 460 00:40:53,089 --> 00:40:58,779 When you see this formulation in your language that says: it's this or that or 461 00:40:58,779 --> 00:41:02,369 that or that, or maybe it is one of the following. Then you're not looking at 462 00:41:02,369 --> 00:41:08,420 compound data, you're looking at a phenomenon called "mixed data". So you've 463 00:41:08,420 --> 00:41:14,539 seen this, you've seen this, you've seen this mixed data. So you recognize it by 464 00:41:14,539 --> 00:41:18,759 either the words "or" or "one of" and you write a data definition that really has 465 00:41:18,759 --> 00:41:22,820 that form, you count the alternatives just like you do with compound data. You write 466 00:41:22,820 --> 00:41:26,289 a signature definition. I'll show you how to do that. And you ensure that the counts 467 00:41:26,289 --> 00:41:33,369 match. And so the way that you do that is this. We said data definition, so we said: 468 00:41:33,369 --> 00:41:43,160 a traffic violation is one of the following. It's either a red light 469 00:41:43,160 --> 00:41:55,079 violation or it is a speeding violation. And just as with the compound data this 470 00:41:55,079 --> 00:41:58,180 little data definition has some code that goes with it. So we'll just call this 471 00:41:58,180 --> 00:42:04,119 thing a traffic violation and we just use define to say what that is and define 472 00:42:04,119 --> 00:42:11,269 traffic violation, is it just a signature that says it's mixed, it's mixed data from 473 00:42:11,269 --> 00:42:19,839 red light violation and speeding violation. So here you go. So now we can 474 00:42:19,839 --> 00:42:23,690 use that in signatures. You remember the problem statement didn't say: find out 475 00:42:23,690 --> 00:42:28,300 whether a red light violation was serious or a speeding violation was serious, it 476 00:42:28,300 --> 00:42:34,619 said: find out whether a traffic violation is serious. So you know it is a traffic 477 00:42:34,619 --> 00:42:40,549 violation, but so far we only have functions, one works on red light 478 00:42:40,549 --> 00:42:43,729 violations, the other one works on speeding violations, but they don't work 479 00:42:43,729 --> 00:42:53,720 on that mixed. So we'll try to do that now and instead of writing red light violation 480 00:42:53,720 --> 00:43:01,119 we'll just write traffic violation to boolean. So we could now write tests that 481 00:43:01,119 --> 00:43:05,199 match those that are there but I'll spare you that. But in class we absolutely would 482 00:43:05,199 --> 00:43:15,560 need to do that. And now what we do is, when we have a traffic violation– Remember 483 00:43:15,560 --> 00:43:20,849 how I said if you have compound data, you put calls to the accessors in the body, 484 00:43:20,849 --> 00:43:25,420 and then you go on from there. But now we're looking at mixed data in the input. 485 00:43:25,420 --> 00:43:29,549 So mixed data has a different template and that template says: well if you're looking 486 00:43:29,549 --> 00:43:32,709 at mixed data, maybe this or that or that, you should probably find out what that is 487 00:43:32,709 --> 00:43:40,479 before you do anything else. And for doing that we use a conditional we use something 488 00:43:40,479 --> 00:43:45,430 like this– So what we need to do is we need to distinguish red light violations 489 00:43:45,430 --> 00:43:48,460 from speeding violations, so we need some function that will tell us which one it 490 00:43:48,460 --> 00:43:54,609 is. And this is the last bit up here in the record definition. You remember that 491 00:43:54,609 --> 00:43:58,309 we said red violation here, red light violation here. This is the name of the 492 00:43:58,309 --> 00:44:04,289 constructor, so it is the constructor. These are the accessors. And this is 493 00:44:04,289 --> 00:44:08,230 what's called the predicate, and the predicate tells us whether a thing is a 494 00:44:08,230 --> 00:44:14,089 red light violation or not. So in this case the predicate says: red light 495 00:44:14,089 --> 00:44:20,489 violation question mark, or "p" is what the programmers in these languages say. 496 00:44:20,489 --> 00:44:26,190 And it takes anything and it tells us whether it is a red light violation object 497 00:44:26,190 --> 00:44:33,640 or not. I'm just gonna copy that down so that we remember. We're almost done. So of 498 00:44:33,640 --> 00:44:37,119 course the same thing goes for speeding violation. So we need a conditional that 499 00:44:37,119 --> 00:44:41,451 has as many branches as we have alternatives in the data definition. And 500 00:44:41,451 --> 00:44:45,420 again you think this is super trivial and childish, but it works very well for 501 00:44:45,420 --> 00:44:50,980 making successful programmers. So we need two branches, and the way that works is 502 00:44:50,980 --> 00:44:59,119 this. So you write this out with ellipses, and then you need to come up with tests 503 00:44:59,119 --> 00:45:03,079 for the two branches in this case the tests are: is something a red light 504 00:45:03,079 --> 00:45:11,380 violation or is it a speeding violation. So we have this, question mark tv, and we 505 00:45:11,380 --> 00:45:18,819 have this which says, speeding violation tv. And now here we just need to put in 506 00:45:18,819 --> 00:45:21,799 the answers, and the great thing is we already have the answers we already have 507 00:45:21,799 --> 00:45:33,301 two functions that tell us whether a red light violation is serious and so we can 508 00:45:33,301 --> 00:45:42,259 just call that here and we can do this here so and then we're done. So I think 509 00:45:42,259 --> 00:45:47,039 that's all we can do in this hour that we have today. So I hope you see two things. 510 00:45:47,039 --> 00:45:56,709 First of all this is super boring and super bureaucratic. But maybe you can see 511 00:45:56,709 --> 00:46:02,559 that every single step that we have here has is a principle that has a specific 512 00:46:02,559 --> 00:46:06,250 name and that you can explain in very specific concrete terms that are not 513 00:46:06,250 --> 00:46:10,329 abstract. And that means it can really explain every step that's needed to solve 514 00:46:10,329 --> 00:46:16,410 this problem. And I can't tell you what a game changer to that is for teaching. If 515 00:46:16,410 --> 00:46:20,199 you really ask yourself if, you know, when you when you present an example to your 516 00:46:20,199 --> 00:46:24,069 students whether you can really explain every single step and explain to the 517 00:46:24,069 --> 00:46:27,199 students here's what you should have thought, you know, here's how you should 518 00:46:27,199 --> 00:46:33,339 have picked what to do next. That usually ends up badly. So so one of the principles 519 00:46:33,339 --> 00:46:38,890 behind this style of teaching is really to be absolutely sure every single step that 520 00:46:38,890 --> 00:46:42,680 you expect your students to make when they solve a problem has a name and has been 521 00:46:42,680 --> 00:46:46,650 explicitly taught in your class. So every technique has a name. You noticed me 522 00:46:46,650 --> 00:46:52,219 saying compound data and mixed data and design recipe and template and skeleton. 523 00:46:52,219 --> 00:46:57,099 And so this is the factual knowledge that we use that precedes the skill that we 524 00:46:57,099 --> 00:47:03,940 want to then induce. If you're teaching a class that has rewards you reward every 525 00:47:03,940 --> 00:47:10,019 single step. You really insist on form. I also can't stress this enough so on our 526 00:47:10,019 --> 00:47:14,430 home page you find a paper that says form over function. We don't accept any program 527 00:47:14,430 --> 00:47:19,010 that is correct. We just accept the ones that match the form that you've seen. We 528 00:47:19,010 --> 00:47:22,809 also measure success. You know you really need to look at how well your teaching 529 00:47:22,809 --> 00:47:26,019 style is doing and you improve it continuously. So those are the important 530 00:47:26,019 --> 00:47:31,650 principles. You might think that this stifles creativity. And I really don't 531 00:47:31,650 --> 00:47:35,269 think that's true. And I think that is based on a misguided notion of creativity. 532 00:47:35,269 --> 00:47:39,869 So if you talk it successfully creative artists they really also rely on a set of 533 00:47:39,869 --> 00:47:44,799 named techniques that they use to tackle a creative problem. And so somebody always 534 00:47:44,799 --> 00:47:49,230 says Mozart you know Mozart never had to learn or practice before he got to be a 535 00:47:49,230 --> 00:47:54,019 great composer but Mozart started it so early in childhood that he had his 10000 536 00:47:54,019 --> 00:48:00,670 hours of practice in there to be before most people even start. So this works for. 537 00:48:00,670 --> 00:48:03,499 So this has been proven to work this approach for children. I think I would 538 00:48:03,499 --> 00:48:07,839 start about 11 years, beginning programmers. It's worked for programmers 539 00:48:07,839 --> 00:48:11,839 that had learned some other via some other approach you know bad habits and 540 00:48:11,839 --> 00:48:16,059 professional developers. There's two websites that you can go on to get more 541 00:48:16,059 --> 00:48:20,699 information. One is our American sister project called programmed by design that 542 00:48:20,699 --> 00:48:24,829 has lots of material, links and publications. The DrRacket software that I 543 00:48:24,829 --> 00:48:28,939 showed you. And there's also a book in English how to design programs. And it 544 00:48:28,939 --> 00:48:32,559 doesn't say that here but that book is available for free online but there's also 545 00:48:32,559 --> 00:48:36,989 a print version. And similarly if you're looking for German language material 546 00:48:36,989 --> 00:48:41,119 there's "dein programm DOT de" which also has links and publication, links to the 547 00:48:41,119 --> 00:48:45,709 same software. And the draft version of that book is there too. And hopefully 548 00:48:45,709 --> 00:48:50,269 we'll have a print version of that also next year. And that's all I have for you 549 00:48:50,269 --> 00:48:52,409 today. Thank you very much. 550 00:48:52,409 --> 00:49:03,349 *Applause* 551 00:49:03,349 --> 00:49:06,309 Herald angel: Thank you Mike for that talk. If you have any questions, we do 552 00:49:06,309 --> 00:49:11,219 have the microphones lined up here in this row and in that row and does the signal, 553 00:49:11,219 --> 00:49:17,479 yes the signal Angel has a question. Signal Angel: Yes, so one IRC user asks 554 00:49:17,479 --> 00:49:23,390 what are the benefits of using this DrRacket tool instead of for example 555 00:49:23,390 --> 00:49:26,449 Python which was also developed for teaching? 556 00:49:26,449 --> 00:49:30,760 Mike: So Python is definitely not developed for teaching, not in any 557 00:49:30,760 --> 00:49:36,109 meaningful way. So in practice, in practice I think the fundamental diff-, so 558 00:49:36,109 --> 00:49:40,489 but there's a lot of educational initiatives around Python. The thing is 559 00:49:40,489 --> 00:49:47,029 really that if you try to name and really formalize the techniques the systematic 560 00:49:47,029 --> 00:49:50,999 techniques that I showed you and apply that to Python programming you will find 561 00:49:50,999 --> 00:49:55,079 that very hard. I personally found it impossible. Most Python programs out there 562 00:49:55,079 --> 00:49:58,140 in practice are just not developed systematically and I don't know how to do 563 00:49:58,140 --> 00:50:02,200 that. And so that is where that is much better. This corresponds to these 564 00:50:02,200 --> 00:50:08,009 programming languages were designed in lockstep with the didactic principles that 565 00:50:08,009 --> 00:50:12,099 underlie them and as far as I can tell, I'm sorry about that, Python was not 566 00:50:12,099 --> 00:50:16,300 developed with any didactic principles in mind whatsoever. Sorry. 567 00:50:16,300 --> 00:50:21,630 Herald Angel: OK then. Microphone 2 please go now. 568 00:50:21,630 --> 00:50:29,309 Questioner: I teach roughly 14 years olds in the middle school and also programming 569 00:50:29,309 --> 00:50:34,999 and I use the App Inventor right now. The App Inventor, MIT Media Lab App Inventor, 570 00:50:34,999 --> 00:50:43,690 I […] with scratch and I'm not sure you, you said okay you need to buy Lego 571 00:50:43,690 --> 00:50:49,979 Mindstorms robots and stuff like that or scratch or MIT App Inventor. That's not 572 00:50:49,979 --> 00:50:51,249 the case. Mike: No. Yeah. 573 00:50:51,249 --> 00:50:58,799 Questioner: And what I find difficult for the students I have there they are not the 574 00:50:58,799 --> 00:51:04,299 best from the best parents, then they would like to show something in the end. 575 00:51:04,299 --> 00:51:08,619 And it's your program looks a lot like Mike: Superball! 576 00:51:08,619 --> 00:51:14,750 Questioner: it is really very boring and *laughter* how do you bring it over that 577 00:51:14,750 --> 00:51:19,449 point? I find it so valuable that in the end they can show it on their smartphone. 578 00:51:19,449 --> 00:51:22,539 Mike: Yeah, depending on your target audience of course you choose different 579 00:51:22,539 --> 00:51:27,249 examples and this example just had a lot of things. You might have seen me show the 580 00:51:27,249 --> 00:51:30,420 pictures, show the picture algebra at the beginning. So that's something that tends 581 00:51:30,420 --> 00:51:34,949 to work great for children and older children alike and that scales all the way 582 00:51:34,949 --> 00:51:39,519 to writing video games and there's an entire book that shows children or young 583 00:51:39,519 --> 00:51:43,710 people on how to do that. So that's one of the great aspects of this. I think that's 584 00:51:43,710 --> 00:51:46,190 a fundamental difference to things like scratch and so on this approach to 585 00:51:46,190 --> 00:51:49,979 programming scales all the way to programm-, to professional programming and 586 00:51:49,979 --> 00:51:54,859 it scales to substantial video games. So the students that we so we always used to 587 00:51:54,859 --> 00:51:58,609 do that the halfway point in the first semester at the university and they were 588 00:51:58,609 --> 00:52:02,319 able to write a complete like 80s style you know frogger or snakes or something 589 00:52:02,319 --> 00:52:05,559 like that that looked pretty fancy. And that's something I think that your 590 00:52:05,559 --> 00:52:09,900 children could take home. Herald Angel: OK. Then microphone 1. 591 00:52:09,900 --> 00:52:16,730 Questioner: Hi, thanks for your talk. I'd like to know so your approach adds a lot 592 00:52:16,730 --> 00:52:22,890 of let's say overhead that is also necessary to be taught. How do you go 593 00:52:22,890 --> 00:52:29,459 about the methodology in the actual classroom though. Yeah. Do you al-, do you 594 00:52:29,459 --> 00:52:38,089 also have some recommendations on how to tackle the actual design of the of the 595 00:52:38,089 --> 00:52:42,079 class, what methods do you use, do you use a flipped classroom or what do you do? 596 00:52:42,079 --> 00:52:46,589 Mike: A good point. So so mostly the classes that I have taught they are taught 597 00:52:46,589 --> 00:52:50,400 just like what I did just now. So I try to demonstrate that to really make that clear 598 00:52:50,400 --> 00:52:55,509 because it hasn't really been documented. I could refer you to friends of mine who 599 00:52:55,509 --> 00:53:00,130 have taught a flipped version of that which also seems to work quite well. But 600 00:53:00,130 --> 00:53:04,259 the important thing really I can't stress this enough that as a teacher and I 601 00:53:04,259 --> 00:53:07,939 skipped a couple of corners just now to fit in the time slot was that you go 602 00:53:07,939 --> 00:53:11,930 through all of those motions that you always go through all of that motion and 603 00:53:11,930 --> 00:53:16,390 that's a great tool not just for giving every single step a name but also for 604 00:53:16,390 --> 00:53:21,950 pacing the classroom and that and the rest kind of tends to fall in place has been my 605 00:53:21,950 --> 00:53:25,750 experience, right. No matter whether you're looking at you know beginning 606 00:53:25,750 --> 00:53:28,680 students or professional programmers. I'm not sure I answered your questions but 607 00:53:28,680 --> 00:53:34,249 maybe you can take the rest offline. Herald Angel: Thank you. Microphone 3 608 00:53:34,249 --> 00:53:37,680 please. Questioner: Yes. I think this is very 609 00:53:37,680 --> 00:53:43,809 great but it is teaching functional programming and many people will very soon 610 00:53:43,809 --> 00:53:50,400 need imperative programming. How do you do the switch or can you do it? 611 00:53:50,400 --> 00:53:54,339 Mike: So I I would dispute that but. *Laughter* 612 00:53:54,339 --> 00:53:57,150 Questioner: Well if you want to get paid for it. 613 00:53:57,150 --> 00:53:59,609 Mike: Thank you, go, go. *Laughter* 614 00:53:59,609 --> 00:54:02,960 Mike: So I run a company that does all their software projects doing functional 615 00:54:02,960 --> 00:54:06,979 programming. Ultimately you will need to talk about effects. The thing what this 616 00:54:06,979 --> 00:54:12,109 does really is I mean if you're writing software professionally you know no matter 617 00:54:12,109 --> 00:54:15,739 what the language is, large parts of that should be functional. So this is a great 618 00:54:15,739 --> 00:54:20,479 way to teach good programming discipline and a lot of programs out there don't show 619 00:54:20,479 --> 00:54:25,039 good programming discipline. So I think this would be great to improve upon that. 620 00:54:25,039 --> 00:54:29,180 So what this does is it pushes the boundary. To be honest I have no idea how 621 00:54:29,180 --> 00:54:32,509 to teach systematic development using imperative languages. I don't know how to 622 00:54:32,509 --> 00:54:35,890 do that. I don't know how to do it and I don't know how to teach doing it. On the 623 00:54:35,890 --> 00:54:40,789 other hand what I can do that do here is I can push the imperative parts of the 624 00:54:40,789 --> 00:54:44,240 programming to the fringe and make them less important for the success of my 625 00:54:44,240 --> 00:54:51,529 project and for the structure of my project. So yeah. So you should. This is 626 00:54:51,529 --> 00:54:55,259 the good thing because we know functional programming works well and we know it is a 627 00:54:55,259 --> 00:55:01,490 good foundation for an educational discipline. And yeah I can't, I mean there 628 00:55:01,490 --> 00:55:05,599 are there are various courses that build up upon this, but ask me offline about 629 00:55:05,599 --> 00:55:08,569 that that tackle that imperative programming. 630 00:55:08,569 --> 00:55:14,029 Herald Angel: OK then microphone 4 please. Questioner: Yeah I'd like to thank you for 631 00:55:14,029 --> 00:55:22,380 your talk too and I'm curious what's your experience how many repetitions do you 632 00:55:22,380 --> 00:55:28,539 need to teach your students until they settle with the principles. Do you teach 633 00:55:28,539 --> 00:55:32,920 like three examples or is it up to 10 examples? 634 00:55:32,920 --> 00:55:39,390 Mike: I'm not sure I have a solid rule for that. So my experience has been, so I think 635 00:55:39,390 --> 00:55:44,809 every principle here usually has like two in class examples at the university level 636 00:55:44,809 --> 00:55:48,670 and then has maybe three or four examples where they do exercises and that's usually 637 00:55:48,670 --> 00:55:52,539 enough but your experience might vary. I don't I don't think I have a good rule for 638 00:55:52,539 --> 00:55:58,739 that. Generally you might not have gotten for this but so the point of comparison 639 00:55:58,739 --> 00:56:02,420 and where I have the most experience is at the university level. Overall the 640 00:56:02,420 --> 00:56:06,509 progression of material in here is really really fast compared to your traditional 641 00:56:06,509 --> 00:56:11,969 Java course. So you can cover a lot of material using that. I'm not sure how many 642 00:56:11,969 --> 00:56:16,839 how many university students or university courses have successful video games in the 643 00:56:16,839 --> 00:56:21,719 middle of the first semester and there are nice programs that are well structured so 644 00:56:21,719 --> 00:56:26,539 so surprisingly maybe even though this is so boring and tedious it allows you to 645 00:56:26,539 --> 00:56:30,859 write programs successfully quite fast and also goes to lots of teaching to go quite 646 00:56:30,859 --> 00:56:34,819 fast. Herald Angel: OK. Microphone 2 please. 647 00:56:34,819 --> 00:56:40,979 Questioner: Hello, thank you for your talk. When I learned programming as a kid 648 00:56:40,979 --> 00:56:50,220 quite young and I think that I could transport tools and the mindset also to 649 00:56:50,220 --> 00:56:53,429 mathematics and full blown problems. Mike: Yes. 650 00:56:53,429 --> 00:57:00,900 Questioner: So I just wanted to ask if in your experience can children also use this 651 00:57:00,900 --> 00:57:07,959 systematic way of solving, I mean do they really make this transition? Can, are they 652 00:57:07,959 --> 00:57:11,310 getting better at solving problems? Mike: Yeah absolutely they do. So if you 653 00:57:11,310 --> 00:57:15,499 look at one of the three projects I listed was the Bootstrap Project which is which 654 00:57:15,499 --> 00:57:19,739 is aimed at high school students or middle school students and there the approach is 655 00:57:19,739 --> 00:57:23,510 specifically tied to the algebra part of mathematics and so this is where you'll 656 00:57:23,510 --> 00:57:28,529 find exactly what you're looking for. And that's been that project's been usually 657 00:57:28,529 --> 00:57:32,099 successful and they have lots of material on how it should be taught. So that's 658 00:57:32,099 --> 00:57:35,099 great stuff. Herald Angel: Okay, we have two more 659 00:57:35,099 --> 00:57:39,069 minutes and two questions. So Microphone 1 please. 660 00:57:39,069 --> 00:57:43,900 Questioner: Hi. How do you measure success in your teaching? 661 00:57:43,900 --> 00:57:48,559 Mike: So mostly at the university level we look at the final exams and we have a 662 00:57:48,559 --> 00:57:54,069 few papers out that are referenced from the web page there. That's I mean usually 663 00:57:54,069 --> 00:57:57,200 what we do is we have pretty close supervision, even at the university level. 664 00:57:57,200 --> 00:58:03,069 So we look over students' shoulders all the time to make sure that we're teaching 665 00:58:03,069 --> 00:58:07,359 them at the appropriate level and at the appropriate pace. But over the years we've 666 00:58:07,359 --> 00:58:13,200 seen measurable improvements by looking at the final exams and very specific ones. So 667 00:58:13,200 --> 00:58:16,959 we don't just look at the overall grade we look at individual problems and see all 668 00:58:16,959 --> 00:58:21,569 the progress has been and what we expect and there's papers out on that. 669 00:58:21,569 --> 00:58:25,440 Herald Angel: And micr ophone 4 please. 670 00:58:25,440 --> 00:58:33,059 Questioner: Is there some kind of auto completion in your editor or do you not 671 00:58:33,059 --> 00:58:36,569 advise us to use this feature for beginners? 672 00:58:36,569 --> 00:58:42,109 Mike: *Laughter*. No there's not auto completion as far as I know. I'm not sure 673 00:58:42,109 --> 00:58:47,670 I would advise against it. I know that my American colleagues they've I mean as 674 00:58:47,670 --> 00:58:51,319 you've noticed write the templates as it's sort of always recurring program elements 675 00:58:51,319 --> 00:58:56,289 and you could imagine there being a button that inserts that program fragment and our 676 00:58:56,289 --> 00:59:00,470 American friends they experiment with that and they came out not using that in 677 00:59:00,470 --> 00:59:04,039 practice anymore. But I can't tell you details on how that is. But if you're 678 00:59:04,039 --> 00:59:08,249 interested you could send me email and I could find out. So for some reason so I 679 00:59:08,249 --> 00:59:13,009 can't tell you why and I'm not I'm not ideologically opposed to that but we're 680 00:59:13,009 --> 00:59:18,670 not doing that. Herald Angel: OK then. Mike thank you for 681 00:59:18,670 --> 00:59:24,519 that very enlightening talk and become a big applause for that talk. 682 00:59:24,519 --> 00:59:32,119 Mike: Thank you very much. *Applause* 683 00:59:32,119 --> 00:59:37,494 *postroll music* 684 00:59:37,494 --> 00:59:55,000 Subttitles created by c3subtitles.de in the year 2019. Join and help us!