1 00:00:00,420 --> 00:00:05,910 [Music] 2 00:00:10,240 --> 00:00:13,920 Good afternoon everyone and welcome to 3 00:00:12,320 --> 00:00:18,400 our second talk for our afternoon 4 00:00:13,920 --> 00:00:21,039 session here at PyCon AU 2025. I would 5 00:00:18,400 --> 00:00:23,039 like to introduce Sarah Reichelt. Sarah 6 00:00:21,039 --> 00:00:26,080 has been programming since before most 7 00:00:23,039 --> 00:00:28,240 PyCon AU users were born. 8 00:00:26,080 --> 00:00:30,560 And while she may not consider herself a 9 00:00:28,240 --> 00:00:32,960 teacher, she literally has written the 10 00:00:30,560 --> 00:00:35,840 book on Mac OS Development for Mac OS 11 00:00:32,960 --> 00:00:37,680 newbies. Well, four books actually. 12 00:00:35,840 --> 00:00:40,480 Sarah's passion is trying to get more 13 00:00:37,680 --> 00:00:42,879 people writing apps for Mac itself. So 14 00:00:40,480 --> 00:00:45,920 her latest book, Escape from Tutorial 15 00:00:42,879 --> 00:00:48,960 Hell, helps people get over that next 16 00:00:45,920 --> 00:00:51,760 hurdle from beginner code to developer 17 00:00:48,960 --> 00:00:53,770 in your own right. Sarah Raichel, 18 00:00:51,760 --> 00:00:59,280 thank you very much. 19 00:00:53,770 --> 00:01:01,440 [Applause] 20 00:00:59,280 --> 00:01:03,199 Oh, good afternoon and thank you for 21 00:01:01,440 --> 00:01:05,760 coming to my talk. 22 00:01:03,199 --> 00:01:07,760 Um, I have to say, but I feel a bit of a 23 00:01:05,760 --> 00:01:10,479 fraud standing up in front of you Python 24 00:01:07,760 --> 00:01:12,640 people because I'm not much of a Python 25 00:01:10,479 --> 00:01:15,760 person. In fact, I don't really use 26 00:01:12,640 --> 00:01:19,119 Python very much except every December 27 00:01:15,760 --> 00:01:20,799 when I struggle with Advent of Code. 28 00:01:19,119 --> 00:01:22,880 But give me a few minutes to explain 29 00:01:20,799 --> 00:01:25,439 what I do and then you'll understand why 30 00:01:22,880 --> 00:01:28,159 I'm here. 31 00:01:25,439 --> 00:01:31,200 So, in my day job, I grow yogurt-like 32 00:01:28,159 --> 00:01:34,479 bacteria for use in making cattle feed. 33 00:01:31,200 --> 00:01:36,640 And among my roles in that job, I am in 34 00:01:34,479 --> 00:01:39,600 charge of the process control software, 35 00:01:36,640 --> 00:01:41,040 which is mostly JavaScript, no.js, but 36 00:01:39,600 --> 00:01:43,040 it does have a little bit of Python 37 00:01:41,040 --> 00:01:45,280 involved. 38 00:01:43,040 --> 00:01:48,880 As with any agricultural job, this is 39 00:01:45,280 --> 00:01:51,360 seasonal, so I do other things. 40 00:01:48,880 --> 00:01:54,000 I do consulting programming, mainly web 41 00:01:51,360 --> 00:01:56,320 apps. If any of you have ever bought any 42 00:01:54,000 --> 00:01:57,920 furniture at King Living, you will have 43 00:01:56,320 --> 00:02:00,920 seen the showroom staff using my 44 00:01:57,920 --> 00:02:00,920 software. 45 00:02:01,360 --> 00:02:06,159 I also write apps for Mac and for iOS 46 00:02:04,240 --> 00:02:07,920 using Swift. 47 00:02:06,159 --> 00:02:09,759 So, I'm not really a full stack 48 00:02:07,920 --> 00:02:12,759 developer. I'm more an untidy heap 49 00:02:09,759 --> 00:02:12,759 developer. 50 00:02:13,680 --> 00:02:18,000 Along the way, I learned that I really 51 00:02:15,520 --> 00:02:19,920 like writing books. So, this started 52 00:02:18,000 --> 00:02:21,920 when I was asked to contribute two 53 00:02:19,920 --> 00:02:23,680 chapters to an existing book on Swift 54 00:02:21,920 --> 00:02:25,440 UI. 55 00:02:23,680 --> 00:02:27,760 And then I wrote two more books 56 00:02:25,440 --> 00:02:29,440 specifically about Mac OS app 57 00:02:27,760 --> 00:02:31,840 development. 58 00:02:29,440 --> 00:02:33,760 One's for total beginners and the other 59 00:02:31,840 --> 00:02:36,760 is for people coming from iOS 60 00:02:33,760 --> 00:02:36,760 development. 61 00:02:37,200 --> 00:02:41,200 My most recent book is called Escape 62 00:02:39,200 --> 00:02:44,480 from Tutorial Hell. And that's why I'm 63 00:02:41,200 --> 00:02:47,440 here today. The examples in the book all 64 00:02:44,480 --> 00:02:49,360 use Swift, but the concepts are 65 00:02:47,440 --> 00:02:53,400 universal and can be applied to Python 66 00:02:49,360 --> 00:02:53,400 or to any programming language. 67 00:02:54,800 --> 00:02:59,519 So what's the problem? 68 00:02:57,200 --> 00:03:01,599 Well, you learn to code by learning the 69 00:02:59,519 --> 00:03:03,760 building blocks. You learn how to use 70 00:03:01,599 --> 00:03:06,800 variables, how to use loops, how to 71 00:03:03,760 --> 00:03:08,640 write functions, how to write classes. 72 00:03:06,800 --> 00:03:11,280 But then you get out into the real world 73 00:03:08,640 --> 00:03:13,599 and things are a bit different. 74 00:03:11,280 --> 00:03:15,760 You have to work on a complete project 75 00:03:13,599 --> 00:03:20,360 and the gap between the building blocks 76 00:03:15,760 --> 00:03:20,360 and the projects just seems enormous. 77 00:03:20,879 --> 00:03:24,400 It's like one of those websites that 78 00:03:22,560 --> 00:03:26,239 tries to teach you how to draw an owl. 79 00:03:24,400 --> 00:03:28,319 you know, draw a circle, draw another 80 00:03:26,239 --> 00:03:29,840 circle, and now draw the rest of the 81 00:03:28,319 --> 00:03:31,360 owl, 82 00:03:29,840 --> 00:03:32,640 but you're stuck in tutorial hell 83 00:03:31,360 --> 00:03:36,200 because you don't know how to draw the 84 00:03:32,640 --> 00:03:36,200 rest of the owl. 85 00:03:36,879 --> 00:03:40,799 So, in this talk, my goal is to provide 86 00:03:38,720 --> 00:03:43,920 you with some tools for making that jump 87 00:03:40,799 --> 00:03:45,760 from tutorials to real life projects. 88 00:03:43,920 --> 00:03:48,959 And I have four main steps I'm going to 89 00:03:45,760 --> 00:03:52,480 follow along the way. project design, 90 00:03:48,959 --> 00:03:56,920 project structure, documentation and of 91 00:03:52,480 --> 00:03:56,920 course we got to discuss using AI. 92 00:03:57,760 --> 00:04:02,799 So the first is project design. 93 00:04:00,640 --> 00:04:05,439 Now we all love coding. So it's very 94 00:04:02,799 --> 00:04:07,760 tempting to start by coding but that's 95 00:04:05,439 --> 00:04:10,720 the wrong place to start. Start by 96 00:04:07,760 --> 00:04:13,439 thinking 97 00:04:10,720 --> 00:04:14,799 firstly the highlevel decisions. Well 98 00:04:13,439 --> 00:04:17,759 first what project are you going to 99 00:04:14,799 --> 00:04:19,919 write? Then what platforms is it going 100 00:04:17,759 --> 00:04:21,600 to support? What language are you going 101 00:04:19,919 --> 00:04:24,000 to use? What frameworks are you going to 102 00:04:21,600 --> 00:04:26,240 import? And does it have a user 103 00:04:24,000 --> 00:04:29,479 interface? If so, what's that going to 104 00:04:26,240 --> 00:04:29,479 look like? 105 00:04:30,000 --> 00:04:33,440 So, choose your project options. And for 106 00:04:32,080 --> 00:04:35,600 the rest of this talk, I'm going to 107 00:04:33,440 --> 00:04:38,880 imagine that I've been asked to write 108 00:04:35,600 --> 00:04:42,400 the backend for an online store. 109 00:04:38,880 --> 00:04:44,320 So, the platform is any web server. 110 00:04:42,400 --> 00:04:46,960 Given my audience today, the language 111 00:04:44,320 --> 00:04:49,280 obviously will be Python. 112 00:04:46,960 --> 00:04:52,639 And for the frameworks, we'll choose a 113 00:04:49,280 --> 00:04:54,560 server and we'll choose a database. 114 00:04:52,639 --> 00:04:56,960 Now, this is a backend, so there's no 115 00:04:54,560 --> 00:04:59,040 guey, but if there was, I'd stop at this 116 00:04:56,960 --> 00:05:01,199 point and sketch it out. Doesn't matter 117 00:04:59,040 --> 00:05:03,280 how rough your sketches are. That 118 00:05:01,199 --> 00:05:07,320 visualization will really help you 119 00:05:03,280 --> 00:05:07,320 design the rest of the project. 120 00:05:07,759 --> 00:05:11,199 So now, what are the major functions of 121 00:05:09,600 --> 00:05:14,000 our project? I'm going to start breaking 122 00:05:11,199 --> 00:05:15,919 it down into chunks. So, we start off, 123 00:05:14,000 --> 00:05:17,600 we've got the server component, we've 124 00:05:15,919 --> 00:05:19,520 got the database component, and then 125 00:05:17,600 --> 00:05:21,520 we've got the APIs for communicating 126 00:05:19,520 --> 00:05:25,199 with the front end. 127 00:05:21,520 --> 00:05:27,840 Let's keep going. The APIs, the three 128 00:05:25,199 --> 00:05:29,280 main blocks of APIs, dealing with users, 129 00:05:27,840 --> 00:05:32,240 dealing with the products, and dealing 130 00:05:29,280 --> 00:05:34,160 with orders. So, already we've taken the 131 00:05:32,240 --> 00:05:36,800 monolithic project and we've broken it 132 00:05:34,160 --> 00:05:38,400 down into chunks. Now, if you're an 133 00:05:36,800 --> 00:05:40,720 experienced developer, you've written 134 00:05:38,400 --> 00:05:42,720 this sort of project before, that may be 135 00:05:40,720 --> 00:05:44,479 enough for you. You may now be able to 136 00:05:42,720 --> 00:05:47,919 look at each of these chunks and think, 137 00:05:44,479 --> 00:05:49,919 I can visualize how to do that. 138 00:05:47,919 --> 00:05:52,919 But that's fine if you can't just keep 139 00:05:49,919 --> 00:05:52,919 subdividing. 140 00:05:52,960 --> 00:05:57,520 Let's go into the database section. So, 141 00:05:55,520 --> 00:05:59,360 we need to be able to create the 142 00:05:57,520 --> 00:06:01,520 database. We need to be able to add the 143 00:05:59,360 --> 00:06:04,080 tables. We need to be able to save data. 144 00:06:01,520 --> 00:06:06,000 We need to be able to query the data. 145 00:06:04,080 --> 00:06:08,720 So the goal here is just to keep 146 00:06:06,000 --> 00:06:13,240 subdividing the tasks until you feel 147 00:06:08,720 --> 00:06:13,240 comfortable with each of those tasks. 148 00:06:14,000 --> 00:06:19,759 This next step may surprise you. Step 149 00:06:16,639 --> 00:06:21,360 away from your computer. Go for a walk. 150 00:06:19,759 --> 00:06:24,479 Have something to eat. Get a good 151 00:06:21,360 --> 00:06:26,960 night's sleep. I guarantee you when you 152 00:06:24,479 --> 00:06:30,759 come back tomorrow and reread your plan, 153 00:06:26,960 --> 00:06:30,759 it will become better. 154 00:06:33,840 --> 00:06:37,680 So this is not a coding talk. So I'm not 155 00:06:35,840 --> 00:06:38,960 going to talk about the code, but I am 156 00:06:37,680 --> 00:06:41,759 going to talk about how you structure 157 00:06:38,960 --> 00:06:43,919 the code. 158 00:06:41,759 --> 00:06:45,919 When we're learning to program, the code 159 00:06:43,919 --> 00:06:47,759 that we write is one-off code. We write 160 00:06:45,919 --> 00:06:51,039 it to demonstrate a point or we write it 161 00:06:47,759 --> 00:06:53,280 to um complete an assignment and then 162 00:06:51,039 --> 00:06:55,440 it's gone. 163 00:06:53,280 --> 00:06:57,680 In the real world, you work on a project 164 00:06:55,440 --> 00:06:59,840 that could last for years. So you have 165 00:06:57,680 --> 00:07:03,120 to write code that you or another 166 00:06:59,840 --> 00:07:05,280 developer can navigate and can read. 167 00:07:03,120 --> 00:07:08,280 Then you have a project that you can 168 00:07:05,280 --> 00:07:08,280 maintain. 169 00:07:09,759 --> 00:07:14,400 The main aid to navigation is files and 170 00:07:12,240 --> 00:07:16,720 folders. Divide your code up into 171 00:07:14,400 --> 00:07:18,639 separate files and put these files into 172 00:07:16,720 --> 00:07:22,080 folders so that you can find what you're 173 00:07:18,639 --> 00:07:23,840 looking for. In our store example, we 174 00:07:22,080 --> 00:07:27,039 have orders to process. So I have an 175 00:07:23,840 --> 00:07:29,680 orders folder. Inside the orders folder, 176 00:07:27,039 --> 00:07:31,919 I have a payments folder. And inside the 177 00:07:29,680 --> 00:07:34,080 payments folder, I have a file for each 178 00:07:31,919 --> 00:07:37,120 payment method. 179 00:07:34,080 --> 00:07:40,080 Now, if PayPal changes their API, I can 180 00:07:37,120 --> 00:07:41,759 find where that code is and fix it. Or 181 00:07:40,080 --> 00:07:43,599 if we decide to add a new payment 182 00:07:41,759 --> 00:07:45,280 method, I know where that file should 183 00:07:43,599 --> 00:07:47,919 go. 184 00:07:45,280 --> 00:07:52,599 Basically, each file should only contain 185 00:07:47,919 --> 00:07:52,599 code responsible for one task. 186 00:07:55,680 --> 00:07:59,440 We need the code to be readable so that 187 00:07:57,680 --> 00:08:01,440 when we come back to it, we can work out 188 00:07:59,440 --> 00:08:03,599 what it does. 189 00:08:01,440 --> 00:08:06,000 Martin Fowler in his book on refactoring 190 00:08:03,599 --> 00:08:08,000 wrote, "Any fool can write code that a 191 00:08:06,000 --> 00:08:10,080 computer can understand. Good 192 00:08:08,000 --> 00:08:11,919 programmers write code that humans can 193 00:08:10,080 --> 00:08:14,160 understand." 194 00:08:11,919 --> 00:08:19,000 Now, I think he may be overestimating 195 00:08:14,160 --> 00:08:19,000 fools, but he has a point. 196 00:08:20,000 --> 00:08:25,919 Don't write clever code. Write readable 197 00:08:22,960 --> 00:08:28,000 code. Complex oneliners look really 198 00:08:25,919 --> 00:08:29,680 impressive, but they'll waste your time 199 00:08:28,000 --> 00:08:32,000 later when you're coming back to try and 200 00:08:29,680 --> 00:08:34,399 find out what they do. 201 00:08:32,000 --> 00:08:36,959 Keep your functions short. My rule of 202 00:08:34,399 --> 00:08:38,640 thumb is that if a function extends over 203 00:08:36,959 --> 00:08:40,560 more than the screen, it's got to be 204 00:08:38,640 --> 00:08:42,320 split up. I never want to scroll to read 205 00:08:40,560 --> 00:08:44,240 a function. 206 00:08:42,320 --> 00:08:46,000 And finally, use a llinter or a 207 00:08:44,240 --> 00:08:48,160 formatter to keep your code style 208 00:08:46,000 --> 00:08:51,160 consistent. That'll really increase 209 00:08:48,160 --> 00:08:51,160 readability. 210 00:08:53,440 --> 00:08:58,160 Next up, naming. 211 00:08:56,480 --> 00:09:00,399 And to paraphrase a joke that goes 212 00:08:58,160 --> 00:09:02,560 around the internet, the hardest problem 213 00:09:00,399 --> 00:09:05,600 in computer science is naming things and 214 00:09:02,560 --> 00:09:08,000 off by one errors. 215 00:09:05,600 --> 00:09:09,120 So when you're naming things, you have 216 00:09:08,000 --> 00:09:11,040 to remember that you're going to be 217 00:09:09,120 --> 00:09:13,440 reading this code maybe in a year's 218 00:09:11,040 --> 00:09:15,600 time, maybe in five years time. And 219 00:09:13,440 --> 00:09:17,600 while it may seem very efficient now to 220 00:09:15,600 --> 00:09:20,320 use a short name that saves you a few 221 00:09:17,600 --> 00:09:22,080 keystrokes, it's very inefficient later 222 00:09:20,320 --> 00:09:25,080 when you're trying to remember what it 223 00:09:22,080 --> 00:09:25,080 does. 224 00:09:25,440 --> 00:09:29,279 Remember back in school when you learned 225 00:09:27,040 --> 00:09:32,080 grammar? Or am I the only one old enough 226 00:09:29,279 --> 00:09:34,800 to have learned grammar? 227 00:09:32,080 --> 00:09:38,080 Those rules can apply to naming, too. 228 00:09:34,800 --> 00:09:41,200 Variables are nouns. Username, total 229 00:09:38,080 --> 00:09:44,320 cost, product size. 230 00:09:41,200 --> 00:09:48,880 functions start with verbs. Doing words 231 00:09:44,320 --> 00:09:50,560 like process order, save password. 232 00:09:48,880 --> 00:09:53,279 Since code editors will all help you 233 00:09:50,560 --> 00:09:55,519 autocomplete, there's no excuse for not 234 00:09:53,279 --> 00:09:58,399 using long and descriptive names to make 235 00:09:55,519 --> 00:10:01,920 your code more readable. 236 00:09:58,399 --> 00:10:04,320 Here's a terrible example. 237 00:10:01,920 --> 00:10:06,080 Now, it may have been quick to write 238 00:10:04,320 --> 00:10:07,839 that, but imagine coming back to that in 239 00:10:06,080 --> 00:10:09,040 a year and trying to work out what it 240 00:10:07,839 --> 00:10:10,560 does. 241 00:10:09,040 --> 00:10:13,360 I mean, the only thing I can say in its 242 00:10:10,560 --> 00:10:16,360 favor is it doesn't use fu as a variable 243 00:10:13,360 --> 00:10:16,360 name. 244 00:10:16,800 --> 00:10:21,680 Now, here's exactly the same function 245 00:10:19,200 --> 00:10:24,399 only with good names. 246 00:10:21,680 --> 00:10:25,920 And each line reads practically like a 247 00:10:24,399 --> 00:10:27,360 sentence. 248 00:10:25,920 --> 00:10:28,640 So, which one would you rather be 249 00:10:27,360 --> 00:10:31,959 looking at when you're reading somebody 250 00:10:28,640 --> 00:10:31,959 else's code? 251 00:10:32,240 --> 00:10:37,279 The other thing to remember about naming 252 00:10:34,320 --> 00:10:39,360 is that it's not a one-off task. It's 253 00:10:37,279 --> 00:10:42,399 something that is a live part of your 254 00:10:39,360 --> 00:10:44,480 code you've got to keep working on. If 255 00:10:42,399 --> 00:10:47,120 you come back to your project and 256 00:10:44,480 --> 00:10:48,800 something is hard to understand, think 257 00:10:47,120 --> 00:10:51,839 about how you can rename it to make it 258 00:10:48,800 --> 00:10:54,079 easier to understand next time. And if 259 00:10:51,839 --> 00:10:57,800 what a function does changes, change it 260 00:10:54,079 --> 00:10:57,800 in the name to match. 261 00:10:59,680 --> 00:11:04,560 Still on project structure, one file 262 00:11:02,079 --> 00:11:07,200 that I add to all my projects is a notes 263 00:11:04,560 --> 00:11:10,320 file. I use markdown, but it can be text 264 00:11:07,200 --> 00:11:12,959 or anything you like. I work on multiple 265 00:11:10,320 --> 00:11:16,000 projects at a time. So, this is to help 266 00:11:12,959 --> 00:11:17,680 me get back to every project. So, I'll 267 00:11:16,000 --> 00:11:20,000 write what I'm working on now or what 268 00:11:17,680 --> 00:11:22,959 I'm going to work on next. I'll list the 269 00:11:20,000 --> 00:11:25,200 known bugs. I'll say my future plans, 270 00:11:22,959 --> 00:11:27,279 you know, for version two, three, and 271 00:11:25,200 --> 00:11:29,920 I'll give links to anything that I think 272 00:11:27,279 --> 00:11:32,240 might help me. Just whatever I think I 273 00:11:29,920 --> 00:11:36,279 need to get back up to speed on that 274 00:11:32,240 --> 00:11:36,279 project as fast as possible. 275 00:11:36,880 --> 00:11:41,760 And finally, as far as project structure 276 00:11:39,040 --> 00:11:44,480 is concerned, source control, which 277 00:11:41,760 --> 00:11:47,600 these days basically means git. 278 00:11:44,480 --> 00:11:49,920 So git is a tool that has saved me many, 279 00:11:47,600 --> 00:11:52,399 many times. It's like a magic time 280 00:11:49,920 --> 00:11:55,279 machine. And if you save snapshots of 281 00:11:52,399 --> 00:11:58,399 your code, you can always revert when 282 00:11:55,279 --> 00:12:01,760 you've totally broken everything. 283 00:11:58,399 --> 00:12:04,880 And if you connect your code to one of 284 00:12:01,760 --> 00:12:07,360 the big providers, GitHub, Gitbucket, 285 00:12:04,880 --> 00:12:09,360 Bitbucket, GitLab, whatever, then you 286 00:12:07,360 --> 00:12:11,040 get an off-site backup and you get the 287 00:12:09,360 --> 00:12:14,079 ability to run your code on any 288 00:12:11,040 --> 00:12:16,160 computer, which is really useful. So, if 289 00:12:14,079 --> 00:12:17,760 you're not familiar with using Git, this 290 00:12:16,160 --> 00:12:21,399 is one place where I recommend you do go 291 00:12:17,760 --> 00:12:21,399 back and do a tutorial. 292 00:12:23,440 --> 00:12:28,079 The next step on my escape route is 293 00:12:25,760 --> 00:12:30,560 documentation. And this may sound 294 00:12:28,079 --> 00:12:32,880 obvious or boring, but learning how to 295 00:12:30,560 --> 00:12:36,079 read and write documentation effectively 296 00:12:32,880 --> 00:12:38,639 is a vital skill. 297 00:12:36,079 --> 00:12:40,480 Firstly, every programming language has 298 00:12:38,639 --> 00:12:42,800 its own documentation with its own 299 00:12:40,480 --> 00:12:45,360 style. So, you need to spend some time 300 00:12:42,800 --> 00:12:47,920 learning your way around this. 301 00:12:45,360 --> 00:12:49,760 Learn how to navigate, how to set the 302 00:12:47,920 --> 00:12:52,720 version number that you're working with, 303 00:12:49,760 --> 00:12:54,880 how to follow the links, how to search. 304 00:12:52,720 --> 00:12:57,120 If you spend some time early in your 305 00:12:54,880 --> 00:12:59,120 project to learn how the documentation 306 00:12:57,120 --> 00:13:02,079 works, you really save time in the long 307 00:12:59,120 --> 00:13:03,760 run. 308 00:13:02,079 --> 00:13:05,360 Depending on your editor or its 309 00:13:03,760 --> 00:13:07,600 extensions, you may be able to have some 310 00:13:05,360 --> 00:13:09,760 of this documentation locally as well. 311 00:13:07,600 --> 00:13:12,800 And that's really good because you can 312 00:13:09,760 --> 00:13:15,200 see the help without having to interrupt 313 00:13:12,800 --> 00:13:16,959 your workflow to get out into the 314 00:13:15,200 --> 00:13:21,320 website and look for it. So, if that's a 315 00:13:16,959 --> 00:13:21,320 possibility, enable it. 316 00:13:22,399 --> 00:13:26,399 The other aspect of documentation is 317 00:13:24,160 --> 00:13:29,040 what you write. And this will mainly be 318 00:13:26,399 --> 00:13:31,279 in the form of comments. Now, some 319 00:13:29,040 --> 00:13:32,800 people say if you use good names, the 320 00:13:31,279 --> 00:13:35,200 code is self-documenting and you don't 321 00:13:32,800 --> 00:13:36,480 need to add comments. Nope. There's a 322 00:13:35,200 --> 00:13:40,519 certain amount of truth in that, but 323 00:13:36,480 --> 00:13:40,519 comments can add more value. 324 00:13:40,639 --> 00:13:45,600 Here's an example of a function with bad 325 00:13:42,959 --> 00:13:48,240 and unnecessary comments. 326 00:13:45,600 --> 00:13:51,200 Basically, every comment is just saying 327 00:13:48,240 --> 00:13:52,800 what the next line does. But the lines 328 00:13:51,200 --> 00:13:55,360 have good enough naming, so that's 329 00:13:52,800 --> 00:13:56,880 useless. So, in fact, all these comments 330 00:13:55,360 --> 00:14:01,560 are actually making the code less 331 00:13:56,880 --> 00:14:01,560 readable by adding noise. 332 00:14:02,079 --> 00:14:05,360 This is the same function, and I've 333 00:14:03,920 --> 00:14:08,639 stripped out the boring, useless 334 00:14:05,360 --> 00:14:10,800 comments, and I've added some new ones. 335 00:14:08,639 --> 00:14:13,519 Firstly, we have a to-do reminding me of 336 00:14:10,800 --> 00:14:16,160 an optimization that I want to do. and a 337 00:14:13,519 --> 00:14:19,600 lot of editors can format or gather 338 00:14:16,160 --> 00:14:21,040 to-dos or fix me in a useful way. So you 339 00:14:19,600 --> 00:14:23,360 that's a comment that's used as a 340 00:14:21,040 --> 00:14:25,600 bookmark. 341 00:14:23,360 --> 00:14:28,399 My other comment is one that's giving 342 00:14:25,600 --> 00:14:30,560 more information about how the returned 343 00:14:28,399 --> 00:14:33,680 data is structured. 344 00:14:30,560 --> 00:14:36,079 So don't comment the what, comment the 345 00:14:33,680 --> 00:14:39,079 how or the why, or use comments as 346 00:14:36,079 --> 00:14:39,079 bookmarks. 347 00:14:40,880 --> 00:14:45,519 My final recommendation for 348 00:14:42,320 --> 00:14:47,440 documentation is to save code snippets. 349 00:14:45,519 --> 00:14:50,480 You can use a dedicated snippets manager 350 00:14:47,440 --> 00:14:52,320 or a text file or anything you like. I 351 00:14:50,480 --> 00:14:54,079 don't actually recommend using a bunch 352 00:14:52,320 --> 00:14:56,800 of sticky notes, but that just seemed 353 00:14:54,079 --> 00:14:58,399 like a good graphic to use. 354 00:14:56,800 --> 00:15:00,480 It's so frustrating when you know you've 355 00:14:58,399 --> 00:15:02,880 seen a way to do something and you can't 356 00:15:00,480 --> 00:15:04,399 remember what it is. So, whenever I see 357 00:15:02,880 --> 00:15:06,240 something cool online that I think one 358 00:15:04,399 --> 00:15:08,959 day I'm going to need that, it goes into 359 00:15:06,240 --> 00:15:11,760 my snippets manager. And if I've spent 360 00:15:08,959 --> 00:15:13,600 ages researching how to do something, it 361 00:15:11,760 --> 00:15:17,560 goes into my snippets manager so I don't 362 00:15:13,600 --> 00:15:17,560 have to do that research again. 363 00:15:18,560 --> 00:15:23,839 Okay, finally we get to AI, which you 364 00:15:21,279 --> 00:15:26,959 know about half the talks here have been 365 00:15:23,839 --> 00:15:30,160 about AI. So I'm not going to go into 366 00:15:26,959 --> 00:15:32,000 any details of why you should or whether 367 00:15:30,160 --> 00:15:36,920 you should. I'm going to tell you how I 368 00:15:32,000 --> 00:15:36,920 use AI and how I find it helps me. 369 00:15:37,040 --> 00:15:41,920 I started using GitHub Copilot about two 370 00:15:39,440 --> 00:15:46,240 years ago. And at first I just used it 371 00:15:41,920 --> 00:15:47,839 like a super code completer. So we're 372 00:15:46,240 --> 00:15:49,759 all used to the code completion where 373 00:15:47,839 --> 00:15:53,040 you start typing a variable name and it 374 00:15:49,759 --> 00:15:54,720 fills it in for you. But GitHub Copilot 375 00:15:53,040 --> 00:15:56,480 would go further than that. It would 376 00:15:54,720 --> 00:15:59,440 finish the line or it would even suggest 377 00:15:56,480 --> 00:16:01,519 another line. If you use good names for 378 00:15:59,440 --> 00:16:04,079 your functions and variables, copilot 379 00:16:01,519 --> 00:16:06,560 can extrapolate from those to suggest 380 00:16:04,079 --> 00:16:10,600 more code, which has the added benefit 381 00:16:06,560 --> 00:16:10,600 of encouraging good naming. 382 00:16:10,959 --> 00:16:15,040 AI is great for explaining code that you 383 00:16:13,120 --> 00:16:17,279 don't understand. 384 00:16:15,040 --> 00:16:19,759 I had a Ruby script that was generating 385 00:16:17,279 --> 00:16:22,639 all the different formats of my book, 386 00:16:19,759 --> 00:16:24,800 and I don't do Ruby, so I didn't know 387 00:16:22,639 --> 00:16:27,040 what I was doing. 388 00:16:24,800 --> 00:16:28,639 So I asked Copilot to explain it to me 389 00:16:27,040 --> 00:16:29,920 and it took me line by line through the 390 00:16:28,639 --> 00:16:34,320 code and showed me what each of the 391 00:16:29,920 --> 00:16:37,680 lines was doing. It's really good. 392 00:16:34,320 --> 00:16:39,680 Another use is reminding you of syntax. 393 00:16:37,680 --> 00:16:41,519 Now when working with JavaScript arrays, 394 00:16:39,680 --> 00:16:44,000 I can never remember all the different 395 00:16:41,519 --> 00:16:47,279 array functions. Is it splice or split 396 00:16:44,000 --> 00:16:49,600 or slice or I don't know. So I'll write 397 00:16:47,279 --> 00:16:52,000 a comment, you know, get the last three 398 00:16:49,600 --> 00:16:54,639 elements of this array or delete element 399 00:16:52,000 --> 00:16:57,440 four of this array. And when I press 400 00:16:54,639 --> 00:17:00,880 return, copilot provides that syntax for 401 00:16:57,440 --> 00:17:04,360 me. And yes, I should put that into my 402 00:17:00,880 --> 00:17:04,360 snippets manager. 403 00:17:04,640 --> 00:17:10,400 Finally, I use AI for generating sample 404 00:17:07,120 --> 00:17:12,480 data. This is particularly good if I'm 405 00:17:10,400 --> 00:17:14,640 designing an app with a GUI and I want 406 00:17:12,480 --> 00:17:18,280 to see how it looks with some user data 407 00:17:14,640 --> 00:17:18,280 already in place. 408 00:17:19,839 --> 00:17:24,160 So after using GitHub Copilot for a 409 00:17:21,839 --> 00:17:26,959 while, I moved on to using the cursor AI 410 00:17:24,160 --> 00:17:30,320 editor. This is a fork of Visual Studio 411 00:17:26,959 --> 00:17:32,240 Code with AI built into it. And the 412 00:17:30,320 --> 00:17:34,799 benefit of this is that as well as doing 413 00:17:32,240 --> 00:17:36,960 everything C-pilot does, it can access 414 00:17:34,799 --> 00:17:39,919 the entire project, editing multiple 415 00:17:36,960 --> 00:17:42,480 files at a time and even adding new 416 00:17:39,919 --> 00:17:44,880 files if it needs to. And it adds a 417 00:17:42,480 --> 00:17:47,600 chatbased interfaced option for lower 418 00:17:44,880 --> 00:17:50,400 longer form queries. Now, I think 419 00:17:47,600 --> 00:17:53,520 probably GitHub can do this now, but it 420 00:17:50,400 --> 00:17:55,039 couldn't at the time. Anyway, I found 421 00:17:53,520 --> 00:17:58,799 this to be great for filling in the 422 00:17:55,039 --> 00:18:00,640 blanks in my expertise. 423 00:17:58,799 --> 00:18:03,360 For example, I recently changed my 424 00:18:00,640 --> 00:18:05,600 website at trolls.net to use a different 425 00:18:03,360 --> 00:18:07,760 static site generator. And unlike the 426 00:18:05,600 --> 00:18:10,799 ones I'd used before, this one didn't 427 00:18:07,760 --> 00:18:12,559 come with pre-built themes. So, when I'd 428 00:18:10,799 --> 00:18:15,600 added all my content and set up the 429 00:18:12,559 --> 00:18:18,559 navigation, I was left with this rather 430 00:18:15,600 --> 00:18:20,880 ugly site. And I thought, uh, now I've 431 00:18:18,559 --> 00:18:23,600 got to get into the CSS, but I'm not a 432 00:18:20,880 --> 00:18:25,039 CSS expert. 433 00:18:23,600 --> 00:18:28,080 So, then, of course, it occurred to me 434 00:18:25,039 --> 00:18:30,320 to ask the AI to generate my CSS. So, I 435 00:18:28,080 --> 00:18:33,520 pointed it at my project folder and gave 436 00:18:30,320 --> 00:18:36,080 it this prompt. Create a responsive CSS 437 00:18:33,520 --> 00:18:38,240 theme with light and dark modes. It 438 00:18:36,080 --> 00:18:40,720 should have a header with navigation, a 439 00:18:38,240 --> 00:18:42,559 footer with links and copyright notices. 440 00:18:40,720 --> 00:18:44,320 The homepage is a list of blog post 441 00:18:42,559 --> 00:18:47,120 summaries, and each post has its own 442 00:18:44,320 --> 00:18:49,280 page. The site is mainly text with some 443 00:18:47,120 --> 00:18:51,679 images. 444 00:18:49,280 --> 00:18:55,039 So, it didn't get it right first time. 445 00:18:51,679 --> 00:18:57,360 It took me maybe three hours of asking 446 00:18:55,039 --> 00:18:59,600 and reverting and adding suggestions and 447 00:18:57,360 --> 00:19:03,039 asking for more features and tweaking 448 00:18:59,600 --> 00:19:06,320 the colors and all those sort of things. 449 00:19:03,039 --> 00:19:08,880 But finally it came up with this which I 450 00:19:06,320 --> 00:19:10,880 was very pleased with. 451 00:19:08,880 --> 00:19:13,200 So the AI had allowed me to take a step 452 00:19:10,880 --> 00:19:16,160 back and instead of operating as a 453 00:19:13,200 --> 00:19:18,400 mediocre CSS developer, I was a designer 454 00:19:16,160 --> 00:19:20,640 who was talking to a very patient CSS 455 00:19:18,400 --> 00:19:23,280 developer. And while I could have done 456 00:19:20,640 --> 00:19:25,360 this myself, I would have got stuck in 457 00:19:23,280 --> 00:19:29,080 how to do instead of being able to focus 458 00:19:25,360 --> 00:19:29,080 on what to do. 459 00:19:30,160 --> 00:19:34,720 Which leads me neatly on to this rule. 460 00:19:33,360 --> 00:19:37,039 I don't know who wrote this, so I'm 461 00:19:34,720 --> 00:19:40,000 afraid I can't give credit, but I love 462 00:19:37,039 --> 00:19:42,640 it. Never get an AI to write code that 463 00:19:40,000 --> 00:19:45,600 you couldn't have written yourself. 464 00:19:42,640 --> 00:19:47,600 This just feels right to me. The AI is 465 00:19:45,600 --> 00:19:49,280 saving me time by filling in the blanks, 466 00:19:47,600 --> 00:19:51,679 but I could have done it all myself. It 467 00:19:49,280 --> 00:19:54,000 just would have taken longer. 468 00:19:51,679 --> 00:19:55,600 I could have written all that CSS, and I 469 00:19:54,000 --> 00:19:58,480 can write code without super 470 00:19:55,600 --> 00:20:01,280 autocomplete. But the AI makes it faster 471 00:19:58,480 --> 00:20:02,559 and easier, and I still know enough to 472 00:20:01,280 --> 00:20:05,559 know if it's right or if it's 473 00:20:02,559 --> 00:20:05,559 hallucinating. 474 00:20:06,960 --> 00:20:12,320 Here are my tips for working with AI. 475 00:20:10,080 --> 00:20:15,679 Provide context. Now, a lot of people 476 00:20:12,320 --> 00:20:18,720 have discussed context in this 477 00:20:15,679 --> 00:20:21,039 conference so far, but the more 478 00:20:18,720 --> 00:20:23,120 information that you give the AI as part 479 00:20:21,039 --> 00:20:25,520 of the prompt, the better information 480 00:20:23,120 --> 00:20:27,360 you're going to get back. So point it at 481 00:20:25,520 --> 00:20:29,600 websites that deal with the issue you're 482 00:20:27,360 --> 00:20:32,640 asking about. Tell it what files you're 483 00:20:29,600 --> 00:20:34,640 looking at. Select the f the particular 484 00:20:32,640 --> 00:20:36,880 function you're having a problem with. 485 00:20:34,640 --> 00:20:39,760 Give it all the help you can so that it 486 00:20:36,880 --> 00:20:42,320 can help you. 487 00:20:39,760 --> 00:20:44,240 Iterate like with my website doesn't get 488 00:20:42,320 --> 00:20:46,880 everything right first time. Sometimes 489 00:20:44,240 --> 00:20:49,039 it gets dead wrong. But reword the 490 00:20:46,880 --> 00:20:51,520 question or just ask again. You'll get a 491 00:20:49,039 --> 00:20:53,280 different answer. And if it feeds you 492 00:20:51,520 --> 00:20:57,200 something that creates an error, give it 493 00:20:53,280 --> 00:20:59,200 the error and say fix it. 494 00:20:57,200 --> 00:21:01,360 Use a new chat for each topic. And this 495 00:20:59,200 --> 00:21:04,640 is kind of the reverse of point one 496 00:21:01,360 --> 00:21:07,520 because we want to clear the context. So 497 00:21:04,640 --> 00:21:09,280 the great thing about chats is that you 498 00:21:07,520 --> 00:21:11,360 don't have to reiterate everything. You 499 00:21:09,280 --> 00:21:13,200 can ask follow-up questions and it knows 500 00:21:11,360 --> 00:21:14,960 what you've discussed earlier in the 501 00:21:13,200 --> 00:21:17,200 chat. But when you're changing to a 502 00:21:14,960 --> 00:21:18,960 totally new topic, you want it to forget 503 00:21:17,200 --> 00:21:22,320 all that stuff and start from scratch. 504 00:21:18,960 --> 00:21:24,960 So close that and open a new chat. 505 00:21:22,320 --> 00:21:26,880 And finally, don't hesitate to ask it to 506 00:21:24,960 --> 00:21:29,120 explain itself. Don't just accept what 507 00:21:26,880 --> 00:21:32,120 it says. Ask it to if you don't 508 00:21:29,120 --> 00:21:32,120 understand. 509 00:21:34,159 --> 00:21:41,360 So that's my escape route. One, project 510 00:21:37,679 --> 00:21:43,440 design before you start coding. Two, 511 00:21:41,360 --> 00:21:45,280 project structure so that it's readable 512 00:21:43,440 --> 00:21:47,760 and maintainable. 513 00:21:45,280 --> 00:21:51,200 Three, documentation, existing 514 00:21:47,760 --> 00:21:53,440 documentation and your own. And four, 515 00:21:51,200 --> 00:21:57,000 using AI can be really helpful, but 516 00:21:53,440 --> 00:21:57,000 check its work. 517 00:21:57,039 --> 00:22:01,360 And finally, I want to emphasize that 518 00:21:59,280 --> 00:22:03,520 I'm not opposed to tutorials. I do 519 00:22:01,360 --> 00:22:05,520 tutorials. I read articles and books. I 520 00:22:03,520 --> 00:22:08,240 watch videos all the time to keep up to 521 00:22:05,520 --> 00:22:10,640 date. The problem is making that initial 522 00:22:08,240 --> 00:22:12,720 jump from tutorials to projects. But 523 00:22:10,640 --> 00:22:15,720 once you've escaped, never stop 524 00:22:12,720 --> 00:22:15,720 learning. 525 00:22:16,080 --> 00:22:20,159 So, thank you for listening to my talk. 526 00:22:18,159 --> 00:22:24,400 If you'd like to contact me, my website 527 00:22:20,159 --> 00:22:26,640 is tros.net and I'm at tro on mastadon. 528 00:22:24,400 --> 00:22:28,880 And if you'd like to buy my book, come 529 00:22:26,640 --> 00:22:31,280 up and grab one of my cards that has a 530 00:22:28,880 --> 00:22:32,720 QR code with a special pyon discount. 531 00:22:31,280 --> 00:22:36,490 And I'll put more of these out on the 532 00:22:32,720 --> 00:22:43,280 sticker table, too. Thank you very much. 533 00:22:36,490 --> 00:22:44,880 [Applause] 534 00:22:43,280 --> 00:22:48,159 Thank you very much, Sarah. What a 535 00:22:44,880 --> 00:22:50,799 wonderful talk. How insightful on how to 536 00:22:48,159 --> 00:22:52,080 do things with confidence and uh 537 00:22:50,799 --> 00:22:53,440 stability. Uh 538 00:22:52,080 --> 00:22:55,039 the things I do to get a mug. 539 00:22:53,440 --> 00:22:57,039 The things we do to get a mug. Yes. The 540 00:22:55,039 --> 00:22:58,400 weather here is quite muggy indeed. Uh 541 00:22:57,039 --> 00:22:59,360 so Sarah, thank you very much on behalf 542 00:22:58,400 --> 00:23:00,400 of 543 00:22:59,360 --> 00:23:02,190 Yay. 544 00:23:00,400 --> 00:23:04,720 Once again for Sarah. 545 00:23:02,190 --> 00:23:06,640 [Applause] 546 00:23:04,720 --> 00:23:07,919 Uh friends, we do have some time for any 547 00:23:06,640 --> 00:23:09,360 questions. Was there anyone that would 548 00:23:07,919 --> 00:23:12,360 like to ask any questions of Sarah this 549 00:23:09,360 --> 00:23:12,360 afternoon? 550 00:23:13,919 --> 00:23:18,080 That's my son. 551 00:23:15,640 --> 00:23:20,000 [Laughter] 552 00:23:18,080 --> 00:23:22,000 It's important to have communication and 553 00:23:20,000 --> 00:23:25,000 familial relationships to be 554 00:23:22,000 --> 00:23:25,000 okay. 555 00:23:32,000 --> 00:23:36,880 Are you proud of me? No. Um, 556 00:23:34,400 --> 00:23:38,000 yes I am. there. 557 00:23:36,880 --> 00:23:40,240 Was that the question? 558 00:23:38,000 --> 00:23:42,799 Um, 559 00:23:40,240 --> 00:23:45,440 when you're breaking down uh into into 560 00:23:42,799 --> 00:23:47,760 your project structure, 561 00:23:45,440 --> 00:23:50,480 how small do you go for those files? 562 00:23:47,760 --> 00:23:52,320 Like some of them seemed like they might 563 00:23:50,480 --> 00:23:55,120 only just have a single function per 564 00:23:52,320 --> 00:23:57,280 file. Do you find that's tedious? Do you 565 00:23:55,120 --> 00:23:58,640 do you then kind of move those up a 566 00:23:57,280 --> 00:24:00,880 level and group a few of them together 567 00:23:58,640 --> 00:24:03,600 or do you just run with that? 568 00:24:00,880 --> 00:24:06,080 I when I'm writing in Swift, I have a 569 00:24:03,600 --> 00:24:08,799 line limit. I don't like to go over 300 570 00:24:06,080 --> 00:24:11,520 lines in a file. I find when I'm writing 571 00:24:08,799 --> 00:24:14,080 in other languages that that is too 572 00:24:11,520 --> 00:24:15,919 limiting, particularly in a like a 573 00:24:14,080 --> 00:24:17,440 client side JavaScript where I don't 574 00:24:15,919 --> 00:24:19,039 want it to be rushing off to the server 575 00:24:17,440 --> 00:24:22,080 every time. So I'll have much longer 576 00:24:19,039 --> 00:24:25,919 files. But yes, um we kept breaking down 577 00:24:22,080 --> 00:24:28,799 the the the tasks, but a single file 578 00:24:25,919 --> 00:24:32,039 could be a super task rather than each 579 00:24:28,799 --> 00:24:32,039 of the subtasks. 580 00:24:33,200 --> 00:24:38,840 Fantastic. Thank you. Do we have any 581 00:24:35,200 --> 00:24:38,840 more one more here? 582 00:24:42,080 --> 00:24:47,919 Yeah, thanks for the talk. The I like 583 00:24:45,200 --> 00:24:49,600 that you said um don't use AI for 584 00:24:47,919 --> 00:24:53,440 something that you couldn't have written 585 00:24:49,600 --> 00:24:57,440 yourself. Actually my case I've I have 586 00:24:53,440 --> 00:25:02,080 to admit I written like um a package 587 00:24:57,440 --> 00:25:05,039 and I have no idea how it works but but 588 00:25:02,080 --> 00:25:07,360 I was all interested is I know the 589 00:25:05,039 --> 00:25:10,799 output so I made sure that all the test 590 00:25:07,360 --> 00:25:13,360 pass but I don't know how it works so I 591 00:25:10,799 --> 00:25:14,720 don't know pro and actually maybe a lot 592 00:25:13,360 --> 00:25:17,600 of people would be doing something like 593 00:25:14,720 --> 00:25:19,039 that. Look, I think we all do that to a 594 00:25:17,600 --> 00:25:20,960 certain extent. I mean, none of us are 595 00:25:19,039 --> 00:25:22,640 writing the machine code. We're all 596 00:25:20,960 --> 00:25:26,000 taking in stuff that we don't know how 597 00:25:22,640 --> 00:25:28,880 it works, whether it's Python itself or 598 00:25:26,000 --> 00:25:30,960 or a framework or anything. So, at some 599 00:25:28,880 --> 00:25:32,799 point, you've just got to trust that the 600 00:25:30,960 --> 00:25:34,159 maintainers of whatever that is know 601 00:25:32,799 --> 00:25:36,159 what they're doing, but you're 602 00:25:34,159 --> 00:25:39,559 responsible for your you code, not for 603 00:25:36,159 --> 00:25:39,559 what they code. 604 00:25:40,240 --> 00:25:42,640 Excellent. We have time for probably one 605 00:25:41,600 --> 00:25:45,760 more question if there were anything 606 00:25:42,640 --> 00:25:47,200 further. Of 607 00:25:45,760 --> 00:25:48,480 course, Sarah will be around for the 608 00:25:47,200 --> 00:25:50,320 rest of the conference. We very much 609 00:25:48,480 --> 00:25:51,760 appreciate your time this afternoon. Uh, 610 00:25:50,320 --> 00:25:55,799 and we'll see you back shortly. Thank 611 00:25:51,760 --> 00:25:55,799 you. Thank you.