1 00:00:11,920 --> 00:00:18,560 hello pike online 2021 welcome back to 2 00:00:15,839 --> 00:00:21,039 the education track and it is my 3 00:00:18,560 --> 00:00:25,760 absolute pleasure to introduce shrey 4 00:00:21,039 --> 00:00:28,000 samaya to give a talk uh on python type 5 00:00:25,760 --> 00:00:33,040 hints and how they can supercharge cs 6 00:00:28,000 --> 00:00:35,280 education um this is very exciting i uh 7 00:00:33,040 --> 00:00:38,000 i want to know this and i i want this to 8 00:00:35,280 --> 00:00:40,000 be better and i'm hoping that you stray 9 00:00:38,000 --> 00:00:42,160 will improve the quality my quality of 10 00:00:40,000 --> 00:00:45,039 life through this talk 11 00:00:42,160 --> 00:00:48,640 it's a big ask i know um 12 00:00:45,039 --> 00:00:49,440 but i i i reckon you can do it um now 13 00:00:48,640 --> 00:00:52,640 uh 14 00:00:49,440 --> 00:00:54,000 trey i have i found a fabulous bio that 15 00:00:52,640 --> 00:00:55,840 i did submit but i didn't find it to 16 00:00:54,000 --> 00:00:59,760 begin with um and he said that i could 17 00:00:55,840 --> 00:01:01,920 make up anything about him um so uh i 18 00:00:59,760 --> 00:01:04,799 would like to start his bio by saying uh 19 00:01:01,920 --> 00:01:08,400 that shrey is joining us um following a 20 00:01:04,799 --> 00:01:12,799 wildly successful uh olympic performance 21 00:01:08,400 --> 00:01:14,560 um uh i was just amazed at how how how 22 00:01:12,799 --> 00:01:15,600 true to form um 23 00:01:14,560 --> 00:01:17,520 you showed real courage and 24 00:01:15,600 --> 00:01:19,840 determination i'm i'm proud of you i'm 25 00:01:17,520 --> 00:01:21,920 proud of you stretch for me yeah um 26 00:01:19,840 --> 00:01:26,000 but also shay is a course administrator 27 00:01:21,920 --> 00:01:27,680 and tutor of comp 1511 28 00:01:26,000 --> 00:01:30,560 uh the programming fundamentals course 29 00:01:27,680 --> 00:01:33,280 uh in unsw's school of computer science 30 00:01:30,560 --> 00:01:35,040 um he's been teaching in some form for 31 00:01:33,280 --> 00:01:37,200 most of his life and started tinkering 32 00:01:35,040 --> 00:01:39,119 with python in early high school uh 33 00:01:37,200 --> 00:01:41,840 trey's also currently co-president of 34 00:01:39,119 --> 00:01:45,600 the cse soc unsw which is the resident 35 00:01:41,840 --> 00:01:47,759 computer society of unsw um 36 00:01:45,600 --> 00:01:50,320 which is one of our universities here in 37 00:01:47,759 --> 00:01:52,960 new south wales um 38 00:01:50,320 --> 00:01:55,600 and he's leading a team of about 150 39 00:01:52,960 --> 00:01:58,479 people to create produce social events 40 00:01:55,600 --> 00:02:01,600 podcasts hackathons career events videos 41 00:01:58,479 --> 00:02:03,680 workshops peer mentoring ctfs assorted 42 00:02:01,600 --> 00:02:05,439 technical projects high school outreach 43 00:02:03,680 --> 00:02:08,080 and more 44 00:02:05,439 --> 00:02:09,920 so many things uh but you do so many 45 00:02:08,080 --> 00:02:11,680 fantastic things as part of it so um 46 00:02:09,920 --> 00:02:12,640 it's a fantastic society 47 00:02:11,680 --> 00:02:15,440 um 48 00:02:12,640 --> 00:02:17,760 and otherwise uh shrey apparently you 49 00:02:15,440 --> 00:02:19,280 love cats music reading and video games 50 00:02:17,760 --> 00:02:21,200 and that seems 51 00:02:19,280 --> 00:02:22,800 great and i would say you also 52 00:02:21,200 --> 00:02:24,160 love python ah 53 00:02:22,800 --> 00:02:27,360 we could have had a cat on the stream 54 00:02:24,160 --> 00:02:28,640 yes that's quite sad ah maybe next time 55 00:02:27,360 --> 00:02:30,640 all right well 56 00:02:28,640 --> 00:02:31,680 i'm keen to hear what you think um shrey 57 00:02:30,640 --> 00:02:33,280 will be 58 00:02:31,680 --> 00:02:36,640 accepting questions assuming i haven't 59 00:02:33,280 --> 00:02:39,360 taken up all of the time in this chat um 60 00:02:36,640 --> 00:02:40,319 so throw your questions in the stream 61 00:02:39,360 --> 00:02:41,519 yard 62 00:02:40,319 --> 00:02:43,680 chat 63 00:02:41,519 --> 00:02:45,920 and i will let you get to it 64 00:02:43,680 --> 00:02:48,160 cool awesome thank you so much nikki um 65 00:02:45,920 --> 00:02:49,200 cool so hello everyone as nicki drews my 66 00:02:48,160 --> 00:02:50,800 name is shrey 67 00:02:49,200 --> 00:02:54,000 just a quick note on this talk this talk 68 00:02:50,800 --> 00:02:55,840 is going through quite a lot um as usual 69 00:02:54,000 --> 00:02:57,360 um i want to talk about python type in 70 00:02:55,840 --> 00:02:59,280 so we're going to go a bit introduction 71 00:02:57,360 --> 00:03:01,120 about what is a type what is types 72 00:02:59,280 --> 00:03:02,959 safety what other type systems what are 73 00:03:01,120 --> 00:03:04,800 they useful for um we'll then go into 74 00:03:02,959 --> 00:03:06,239 the specifics of python type hints and 75 00:03:04,800 --> 00:03:08,239 how we can look at doing those and then 76 00:03:06,239 --> 00:03:09,760 we'll jump from there to 77 00:03:08,239 --> 00:03:12,159 using them in education how we can use 78 00:03:09,760 --> 00:03:14,319 type ins to force students to design 79 00:03:12,159 --> 00:03:16,879 better think uh as a software engineer 80 00:03:14,319 --> 00:03:19,040 and actually do a full uh front to back 81 00:03:16,879 --> 00:03:20,879 sort of design of that program so let's 82 00:03:19,040 --> 00:03:22,640 jump straight into it um and i'm hoping 83 00:03:20,879 --> 00:03:24,799 that i stick on time otherwise i'm going 84 00:03:22,640 --> 00:03:26,959 to get yelled at so let's go um 85 00:03:24,799 --> 00:03:28,000 disclaimer i am not a genius i'm not 86 00:03:26,959 --> 00:03:29,920 guido 87 00:03:28,000 --> 00:03:31,120 i do not know everything i only know 88 00:03:29,920 --> 00:03:33,280 some things and i'm going to tell you 89 00:03:31,120 --> 00:03:35,440 about those some things i may be wrong 90 00:03:33,280 --> 00:03:38,159 and please please inform me if i am 91 00:03:35,440 --> 00:03:40,560 yes thank you cool so 92 00:03:38,159 --> 00:03:42,319 safety uh what is safety when we talk 93 00:03:40,560 --> 00:03:44,480 about programming languages and running 94 00:03:42,319 --> 00:03:46,000 our code what is safety um i was reading 95 00:03:44,480 --> 00:03:48,640 a stanford article that talks about 96 00:03:46,000 --> 00:03:50,319 safety as a vague term lacking great 97 00:03:48,640 --> 00:03:51,760 definition and i was like great that's 98 00:03:50,319 --> 00:03:54,000 very useful for my python talk i'm going 99 00:03:51,760 --> 00:03:55,200 to slap that right in there um but for 100 00:03:54,000 --> 00:03:57,040 the purpose of this talk we'll say 101 00:03:55,200 --> 00:03:59,599 something on the lines of safety is 102 00:03:57,040 --> 00:04:01,200 about avoiding harmful mistakes um now 103 00:03:59,599 --> 00:04:02,879 when we run our code when we run our 104 00:04:01,200 --> 00:04:05,360 python code we usually run into sort of 105 00:04:02,879 --> 00:04:07,360 two major problems uh our program 106 00:04:05,360 --> 00:04:08,879 crashes and burns it holds it stops 107 00:04:07,360 --> 00:04:12,159 there's some sort of error and says you 108 00:04:08,879 --> 00:04:14,000 can't do this or this failed or we get 109 00:04:12,159 --> 00:04:16,479 we have like a human error undefined 110 00:04:14,000 --> 00:04:18,000 behavior unexpected behavior something 111 00:04:16,479 --> 00:04:21,359 went wrong but the program still runs 112 00:04:18,000 --> 00:04:23,840 fine um and so if only there was a way 113 00:04:21,359 --> 00:04:25,919 that we could avoid these behaviors as 114 00:04:23,840 --> 00:04:27,759 much as we could uh 115 00:04:25,919 --> 00:04:29,680 psych there is and that's called type 116 00:04:27,759 --> 00:04:31,520 safety so 117 00:04:29,680 --> 00:04:35,199 a lot of type languages 118 00:04:31,520 --> 00:04:38,000 such as c rust etc can attempt to 119 00:04:35,199 --> 00:04:40,880 enforce good behavior including safety 120 00:04:38,000 --> 00:04:42,800 by performing static checks when you run 121 00:04:40,880 --> 00:04:44,240 the code so when you run the code it 122 00:04:42,800 --> 00:04:46,880 scans through and checks all right 123 00:04:44,240 --> 00:04:48,400 you've said this variable is an integer 124 00:04:46,880 --> 00:04:50,479 but you're trying to multiply it by a 125 00:04:48,400 --> 00:04:52,320 string i can't multiply an integer by a 126 00:04:50,479 --> 00:04:53,840 string i'm not going to let you run the 127 00:04:52,320 --> 00:04:55,759 code so it doesn't even get to that 128 00:04:53,840 --> 00:04:58,160 running point so this is what we call a 129 00:04:55,759 --> 00:04:59,680 statically checked language 130 00:04:58,160 --> 00:05:01,360 the process of checking the code is 131 00:04:59,680 --> 00:05:03,120 called type checking 132 00:05:01,360 --> 00:05:04,960 and the algorithm that does the checking 133 00:05:03,120 --> 00:05:07,199 is called the type checker so if you 134 00:05:04,960 --> 00:05:08,479 hear me jumble those like language later 135 00:05:07,199 --> 00:05:10,000 on the talk 136 00:05:08,479 --> 00:05:11,120 that's what we're talking about so 137 00:05:10,000 --> 00:05:13,520 essentially 138 00:05:11,120 --> 00:05:16,400 every value has a type and when you run 139 00:05:13,520 --> 00:05:18,800 the code the operations on the value are 140 00:05:16,400 --> 00:05:20,880 checked per the type now python doesn't 141 00:05:18,800 --> 00:05:22,880 do this python does something different 142 00:05:20,880 --> 00:05:25,120 python's what we call it dynamically 143 00:05:22,880 --> 00:05:26,320 oops i already talked about this yikes 144 00:05:25,120 --> 00:05:28,240 um 145 00:05:26,320 --> 00:05:29,919 python does something different python 146 00:05:28,240 --> 00:05:31,199 does what we call dynamically typelink 147 00:05:29,919 --> 00:05:34,000 it's a dynamically typed language and 148 00:05:31,199 --> 00:05:35,360 we'll go over it in a bit um but in 149 00:05:34,000 --> 00:05:37,120 python we don't have these types right 150 00:05:35,360 --> 00:05:38,479 so why not if it sounds so great if we 151 00:05:37,120 --> 00:05:40,400 can avoid these errors if we can if we 152 00:05:38,479 --> 00:05:42,320 can make our code better why don't we do 153 00:05:40,400 --> 00:05:44,639 it and the answer here is convenience 154 00:05:42,320 --> 00:05:47,440 right imagine if you had to specify for 155 00:05:44,639 --> 00:05:49,759 every single variable what type it was 156 00:05:47,440 --> 00:05:51,360 it would be so slow to write your code 157 00:05:49,759 --> 00:05:53,280 especially when you want to use python 158 00:05:51,360 --> 00:05:54,800 for quick quick tools right so a lot of 159 00:05:53,280 --> 00:05:57,280 the time i'll use python for doing some 160 00:05:54,800 --> 00:05:58,479 quick dynamic or changing formats of 161 00:05:57,280 --> 00:06:00,240 stuff i don't really want to make it 162 00:05:58,479 --> 00:06:02,560 work correctly i just want to work very 163 00:06:00,240 --> 00:06:04,400 quickly i want to write it quickly so 164 00:06:02,560 --> 00:06:06,639 we lose some safety but we get a lot of 165 00:06:04,400 --> 00:06:08,560 convenience um 166 00:06:06,639 --> 00:06:10,639 so python instead instead of having 167 00:06:08,560 --> 00:06:14,000 static typing we have what we call 168 00:06:10,639 --> 00:06:16,560 doctyping um or dynamic typing so what 169 00:06:14,000 --> 00:06:18,319 is doctyping and how is that relevant to 170 00:06:16,560 --> 00:06:21,360 what i'm about to tell you so duck 171 00:06:18,319 --> 00:06:24,400 typing is not this one duck typing is 172 00:06:21,360 --> 00:06:27,600 something like this so python it only 173 00:06:24,400 --> 00:06:29,840 checks if you're allowed to do something 174 00:06:27,600 --> 00:06:31,520 it doesn't check if it's the it doesn't 175 00:06:29,840 --> 00:06:33,440 check it at compile time it checks it 176 00:06:31,520 --> 00:06:34,479 when you're running the code so for 177 00:06:33,440 --> 00:06:36,319 example 178 00:06:34,479 --> 00:06:37,680 let's say you have a class duck 179 00:06:36,319 --> 00:06:39,199 my cursor doesn't show let's say you 180 00:06:37,680 --> 00:06:41,280 have a class duck 181 00:06:39,199 --> 00:06:42,800 this duck has a quack method when you 182 00:06:41,280 --> 00:06:44,720 call the quack method 183 00:06:42,800 --> 00:06:46,880 it will print out quack 184 00:06:44,720 --> 00:06:48,479 there's also in this code a say quack 185 00:06:46,880 --> 00:06:49,840 function which takes in a variable 186 00:06:48,479 --> 00:06:52,000 called duck 187 00:06:49,840 --> 00:06:53,039 so when takes in the variable it'll say 188 00:06:52,000 --> 00:06:55,280 uh 189 00:06:53,039 --> 00:06:57,599 of that instance of a class of that doc 190 00:06:55,280 --> 00:06:59,520 tell it to quack so if we have a new 191 00:06:57,599 --> 00:07:02,000 duck called jeff and we say all right 192 00:06:59,520 --> 00:07:03,440 jeff say quack jeff will say quack cool 193 00:07:02,000 --> 00:07:04,960 this this works fine this is as we 194 00:07:03,440 --> 00:07:06,000 expect um 195 00:07:04,960 --> 00:07:07,919 but 196 00:07:06,000 --> 00:07:10,400 what happens if we have a dog class and 197 00:07:07,919 --> 00:07:12,479 this dog class also has a quack method 198 00:07:10,400 --> 00:07:16,160 uh if we tell the dog to quack it'll 199 00:07:12,479 --> 00:07:17,599 quack and so duck typing essentially is 200 00:07:16,160 --> 00:07:20,160 if it quacks like a duck and it walks 201 00:07:17,599 --> 00:07:22,000 like a duck then it must be a dock so if 202 00:07:20,160 --> 00:07:24,000 it's able to do the thing that you ask 203 00:07:22,000 --> 00:07:26,880 it to do then that's fine that's okay 204 00:07:24,000 --> 00:07:29,120 and that's all we care about um 205 00:07:26,880 --> 00:07:30,479 so you might be wondering oh my gosh why 206 00:07:29,120 --> 00:07:31,919 are we talking about type systems and 207 00:07:30,479 --> 00:07:34,000 type theory i thought i was here a lot 208 00:07:31,919 --> 00:07:35,120 of education and yes as i mentioned 209 00:07:34,000 --> 00:07:37,280 we'll get we'll get there we'll get 210 00:07:35,120 --> 00:07:39,840 there i promise uh assuming i get kicked 211 00:07:37,280 --> 00:07:41,039 out but we'll get there um 212 00:07:39,840 --> 00:07:43,199 so 213 00:07:41,039 --> 00:07:45,039 i was going through some old hsc code 214 00:07:43,199 --> 00:07:46,400 that i wrote so uh in new south wales 215 00:07:45,039 --> 00:07:47,840 there's a system called the hsc where 216 00:07:46,400 --> 00:07:50,560 students will do a series of subjects 217 00:07:47,840 --> 00:07:53,039 towards their final grade um and as part 218 00:07:50,560 --> 00:07:55,039 of the software design hsd subject which 219 00:07:53,039 --> 00:07:57,360 i did in elective you have to write a 220 00:07:55,039 --> 00:07:59,120 massive major work so i was going 221 00:07:57,360 --> 00:08:00,720 through a lot of my code for this talk 222 00:07:59,120 --> 00:08:02,720 to see if there's anything i could use 223 00:08:00,720 --> 00:08:05,039 as an example of code that was 224 00:08:02,720 --> 00:08:07,440 questionable and hard to understand and 225 00:08:05,039 --> 00:08:09,599 i came across this function um this 226 00:08:07,440 --> 00:08:11,599 function is called get body it takes in 227 00:08:09,599 --> 00:08:15,360 a message it checks if the message is 228 00:08:11,599 --> 00:08:18,720 multi-part uh then it returns itself 229 00:08:15,360 --> 00:08:21,840 or a get payload so what is what is 230 00:08:18,720 --> 00:08:24,319 message uh is message some sort of class 231 00:08:21,840 --> 00:08:26,639 is is it a function or a type from 232 00:08:24,319 --> 00:08:28,400 somewhere else like uh what is is 233 00:08:26,639 --> 00:08:30,800 multi-part i've never seen it before at 234 00:08:28,400 --> 00:08:32,800 all um so 235 00:08:30,800 --> 00:08:34,719 looking at my code it's very difficult 236 00:08:32,800 --> 00:08:36,640 to reason what it's doing and how it 237 00:08:34,719 --> 00:08:38,080 works i don't know what messages i don't 238 00:08:36,640 --> 00:08:39,839 know what it's supposed to return there 239 00:08:38,080 --> 00:08:42,159 are so many things here that is very 240 00:08:39,839 --> 00:08:43,680 difficult to understand and extracts the 241 00:08:42,159 --> 00:08:45,040 body from the email 242 00:08:43,680 --> 00:08:46,560 doesn't help at all 243 00:08:45,040 --> 00:08:49,440 until i read this comment i had no idea 244 00:08:46,560 --> 00:08:51,680 this is about emails um so 245 00:08:49,440 --> 00:08:54,320 i wonder what that's looking at 246 00:08:51,680 --> 00:08:56,240 so if i were to call get body of hello 247 00:08:54,320 --> 00:08:58,480 uh i don't really know what will happen 248 00:08:56,240 --> 00:09:01,040 here and so oh no my error message 249 00:08:58,480 --> 00:09:01,920 didn't appear oh no okay well if i did 250 00:09:01,040 --> 00:09:04,240 this 251 00:09:01,920 --> 00:09:06,720 there's a big error saying uh you cannot 252 00:09:04,240 --> 00:09:09,120 run is multipart on hello um so my 253 00:09:06,720 --> 00:09:10,880 python code just stops and breaks 254 00:09:09,120 --> 00:09:13,600 which is not good we want this stuff to 255 00:09:10,880 --> 00:09:15,519 be checked before we run the code um so 256 00:09:13,600 --> 00:09:17,279 the way we can do this is using type ins 257 00:09:15,519 --> 00:09:19,680 um and so we can tell our function 258 00:09:17,279 --> 00:09:21,839 message is of type blah and we can say 259 00:09:19,680 --> 00:09:24,399 please only do this if this is correct 260 00:09:21,839 --> 00:09:26,080 right so if i say message is a string 261 00:09:24,399 --> 00:09:28,240 this will run fine if i say message 262 00:09:26,080 --> 00:09:30,160 should be an integer or a number and i 263 00:09:28,240 --> 00:09:32,320 say get body of hello my program will 264 00:09:30,160 --> 00:09:34,160 error saying hey you've made a mistake 265 00:09:32,320 --> 00:09:36,560 you've passed in a string where i 266 00:09:34,160 --> 00:09:38,959 expected a number um so let's go over 267 00:09:36,560 --> 00:09:41,279 how to do some of that in python 268 00:09:38,959 --> 00:09:42,720 so in python type ins are written as 269 00:09:41,279 --> 00:09:45,040 annotations 270 00:09:42,720 --> 00:09:47,040 our type ins are completely ignored when 271 00:09:45,040 --> 00:09:48,160 you run the program uh which is you 272 00:09:47,040 --> 00:09:51,120 might be thinking well what the heck's 273 00:09:48,160 --> 00:09:52,959 the point then um typings are ignored 274 00:09:51,120 --> 00:09:54,959 for quite a good reason 275 00:09:52,959 --> 00:09:56,880 which is that you shouldn't be forced to 276 00:09:54,959 --> 00:09:58,320 write python code that has types right 277 00:09:56,880 --> 00:10:00,399 you should that shouldn't be mandatory 278 00:09:58,320 --> 00:10:02,160 so there are actual tools out there 279 00:10:00,399 --> 00:10:03,040 where you run you run the tool on your 280 00:10:02,160 --> 00:10:04,640 code 281 00:10:03,040 --> 00:10:07,680 a good example is something called my pi 282 00:10:04,640 --> 00:10:09,680 which is a very common python supported 283 00:10:07,680 --> 00:10:11,519 type checking program 284 00:10:09,680 --> 00:10:13,120 and you run this over your code it will 285 00:10:11,519 --> 00:10:14,560 then look at the annotations and it will 286 00:10:13,120 --> 00:10:16,640 check that you've done the right things 287 00:10:14,560 --> 00:10:17,920 when you just run python 3 in your code 288 00:10:16,640 --> 00:10:19,760 it won't actually check your types you 289 00:10:17,920 --> 00:10:21,920 can do something completely wrong um so 290 00:10:19,760 --> 00:10:22,880 as python we start as annotations and so 291 00:10:21,920 --> 00:10:24,959 the syntax for this looks something 292 00:10:22,880 --> 00:10:27,200 along the lines of this so 293 00:10:24,959 --> 00:10:29,760 for example i have a variable called age 294 00:10:27,200 --> 00:10:33,680 age i've said is an int or an integer or 295 00:10:29,760 --> 00:10:35,920 a number um and that has a value of 20. 296 00:10:33,680 --> 00:10:38,959 so quite standard you say your variable 297 00:10:35,920 --> 00:10:42,079 name the type and then the value 298 00:10:38,959 --> 00:10:45,279 groceries groceries is a dictionary of 299 00:10:42,079 --> 00:10:46,880 uh string keys to int values 300 00:10:45,279 --> 00:10:49,200 and you can see i've initialized it with 301 00:10:46,880 --> 00:10:50,399 apples goes to five and chocolates goes 302 00:10:49,200 --> 00:10:51,760 to three 303 00:10:50,399 --> 00:10:55,040 and so there are a bunch of what we call 304 00:10:51,760 --> 00:10:57,440 basic types here um so integer bull 305 00:10:55,040 --> 00:10:58,880 float string bytes list blah blah blah 306 00:10:57,440 --> 00:11:03,040 blah 307 00:10:58,880 --> 00:11:05,360 none is also a type that we can use um 308 00:11:03,040 --> 00:11:07,360 so a quick aside 309 00:11:05,360 --> 00:11:10,959 um oh that's not the quickest i wanted 310 00:11:07,360 --> 00:11:12,560 uh here back here we have a dict 311 00:11:10,959 --> 00:11:14,399 in earlier versions of python so 312 00:11:12,560 --> 00:11:17,000 previous to 3.9 313 00:11:14,399 --> 00:11:19,200 you actually have to use typing.dick so 314 00:11:17,000 --> 00:11:21,120 typing.capitaldedict and so you often 315 00:11:19,200 --> 00:11:22,720 see sometimes that sometimes people use 316 00:11:21,120 --> 00:11:24,720 capital dedic sometimes people use 317 00:11:22,720 --> 00:11:27,680 lowercase dict it's encouraged that if 318 00:11:24,720 --> 00:11:29,519 you're using above python 3.9 you'll be 319 00:11:27,680 --> 00:11:31,040 using the lowercase d dict because i 320 00:11:29,519 --> 00:11:32,800 think it just looks a lot better like 321 00:11:31,040 --> 00:11:34,399 why would you use typing into 322 00:11:32,800 --> 00:11:36,399 typing.typing.list 323 00:11:34,399 --> 00:11:38,880 when you can just write dict list int 324 00:11:36,399 --> 00:11:40,160 right it's a lot easier to read um so 325 00:11:38,880 --> 00:11:41,839 just want to note that if you do come 326 00:11:40,160 --> 00:11:43,519 across this in the wild and you see a 327 00:11:41,839 --> 00:11:45,200 uppercase d dict 328 00:11:43,519 --> 00:11:47,920 or an uppercase l list 329 00:11:45,200 --> 00:11:49,600 that is presumably using old uh typing 330 00:11:47,920 --> 00:11:51,839 instances so 331 00:11:49,600 --> 00:11:53,760 we want to know that so 332 00:11:51,839 --> 00:11:55,440 if i was to run this code i specified 333 00:11:53,760 --> 00:11:58,079 all right agent int 334 00:11:55,440 --> 00:11:59,680 age is equal to string 20. 335 00:11:58,079 --> 00:12:01,680 this should probably error right if i 336 00:11:59,680 --> 00:12:04,800 run this with a type checker tool like 337 00:12:01,680 --> 00:12:06,800 my pi it says incompatible types you 338 00:12:04,800 --> 00:12:08,720 said age is an int but now you're saying 339 00:12:06,800 --> 00:12:10,240 it's a string and all of a sudden we can 340 00:12:08,720 --> 00:12:12,399 really see the value in this sort of 341 00:12:10,240 --> 00:12:14,240 type checking um if i make a silly 342 00:12:12,399 --> 00:12:16,240 mistake later on the line in my code and 343 00:12:14,240 --> 00:12:18,160 i make so many silly mistakes trust me i 344 00:12:16,240 --> 00:12:20,320 can statically check this before i run 345 00:12:18,160 --> 00:12:22,079 my code before i run my code in a server 346 00:12:20,320 --> 00:12:23,440 or i ship my code out to people i can 347 00:12:22,079 --> 00:12:25,440 check everything is okay and there's no 348 00:12:23,440 --> 00:12:27,360 silly mistakes rather than just running 349 00:12:25,440 --> 00:12:29,360 it or writing a billion tests now tests 350 00:12:27,360 --> 00:12:30,959 are important in their own right but um 351 00:12:29,360 --> 00:12:32,560 this gives you some sort of static 352 00:12:30,959 --> 00:12:34,959 assurance which is a common buzzword 353 00:12:32,560 --> 00:12:36,240 that you'll hear thrown around um cool 354 00:12:34,959 --> 00:12:37,839 so we've talked about variable 355 00:12:36,240 --> 00:12:40,399 annotations let's talk about function 356 00:12:37,839 --> 00:12:41,680 annotations um so function annotations 357 00:12:40,399 --> 00:12:43,920 have a similar sort of syntax where you 358 00:12:41,680 --> 00:12:45,920 have your function name and each of the 359 00:12:43,920 --> 00:12:47,920 arguments each of the arguments are 360 00:12:45,920 --> 00:12:50,639 annotated as variables so for example 361 00:12:47,920 --> 00:12:52,639 our nums variable or nums argument is a 362 00:12:50,639 --> 00:12:55,120 list of integers right this is really 363 00:12:52,639 --> 00:12:56,639 easy to read um your target is also an 364 00:12:55,120 --> 00:12:58,720 integer 365 00:12:56,639 --> 00:13:00,079 now the next part is a bit tricky 366 00:12:58,720 --> 00:13:01,600 traditionally with python functions 367 00:13:00,079 --> 00:13:03,680 you'd write uh we'll go back to our 368 00:13:01,600 --> 00:13:05,519 example over here 369 00:13:03,680 --> 00:13:07,760 over here all you need to do is write 370 00:13:05,519 --> 00:13:10,240 def your function name and in brackets 371 00:13:07,760 --> 00:13:11,200 your parameters followed by a 372 00:13:10,240 --> 00:13:14,320 colon 373 00:13:11,200 --> 00:13:14,320 when you're using typeints 374 00:13:14,800 --> 00:13:18,560 you want to write your function name 375 00:13:16,720 --> 00:13:20,959 your arguments which are all typed 376 00:13:18,560 --> 00:13:23,360 followed by an arrow to the return type 377 00:13:20,959 --> 00:13:26,240 so in this case our two sum function 378 00:13:23,360 --> 00:13:28,160 should uh find which two integers and so 379 00:13:26,240 --> 00:13:30,160 it should return a list of int so this 380 00:13:28,160 --> 00:13:32,240 is the syntax you'll see it returns with 381 00:13:30,160 --> 00:13:33,760 the arrow a list of int followed by the 382 00:13:32,240 --> 00:13:35,200 colon 383 00:13:33,760 --> 00:13:36,880 in the case where your function returns 384 00:13:35,200 --> 00:13:39,600 nothing which is often the case for some 385 00:13:36,880 --> 00:13:41,120 python programs um you can just say it 386 00:13:39,600 --> 00:13:42,000 returns none 387 00:13:41,120 --> 00:13:44,560 um 388 00:13:42,000 --> 00:13:45,920 which is a really useful pattern to have 389 00:13:44,560 --> 00:13:47,279 sometimes people will 390 00:13:45,920 --> 00:13:49,279 won't add the 391 00:13:47,279 --> 00:13:50,720 returns none part which can make type 392 00:13:49,279 --> 00:13:53,360 checkers confused some type checkers 393 00:13:50,720 --> 00:13:55,760 will uh will assume that you mean none 394 00:13:53,360 --> 00:13:58,560 some type because won't um you can also 395 00:13:55,760 --> 00:14:00,160 do parameters with multiple options so 396 00:13:58,560 --> 00:14:03,760 for example you say my argument is a 397 00:14:00,160 --> 00:14:06,160 string or it's an integer or it's none 398 00:14:03,760 --> 00:14:08,240 um now notably this syntax for the the 399 00:14:06,160 --> 00:14:10,560 union or the bar is only supported from 400 00:14:08,240 --> 00:14:12,639 python 3.10 so i did bait you a little 401 00:14:10,560 --> 00:14:15,120 bit there um but you can use what's 402 00:14:12,639 --> 00:14:17,199 called a union uh if you google python 403 00:14:15,120 --> 00:14:18,880 type union uh you can do the same sort 404 00:14:17,199 --> 00:14:20,480 of thing i just like the syntax a lot 405 00:14:18,880 --> 00:14:22,560 better it's a lot easier to read 406 00:14:20,480 --> 00:14:24,000 um cool so 407 00:14:22,560 --> 00:14:25,440 i did some more research on this 408 00:14:24,000 --> 00:14:27,920 function that we're talking back back 409 00:14:25,440 --> 00:14:30,399 about before um it turns out that my 410 00:14:27,920 --> 00:14:31,920 message is an email message um and it 411 00:14:30,399 --> 00:14:33,199 goes through the email and it checks if 412 00:14:31,920 --> 00:14:35,600 it's a if it's a message that has 413 00:14:33,199 --> 00:14:37,440 multiple parts and it will get me a list 414 00:14:35,600 --> 00:14:40,320 of all those parts so 415 00:14:37,440 --> 00:14:41,839 i added some types to this thing um 416 00:14:40,320 --> 00:14:44,639 i have to import email because these 417 00:14:41,839 --> 00:14:45,760 types are their classes so you can also 418 00:14:44,639 --> 00:14:47,360 add 419 00:14:45,760 --> 00:14:49,519 type annotations that are classes so i 420 00:14:47,360 --> 00:14:51,440 can say my message is an email message 421 00:14:49,519 --> 00:14:53,440 email message class so i have to import 422 00:14:51,440 --> 00:14:54,959 email there so i can access to that so 423 00:14:53,440 --> 00:14:57,120 now when i run get body of test it 424 00:14:54,959 --> 00:14:58,639 errors and says all right argument one 425 00:14:57,120 --> 00:15:00,720 to get body is an incompatible type it 426 00:14:58,639 --> 00:15:01,600 has string i expected an email message 427 00:15:00,720 --> 00:15:04,079 um 428 00:15:01,600 --> 00:15:06,079 please try again uh so 429 00:15:04,079 --> 00:15:07,839 this is really really useful now looking 430 00:15:06,079 --> 00:15:09,600 at this code i can clearly see all right 431 00:15:07,839 --> 00:15:11,600 i know what it's expecting and i know 432 00:15:09,600 --> 00:15:13,440 what it's uh what i what i'm gonna get 433 00:15:11,600 --> 00:15:14,880 out of it and so 434 00:15:13,440 --> 00:15:16,560 without having to run the code i can 435 00:15:14,880 --> 00:15:18,079 already do some manipulations on this 436 00:15:16,560 --> 00:15:19,920 right if i was just reading this code i 437 00:15:18,079 --> 00:15:21,839 can say all right well get body returns 438 00:15:19,920 --> 00:15:23,360 a list i want to then have another 439 00:15:21,839 --> 00:15:25,279 function that will process the body of 440 00:15:23,360 --> 00:15:26,959 emails and it will go through each item 441 00:15:25,279 --> 00:15:28,320 in the list i don't have to waste time 442 00:15:26,959 --> 00:15:30,800 trying to figure out what it's returning 443 00:15:28,320 --> 00:15:32,320 or what it's actually giving etc etc so 444 00:15:30,800 --> 00:15:34,240 you save so much time and energy and 445 00:15:32,320 --> 00:15:35,920 cognitive load you just have to read 446 00:15:34,240 --> 00:15:38,240 this sort of one line to understand how 447 00:15:35,920 --> 00:15:40,480 the function works um which is really 448 00:15:38,240 --> 00:15:41,920 super useful so 449 00:15:40,480 --> 00:15:44,880 let's hop back over to the education 450 00:15:41,920 --> 00:15:47,279 part of things um type ins allow us to 451 00:15:44,880 --> 00:15:49,360 design our program first um when i was 452 00:15:47,279 --> 00:15:51,360 talking to some hsc students who were 453 00:15:49,360 --> 00:15:52,720 doing their software major works 454 00:15:51,360 --> 00:15:55,040 i was talking a lot about designing 455 00:15:52,720 --> 00:15:56,880 their program first don't just rush into 456 00:15:55,040 --> 00:15:58,639 things and code it all up design how 457 00:15:56,880 --> 00:16:01,120 your how your program how part of your 458 00:15:58,639 --> 00:16:02,480 program talk to each other and 459 00:16:01,120 --> 00:16:04,399 they would have had a lot of trouble 460 00:16:02,480 --> 00:16:05,360 coming up with how to do that um and so 461 00:16:04,399 --> 00:16:07,040 this is how i thought of this talk 462 00:16:05,360 --> 00:16:09,199 because type ins allow us to do this 463 00:16:07,040 --> 00:16:11,040 they allow us to specify all right my 464 00:16:09,199 --> 00:16:12,480 function a is going to return a message 465 00:16:11,040 --> 00:16:14,160 that looks like this 466 00:16:12,480 --> 00:16:15,279 function b should also expect a message 467 00:16:14,160 --> 00:16:17,040 that looks like this and return a 468 00:16:15,279 --> 00:16:18,079 different type of message and so all you 469 00:16:17,040 --> 00:16:20,079 need to do is write out the function 470 00:16:18,079 --> 00:16:22,480 prototypes and then you can see how your 471 00:16:20,079 --> 00:16:24,880 program interacts so 472 00:16:22,480 --> 00:16:26,399 for example um i was doing a networks 473 00:16:24,880 --> 00:16:28,320 assignment for my university my 474 00:16:26,399 --> 00:16:31,680 university course um 475 00:16:28,320 --> 00:16:33,360 and so i wanted a way to have a user as 476 00:16:31,680 --> 00:16:35,040 a dictionary right because i didn't want 477 00:16:33,360 --> 00:16:37,519 to do classes classes are too confusing 478 00:16:35,040 --> 00:16:39,360 for me sometimes um so i just wanted a 479 00:16:37,519 --> 00:16:40,800 dictionary but i wanted the dictionary 480 00:16:39,360 --> 00:16:42,399 to have a special type i wanted to be 481 00:16:40,800 --> 00:16:44,000 able to say all right this function 482 00:16:42,399 --> 00:16:46,160 should expect a user this function is a 483 00:16:44,000 --> 00:16:47,839 return user and so there's a thing 484 00:16:46,160 --> 00:16:48,880 called a typed dictionary which you can 485 00:16:47,839 --> 00:16:51,279 use 486 00:16:48,880 --> 00:16:53,360 which will allow you to make a uh 487 00:16:51,279 --> 00:16:55,120 essentially a type which is essentially 488 00:16:53,360 --> 00:16:56,800 a dictionary and it's a bit confusing 489 00:16:55,120 --> 00:16:59,440 but essentially 490 00:16:56,800 --> 00:17:00,480 my user dictionary has a password which 491 00:16:59,440 --> 00:17:02,160 is a string 492 00:17:00,480 --> 00:17:04,160 uh in a number of inbound login attempts 493 00:17:02,160 --> 00:17:05,839 which is an integer at the last login 494 00:17:04,160 --> 00:17:07,600 which is a date or time 495 00:17:05,839 --> 00:17:09,760 the last login can also be none and you 496 00:17:07,600 --> 00:17:11,520 can see the same pattern goes further on 497 00:17:09,760 --> 00:17:13,439 so when i want to make a new user all i 498 00:17:11,520 --> 00:17:15,199 have to do is say all right well john 499 00:17:13,439 --> 00:17:17,199 john is of type user remember we have 500 00:17:15,199 --> 00:17:19,360 the columns say this is of type blah so 501 00:17:17,199 --> 00:17:21,360 this is a type user 502 00:17:19,360 --> 00:17:23,199 and this is all the values for when we 503 00:17:21,360 --> 00:17:25,120 first make our new new 504 00:17:23,199 --> 00:17:26,799 user now this is really useful now 505 00:17:25,120 --> 00:17:28,400 because when i'm designing my program i 506 00:17:26,799 --> 00:17:30,160 can say all right well i want a function 507 00:17:28,400 --> 00:17:32,080 that gets all the logged in users for my 508 00:17:30,160 --> 00:17:33,679 program so let me just write out the 509 00:17:32,080 --> 00:17:35,760 prototype for this uh what the function 510 00:17:33,679 --> 00:17:37,840 might look like uh get logged in users 511 00:17:35,760 --> 00:17:39,679 will return a list of users like how 512 00:17:37,840 --> 00:17:40,559 useful is this now we can just say all 513 00:17:39,679 --> 00:17:41,760 right we don't have to think about 514 00:17:40,559 --> 00:17:43,360 anything else we can just go through and 515 00:17:41,760 --> 00:17:44,799 design all the different things that 516 00:17:43,360 --> 00:17:45,840 we're going to need for our program so i 517 00:17:44,799 --> 00:17:47,520 actually went through and i designed a 518 00:17:45,840 --> 00:17:49,440 whole bunch of functions and a whole 519 00:17:47,520 --> 00:17:50,400 bunch of types that i might need later 520 00:17:49,440 --> 00:17:53,039 on 521 00:17:50,400 --> 00:17:54,799 and it was super super useful um and 522 00:17:53,039 --> 00:17:57,440 easier to sort of break down my program 523 00:17:54,799 --> 00:17:59,840 into multiple parts so types allow us to 524 00:17:57,440 --> 00:18:01,280 not only have guaranteed safety but they 525 00:17:59,840 --> 00:18:03,600 allow us to design our program a lot 526 00:18:01,280 --> 00:18:04,960 better and this is why i think typins 527 00:18:03,600 --> 00:18:07,520 and the future of python typing is gonna 528 00:18:04,960 --> 00:18:09,679 be super awesome for teaching we can now 529 00:18:07,520 --> 00:18:11,679 design and teach about python in terms 530 00:18:09,679 --> 00:18:12,960 of design first no longer do we have to 531 00:18:11,679 --> 00:18:14,559 say all right just run your program test 532 00:18:12,960 --> 00:18:16,720 for this test with that while that is a 533 00:18:14,559 --> 00:18:19,679 useful strategy sometimes we can now 534 00:18:16,720 --> 00:18:21,919 also say if we want to oh design out 535 00:18:19,679 --> 00:18:23,520 your code first and then go back and 536 00:18:21,919 --> 00:18:24,559 code it um 537 00:18:23,520 --> 00:18:26,320 so 538 00:18:24,559 --> 00:18:29,039 another awesome part of type hinting is 539 00:18:26,320 --> 00:18:31,200 documentation um for example back on our 540 00:18:29,039 --> 00:18:32,559 email function we can now see if i'll 541 00:18:31,200 --> 00:18:34,320 send this screenshot to someone and say 542 00:18:32,559 --> 00:18:35,679 hey do you know why this isn't working 543 00:18:34,320 --> 00:18:37,200 they can now see all right well message 544 00:18:35,679 --> 00:18:39,280 is supposed to be this and it's supposed 545 00:18:37,200 --> 00:18:41,280 to return this if they wanted to look at 546 00:18:39,280 --> 00:18:42,320 uh all right what is is multipart 547 00:18:41,280 --> 00:18:43,280 they'll just need to google the 548 00:18:42,320 --> 00:18:45,360 documentation for an 549 00:18:43,280 --> 00:18:47,039 email.message.emailmessage 550 00:18:45,360 --> 00:18:47,840 um or they could find it elsewhere in my 551 00:18:47,039 --> 00:18:49,200 code 552 00:18:47,840 --> 00:18:50,559 um and 553 00:18:49,200 --> 00:18:52,320 i've been sent screenshots of code 554 00:18:50,559 --> 00:18:54,400 before where you know students like help 555 00:18:52,320 --> 00:18:56,480 this is broken and i've sent screenshots 556 00:18:54,400 --> 00:18:57,679 of code before saying help this is 557 00:18:56,480 --> 00:18:59,440 broken 558 00:18:57,679 --> 00:19:01,760 and having these type hints allow us to 559 00:18:59,440 --> 00:19:03,679 uh communicate better with our tutors 560 00:19:01,760 --> 00:19:05,679 with our students about what the code is 561 00:19:03,679 --> 00:19:07,200 doing what is it expecting what is it 562 00:19:05,679 --> 00:19:08,640 going to return to us how is it going to 563 00:19:07,200 --> 00:19:10,080 operate 564 00:19:08,640 --> 00:19:11,840 and it also allows some sort of static 565 00:19:10,080 --> 00:19:14,640 guarantees so when your student runs a 566 00:19:11,840 --> 00:19:15,840 code um and say hey my code is broken 567 00:19:14,640 --> 00:19:17,760 you can just say hey have you tried 568 00:19:15,840 --> 00:19:20,320 running your uh type checker yet have 569 00:19:17,760 --> 00:19:22,840 you done something obviously wrong um 570 00:19:20,320 --> 00:19:25,360 which happens all the time uh 571 00:19:22,840 --> 00:19:27,280 so i guess what i want to look up next 572 00:19:25,360 --> 00:19:29,600 is what's what's next we've talked about 573 00:19:27,280 --> 00:19:30,640 where type hinting is up to today um 574 00:19:29,600 --> 00:19:32,799 we've talked about some of the stuff 575 00:19:30,640 --> 00:19:35,280 that's available in 310 with the bar 576 00:19:32,799 --> 00:19:37,280 union operator but what's coming up next 577 00:19:35,280 --> 00:19:39,200 um what's coming up next is a lot of 578 00:19:37,280 --> 00:19:40,799 cool features uh but i realized my 579 00:19:39,200 --> 00:19:42,320 slides are in order and i'm so sorry for 580 00:19:40,799 --> 00:19:44,559 that uh 581 00:19:42,320 --> 00:19:46,320 there are a bunch more python type 582 00:19:44,559 --> 00:19:47,760 hinting uh 583 00:19:46,320 --> 00:19:49,120 shenanigans that i didn't really mention 584 00:19:47,760 --> 00:19:51,840 in today's talk so we are time 585 00:19:49,120 --> 00:19:53,440 constrained um for example generic types 586 00:19:51,840 --> 00:19:56,320 if you want to say this function accepts 587 00:19:53,440 --> 00:19:58,080 a type t and returns a list of type t 588 00:19:56,320 --> 00:20:00,400 you can do something like that you can 589 00:19:58,080 --> 00:20:03,200 create your own types uh you can 590 00:20:00,400 --> 00:20:05,200 pass in functions as types so a callable 591 00:20:03,200 --> 00:20:06,720 type you can say all right this this 592 00:20:05,200 --> 00:20:09,039 function should return anything that's 593 00:20:06,720 --> 00:20:12,159 iterable anything that implements the 594 00:20:09,039 --> 00:20:14,080 iterable uh sort of subclass 595 00:20:12,159 --> 00:20:15,840 and so you can do a whole bunch of 596 00:20:14,080 --> 00:20:17,200 complex things with type bits typings 597 00:20:15,840 --> 00:20:18,960 aren't just the basic stuff that i've 598 00:20:17,200 --> 00:20:21,360 shown today they are very very very 599 00:20:18,960 --> 00:20:23,120 advanced they have a lot of room to grow 600 00:20:21,360 --> 00:20:26,240 because python was not made for this in 601 00:20:23,120 --> 00:20:28,400 mind they were added on in 2015 602 00:20:26,240 --> 00:20:29,679 but they're they're very very advanced 603 00:20:28,400 --> 00:20:31,039 if you want to get into that level so 604 00:20:29,679 --> 00:20:33,039 don't think that you know your hsc 605 00:20:31,039 --> 00:20:34,320 students or the wiz kids can't use this 606 00:20:33,039 --> 00:20:35,360 this is really really good and i think 607 00:20:34,320 --> 00:20:36,640 it's actually encouraged that they 608 00:20:35,360 --> 00:20:38,640 should use this because you get better 609 00:20:36,640 --> 00:20:40,159 documentation and awareness of how the 610 00:20:38,640 --> 00:20:42,080 code runs and how they can design their 611 00:20:40,159 --> 00:20:44,480 code um 612 00:20:42,080 --> 00:20:46,400 here's the what's next slide so 613 00:20:44,480 --> 00:20:48,559 what's next so 310 hasn't been released 614 00:20:46,400 --> 00:20:50,400 yet and it has some really cool typing 615 00:20:48,559 --> 00:20:52,159 features so for example type union we 616 00:20:50,400 --> 00:20:55,280 talk about the type union 617 00:20:52,159 --> 00:20:56,559 there are two also extra things which uh 618 00:20:55,280 --> 00:20:58,640 i'm not really going to explain too much 619 00:20:56,559 --> 00:21:01,280 but essentially recursive types so for 620 00:20:58,640 --> 00:21:03,200 example if you had a type a tree and 621 00:21:01,280 --> 00:21:05,520 that tree has a field in it which is a 622 00:21:03,200 --> 00:21:07,440 tree aren't very well done in python you 623 00:21:05,520 --> 00:21:09,679 have to do a quote around the second 624 00:21:07,440 --> 00:21:11,200 type it's a bit weird if you have a look 625 00:21:09,679 --> 00:21:14,480 at it later you'll probably run into 626 00:21:11,200 --> 00:21:16,960 this problem um but they are adding a 627 00:21:14,480 --> 00:21:17,840 feature to help that be a lot better um 628 00:21:16,960 --> 00:21:19,679 so 629 00:21:17,840 --> 00:21:20,640 a quick disclaimer before we wrap it up 630 00:21:19,679 --> 00:21:22,640 um 631 00:21:20,640 --> 00:21:25,280 my pi and a lot of python 632 00:21:22,640 --> 00:21:26,400 type checkers are still in beta and 633 00:21:25,280 --> 00:21:28,400 they've been in beta for the last couple 634 00:21:26,400 --> 00:21:30,720 of years for last five years because the 635 00:21:28,400 --> 00:21:32,240 language is constantly evolving even as 636 00:21:30,720 --> 00:21:35,120 i was running this talk i was trying to 637 00:21:32,240 --> 00:21:36,720 show off the the lowercase l list syntax 638 00:21:35,120 --> 00:21:38,720 uh when i was running my error my 639 00:21:36,720 --> 00:21:40,400 programs um and the latest version of my 640 00:21:38,720 --> 00:21:42,640 pi actually didn't let me do that i had 641 00:21:40,400 --> 00:21:45,280 to jump onto the uh the nightly branch 642 00:21:42,640 --> 00:21:46,799 to have a look at using that so just be 643 00:21:45,280 --> 00:21:48,320 in mind there there are some things that 644 00:21:46,799 --> 00:21:49,360 are impossible to do with python type 645 00:21:48,320 --> 00:21:51,360 ins 646 00:21:49,360 --> 00:21:53,440 for example a very common restriction is 647 00:21:51,360 --> 00:21:55,280 higher kind of type so if you want a a 648 00:21:53,440 --> 00:21:57,679 type that has a type 649 00:21:55,280 --> 00:21:59,280 and which you probably won't need but if 650 00:21:57,679 --> 00:22:01,840 you do want to do that that is something 651 00:21:59,280 --> 00:22:04,320 you can't do um recursive types can also 652 00:22:01,840 --> 00:22:06,320 be a pain sometimes uh and a bunch of 653 00:22:04,320 --> 00:22:08,000 super complex things for the most part 654 00:22:06,320 --> 00:22:09,039 though python types are really really 655 00:22:08,000 --> 00:22:10,320 really cool 656 00:22:09,039 --> 00:22:11,600 and i'm very excited for the future i'm 657 00:22:10,320 --> 00:22:13,600 very excited for how they can 658 00:22:11,600 --> 00:22:15,039 supercharge our education how we teach 659 00:22:13,600 --> 00:22:16,799 how we talk about design first how we 660 00:22:15,039 --> 00:22:19,520 can improve documentation how we can 661 00:22:16,799 --> 00:22:20,880 improve clarity of our code um and 662 00:22:19,520 --> 00:22:21,919 overall i think they're a really great 663 00:22:20,880 --> 00:22:24,240 thing for the language and i'm very 664 00:22:21,919 --> 00:22:25,360 excited to see where the future goes um 665 00:22:24,240 --> 00:22:27,039 but yeah thank you so much for coming 666 00:22:25,360 --> 00:22:29,360 along everyone i hope you've learned 667 00:22:27,039 --> 00:22:31,280 something today um and i'll be taking 668 00:22:29,360 --> 00:22:32,559 questions for the next few minutes if 669 00:22:31,280 --> 00:22:34,960 that's okay 670 00:22:32,559 --> 00:22:34,960 nikki 671 00:22:36,960 --> 00:22:40,480 hello 672 00:22:38,640 --> 00:22:43,440 i cannot see you thank you so much thank 673 00:22:40,480 --> 00:22:46,400 you sorry the the duck maybe isn't 674 00:22:43,440 --> 00:22:47,120 adding to the uh mystique here um 675 00:22:46,400 --> 00:22:49,200 uh 676 00:22:47,120 --> 00:22:51,360 thank you so much uh we do have a few 677 00:22:49,200 --> 00:22:54,159 questions and there is time 678 00:22:51,360 --> 00:22:57,120 uh for a few more questions to be added 679 00:22:54,159 --> 00:22:59,760 as well um now the first question is 680 00:22:57,120 --> 00:23:02,320 simply a question of a duck 681 00:22:59,760 --> 00:23:03,919 uh with a question mark um how would you 682 00:23:02,320 --> 00:23:05,280 like to respond 683 00:23:03,919 --> 00:23:11,600 uh duck 684 00:23:05,280 --> 00:23:14,159 quack excellent fantastic um great um uh 685 00:23:11,600 --> 00:23:17,360 can you make my pie figure out what 686 00:23:14,159 --> 00:23:19,679 types are instead of finding them 687 00:23:17,360 --> 00:23:21,120 yourself is our next question yes you 688 00:23:19,679 --> 00:23:22,559 definitely can so my pi has some 689 00:23:21,120 --> 00:23:24,640 functions there's a particular function 690 00:23:22,559 --> 00:23:26,480 called reveal type so if you if you 691 00:23:24,640 --> 00:23:28,080 print reveal type of a variable it'll 692 00:23:26,480 --> 00:23:29,840 print out this type this variables of 693 00:23:28,080 --> 00:23:32,320 blah blah blah which is really useful 694 00:23:29,840 --> 00:23:34,720 for big complex code bases of you know a 695 00:23:32,320 --> 00:23:36,240 couple files or even even larger 696 00:23:34,720 --> 00:23:37,679 and you can just get a variable and you 697 00:23:36,240 --> 00:23:40,400 can say all right revealed what this 698 00:23:37,679 --> 00:23:41,760 type is um so yes you definitely can and 699 00:23:40,400 --> 00:23:42,960 a lot of them are built in mind to do 700 00:23:41,760 --> 00:23:44,880 that 701 00:23:42,960 --> 00:23:48,080 fantastic excellent 702 00:23:44,880 --> 00:23:50,480 um uh another question here which 703 00:23:48,080 --> 00:23:54,720 version of python will this work for you 704 00:23:50,480 --> 00:23:57,520 took about 3.9 onwards what about 3.6 705 00:23:54,720 --> 00:23:59,919 so uh lovely chart type painting was 706 00:23:57,520 --> 00:24:01,919 first implemented in three five 707 00:23:59,919 --> 00:24:03,679 three six onwards has support for type 708 00:24:01,919 --> 00:24:05,279 hinting there are some features that 709 00:24:03,679 --> 00:24:07,360 aren't there like for example if you 710 00:24:05,279 --> 00:24:10,240 really want generic types or super 711 00:24:07,360 --> 00:24:12,480 complex stuff 373839 are your are your 712 00:24:10,240 --> 00:24:14,320 best but yes it does exist in three six 713 00:24:12,480 --> 00:24:16,799 and you can do the basic stuff you may 714 00:24:14,320 --> 00:24:18,559 have to do typing dot uppercase d dict 715 00:24:16,799 --> 00:24:20,400 instead of a lowercase d dick but that's 716 00:24:18,559 --> 00:24:22,000 just semantics everything else will work 717 00:24:20,400 --> 00:24:24,000 fine 718 00:24:22,000 --> 00:24:24,880 excellent fantastic 719 00:24:24,000 --> 00:24:26,720 um 720 00:24:24,880 --> 00:24:29,200 here's a question on 721 00:24:26,720 --> 00:24:30,240 uh why would you pipe int 722 00:24:29,200 --> 00:24:33,200 to none 723 00:24:30,240 --> 00:24:34,720 um can none be implied if there's no int 724 00:24:33,200 --> 00:24:35,520 available 725 00:24:34,720 --> 00:24:37,679 uh 726 00:24:35,520 --> 00:24:39,760 so this is a really good question 727 00:24:37,679 --> 00:24:42,559 i propose you a counter question imagine 728 00:24:39,760 --> 00:24:43,840 i pass in a variable to a function um 729 00:24:42,559 --> 00:24:46,720 and for some reason that variable's 730 00:24:43,840 --> 00:24:48,960 turned to none now if i am implying now 731 00:24:46,720 --> 00:24:51,200 that my function of you know string or 732 00:24:48,960 --> 00:24:52,400 int should also take in none the type 733 00:24:51,200 --> 00:24:54,480 checker won't error it will say all 734 00:24:52,400 --> 00:24:56,080 right none is expected but often times 735 00:24:54,480 --> 00:24:58,000 you want it to error you want to say hey 736 00:24:56,080 --> 00:25:00,159 for some reason this is actually turned 737 00:24:58,000 --> 00:25:01,919 to none whereas i'm expecting a string 738 00:25:00,159 --> 00:25:04,080 or an int so you should explicitly 739 00:25:01,919 --> 00:25:05,520 specify this should also accept none if 740 00:25:04,080 --> 00:25:06,960 that's a valid use case because 741 00:25:05,520 --> 00:25:08,720 sometimes things will turn to none and 742 00:25:06,960 --> 00:25:10,159 that's not what's supposed to happen and 743 00:25:08,720 --> 00:25:12,640 you want to yell you an error and say 744 00:25:10,159 --> 00:25:14,400 hey something's gone wrong so 745 00:25:12,640 --> 00:25:15,760 that's a good question um but yes you 746 00:25:14,400 --> 00:25:17,440 should definitely be very explicit about 747 00:25:15,760 --> 00:25:19,760 those things 748 00:25:17,440 --> 00:25:20,799 that is a great answer excellent 749 00:25:19,760 --> 00:25:23,520 um 750 00:25:20,799 --> 00:25:24,720 two more questions 751 00:25:23,520 --> 00:25:26,960 um 752 00:25:24,720 --> 00:25:30,640 uh one of my favorite things about 753 00:25:26,960 --> 00:25:32,559 typing as a dev is it enables ide magic 754 00:25:30,640 --> 00:25:33,919 for navigating around your code 755 00:25:32,559 --> 00:25:35,440 there's more there's more this question 756 00:25:33,919 --> 00:25:37,919 continues it's like an essay it's 757 00:25:35,440 --> 00:25:40,000 fantastic our ide is the editor tooling 758 00:25:37,919 --> 00:25:42,000 types sorry our ids and the editor 759 00:25:40,000 --> 00:25:44,000 tooling types uh 760 00:25:42,000 --> 00:25:46,720 are they able to enable useful 761 00:25:44,000 --> 00:25:48,640 things for teaching or is the magic a 762 00:25:46,720 --> 00:25:51,679 hindrance in understanding how the 763 00:25:48,640 --> 00:25:53,679 system works what are your thoughts so a 764 00:25:51,679 --> 00:25:56,000 lot of editors will 765 00:25:53,679 --> 00:25:57,840 analyze your types as you write the code 766 00:25:56,000 --> 00:25:59,039 and so when you call the function so 767 00:25:57,840 --> 00:26:00,640 oftentimes you write the function and 768 00:25:59,039 --> 00:26:02,480 use it later right so you write the 769 00:26:00,640 --> 00:26:04,559 function you go to call the function and 770 00:26:02,480 --> 00:26:06,000 it will actually hover in your preview 771 00:26:04,559 --> 00:26:07,360 saying this function expects two 772 00:26:06,000 --> 00:26:08,720 arguments the first argument between 773 00:26:07,360 --> 00:26:10,880 integer blur and the second argument 774 00:26:08,720 --> 00:26:13,039 should be of string blah 775 00:26:10,880 --> 00:26:14,640 and so oftentimes it won't do the magic 776 00:26:13,039 --> 00:26:16,640 of checking if you pass in a variable 777 00:26:14,640 --> 00:26:19,919 blah blah so it won't actually hinder 778 00:26:16,640 --> 00:26:21,600 you that sense um i think that editors 779 00:26:19,919 --> 00:26:23,919 can be super super useful when it comes 780 00:26:21,600 --> 00:26:26,320 to hinting because they will enable that 781 00:26:23,919 --> 00:26:28,400 magic feature and so 782 00:26:26,320 --> 00:26:29,360 as to whether it's a it's too magic 783 00:26:28,400 --> 00:26:31,600 that's a question that gets asked 784 00:26:29,360 --> 00:26:33,440 sometimes like i don't want my students 785 00:26:31,600 --> 00:26:35,279 to have this magical pop-over of this is 786 00:26:33,440 --> 00:26:37,440 what it should expect i want to fail and 787 00:26:35,279 --> 00:26:40,240 learn the hard way um which is which is 788 00:26:37,440 --> 00:26:41,919 a valid strategy that's totally okay um 789 00:26:40,240 --> 00:26:42,799 but i think you can disable those if 790 00:26:41,919 --> 00:26:45,039 that's something you're interested in 791 00:26:42,799 --> 00:26:46,320 doing um so i'm not entirely sure if 792 00:26:45,039 --> 00:26:48,000 that answers your question feel free to 793 00:26:46,320 --> 00:26:50,640 ask me more on the hallway channel 794 00:26:48,000 --> 00:26:52,400 afterwards um but yes they're they're 795 00:26:50,640 --> 00:26:54,960 super helpful five years 796 00:26:52,400 --> 00:26:57,360 i i think i have to agree that those 797 00:26:54,960 --> 00:26:58,720 that special magic can be ridiculously 798 00:26:57,360 --> 00:27:00,799 useful when 799 00:26:58,720 --> 00:27:02,640 um helping students 800 00:27:00,799 --> 00:27:04,159 gain that sense of confidence like oh 801 00:27:02,640 --> 00:27:06,159 wow i can actually do this this isn't 802 00:27:04,159 --> 00:27:08,559 just in fact exactly almost ironically 803 00:27:06,159 --> 00:27:11,360 this isn't just magic i can i can i can 804 00:27:08,559 --> 00:27:13,840 use the magic um but then it also 805 00:27:11,360 --> 00:27:14,880 um is handy to to occasionally 806 00:27:13,840 --> 00:27:18,080 um 807 00:27:14,880 --> 00:27:19,120 to feel like uh that 808 00:27:18,080 --> 00:27:20,080 that they understand they really 809 00:27:19,120 --> 00:27:21,039 understand what's going on under the 810 00:27:20,080 --> 00:27:22,000 hood yeah 811 00:27:21,039 --> 00:27:24,880 yeah so 812 00:27:22,000 --> 00:27:28,480 everything's optional which is great 813 00:27:24,880 --> 00:27:31,279 um one last question um unless there's 814 00:27:28,480 --> 00:27:37,039 another one that comes in now uh could 815 00:27:31,279 --> 00:27:39,120 we run my pie as part of the gitlab ci 816 00:27:37,039 --> 00:27:41,039 i am almost certain that is a 817 00:27:39,120 --> 00:27:43,120 possibility i would be very surprised if 818 00:27:41,039 --> 00:27:45,679 gitlab has no way to 819 00:27:43,120 --> 00:27:47,200 enable some static type checking so i'm 820 00:27:45,679 --> 00:27:48,720 going to say 95 821 00:27:47,200 --> 00:27:50,320 yes 822 00:27:48,720 --> 00:27:52,799 and leave that last five percent as an 823 00:27:50,320 --> 00:27:54,399 exercise to the homework for the viewer 824 00:27:52,799 --> 00:27:56,159 google it i'm guaranteed there's 825 00:27:54,399 --> 00:27:57,200 something there yeah 826 00:27:56,159 --> 00:28:00,960 excellent 827 00:27:57,200 --> 00:28:03,520 well those were the questions um 828 00:28:00,960 --> 00:28:04,320 that our fantastic audience have come up 829 00:28:03,520 --> 00:28:06,880 with 830 00:28:04,320 --> 00:28:09,279 um so far and we are 831 00:28:06,880 --> 00:28:12,320 pretty much at time 832 00:28:09,279 --> 00:28:16,720 so i am going to invite you 833 00:28:12,320 --> 00:28:18,080 uh dear viewer and you sray um to join 834 00:28:16,720 --> 00:28:19,440 us in the 835 00:28:18,080 --> 00:28:22,240 hallway 836 00:28:19,440 --> 00:28:24,640 in the education hallway track um now 837 00:28:22,240 --> 00:28:28,480 byo beveridges please 838 00:28:24,640 --> 00:28:30,000 um and we'll have a good old chat about 839 00:28:28,480 --> 00:28:31,039 ducks and type checking and all sorts of 840 00:28:30,000 --> 00:28:34,320 things 841 00:28:31,039 --> 00:28:35,760 before you all rejoin us here for our 842 00:28:34,320 --> 00:28:38,559 next talk 843 00:28:35,760 --> 00:28:41,440 uh by andre roberge uh entitled it 844 00:28:38,559 --> 00:28:41,440 doesn't work 845 00:28:42,320 --> 00:28:45,600 i just love it i'm not sure what it is 846 00:28:44,159 --> 00:28:48,000 but it doesn't work it definitely 847 00:28:45,600 --> 00:28:52,000 doesn't work and uh you'll have to come 848 00:28:48,000 --> 00:28:53,760 back uh in 15 minutes to find out more 849 00:28:52,000 --> 00:28:56,000 but trey thank you so very very very 850 00:28:53,760 --> 00:28:57,840 much um that talk really resonated with 851 00:28:56,000 --> 00:29:00,399 that audience and resonated with me it 852 00:28:57,840 --> 00:29:01,360 resonated with my hundreds of ducks 853 00:29:00,399 --> 00:29:02,559 and 854 00:29:01,360 --> 00:29:06,200 thank you 855 00:29:02,559 --> 00:29:06,200 thank you for having me 856 00:29:13,600 --> 00:29:15,679 you