WEBVTT

1
00:00:01.619 --> 00:00:09.520
- So, now that we explored the basic auto-completion and suggestions functionality with this basic

2
00:00:09.520 --> 00:00:14.520
- example, let's dive into another slightly more complex example.

3
00:00:15.780 --> 00:00:22.400
- Let's say we want to write a script that helps us back up our SQLite database.

4
00:00:22.479 --> 00:00:30.620
- So, let's imagine we have some SQLite database, an app.db file, which could contain our SQLite

5
00:00:30.620 --> 00:00:30.940
- database.

6
00:00:31.320 --> 00:00:36.140
- Here it's of course just an empty file, but we could populate and initialize it with some

7
00:00:36.140 --> 00:00:37.000
- other Python code.

8
00:00:38.080 --> 00:00:43.380
- And let's say we have such a database file and now we want to write a little utility

9
00:00:43.380 --> 00:00:47.000
- program which we can run to back up that database.

10
00:00:48.880 --> 00:00:54.480
- And that does not just mean that we want to have a program that copies the database,

11
00:00:54.760 --> 00:01:01.040
- but instead here I want to build a program that actually asks me what I want to do.

12
00:01:01.140 --> 00:01:07.020
- And one thing I could do besides backing up the database could be that I want to restore

13
00:01:07.020 --> 00:01:07.300
- it.

14
00:01:08.340 --> 00:01:13.280
- So, my idea essentially is that it always keeps like one backup and one active database

15
00:01:13.280 --> 00:01:18.160
- and we can roll back and restore the backed up database.

16
00:01:19.580 --> 00:01:23.040
- And of course we can use GitHub Copilot for that.

17
00:01:23.220 --> 00:01:29.520
- Now we could use the chat functionality, but we'll explore that later, so let's get there

18
00:01:29.520 --> 00:01:36.060
- with just suggestions, because as you will see, that's also really simple to do and these

19
00:01:36.060 --> 00:01:38.300
- suggestions can be really powerful.

20
00:01:39.800 --> 00:01:45.380
- Now I'll start here by adding some global variables and I'll start by adding one variable

21
00:01:45.380 --> 00:01:53.420
- which I'll name active DB file and there I'll store a string where I have app.db.

22
00:01:55.020 --> 00:02:00.260
- And you see here for me it automatically suggests backup DB file.

23
00:02:00.500 --> 00:02:03.860
- Now you might be getting different suggestions.

24
00:02:05.560 --> 00:02:05.980
- That's important.

25
00:02:06.200 --> 00:02:10.440
- You will very likely not always see what I'm seeing here.

26
00:02:10.539 --> 00:02:14.700
- That's how AI works, but chances are high that you're getting a suggestion like this

27
00:02:14.700 --> 00:02:15.040
- as well.

28
00:02:15.380 --> 00:02:20.300
- And if you don't, well, you can always just start typing and at some point you should

29
00:02:20.300 --> 00:02:22.060
- see a similar suggestion.

30
00:02:23.810 --> 00:02:30.180
- And here I'll actually rename this to just backup.db because of course you can and should

31
00:02:30.320 --> 00:02:36.420
- always evaluate the code that is generated by GitHub Copilot and you can change it to

32
00:02:36.420 --> 00:02:42.720
- make sure that it is the code you want because this is a course for developers using AI.

33
00:02:43.220 --> 00:02:48.660
- So use your developer skills, your knowledge and get the best of both worlds.

34
00:02:48.840 --> 00:02:51.520
- Get more efficient by using AI.

35
00:02:51.880 --> 00:02:54.420
- Don't rely on just the AI.

36
00:02:55.860 --> 00:02:56.780
- That's really important.

37
00:02:57.200 --> 00:03:02.280
- And if you do the latter, as you will also see a little bit later, you can actually get

38
00:03:02.280 --> 00:03:03.480
- less efficient.

39
00:03:04.100 --> 00:03:08.880
- So always think about the code that was generated by AI.

40
00:03:09.680 --> 00:03:15.320
- Like here where I renamed this to be in line with the naming convention I want to use.

41
00:03:16.440 --> 00:03:21.740
- So now I got these two variables here, but actually I now already got more than that.

42
00:03:22.240 --> 00:03:28.500
- I'm giving GitHub Copilot some extra context already because the entire code base it sees

43
00:03:28.500 --> 00:03:32.900
- in this file is the context it evaluates behind the scenes.

44
00:03:34.190 --> 00:03:41.320
- So it will take these variables into account for its next suggestions and it probably already

45
00:03:41.320 --> 00:03:47.480
- has a first idea regarding what I'm building here, what my program will be about.

46
00:03:49.240 --> 00:03:51.400
- So now I'll add a function and guess what?

47
00:03:51.680 --> 00:03:58.320
- It suggests this function name and also this code block here.

48
00:03:58.440 --> 00:03:59.960
- So not just one line, but multiple lines.

49
00:04:01.200 --> 00:04:06.300
- And if I hover over this after a while, I'm getting this little info box here and I got

50
00:04:06.300 --> 00:04:08.720
- different suggestions here, as you can tell.

51
00:04:10.320 --> 00:04:16.779
- Now here I actually want to take the suggestion, which includes a little log here.

52
00:04:17.060 --> 00:04:20.200
- So I'll hit tab and I got this code here.

53
00:04:21.540 --> 00:04:28.560
- Now as you can tell, got some yellow squiggly lines here that this thing here is not defined

54
00:04:28.560 --> 00:04:32.620
- because I'm using some identifier here, which doesn't exist in this file.

55
00:04:33.700 --> 00:04:36.460
- Now that's because I need to import something.

56
00:04:36.960 --> 00:04:37.860
- So let's go up there.

57
00:04:38.300 --> 00:04:44.740
- And if I type IM, GitHub Copilot, again, because it takes the entire file content into account,

58
00:04:45.940 --> 00:04:51.120
- it understands that this shutil package is missing and it suggests this import.

59
00:04:52.520 --> 00:04:57.200
- So that's how it can speed up your work, because now I'm, of course, taking a lot of time to

60
00:04:57.200 --> 00:05:00.000
- explain everything, but you can go through the

61
00:05:00.000 --> 00:05:05.400
- entire code really fast and just hit tab all the time in the different places, you just need to

62
00:05:05.400 --> 00:05:11.140
- know where to place your cursor and which characters to type to get the right suggestions.

63
00:05:12.460 --> 00:05:19.920
- That's the part where your developer skills still are important, leave alone more complex programs

64
00:05:19.920 --> 00:05:24.800
- where of course GitHub Copilot might not be smart enough. But for simple programs like this,

65
00:05:24.880 --> 00:05:28.080
- it's really just about placing the cursor in the right place,

66
00:05:28.480 --> 00:05:33.620
- typing the right characters and suggestions should then get you all the rest.

67
00:05:35.080 --> 00:05:41.760
- Now here it actually already suggests a restore database function for me here,

68
00:05:41.840 --> 00:05:46.800
- though I'll actually change the indentation and then I'll accept this.

69
00:05:47.820 --> 00:05:54.560
- And as soon as I do, in my case here, it suggests the next lines of code where it wants to copy the

70
00:05:54.580 --> 00:06:03.740
- backup db file and replace the active db file with it, so to say. So that's all looking pretty

71
00:06:03.740 --> 00:06:10.780
- good and with that I already got my very basic backup restore script but of course I got no way

72
00:06:10.780 --> 00:06:17.740
- of invoking these different functions. So therefore I'll do that as a next step and

73
00:06:17.740 --> 00:06:23.020
- now I'm getting a suggestion here which is not helpful to me. This looks better,

74
00:06:23.360 --> 00:06:30.520
- some code that would run when this script is executed, so let's see what I get as the next

75
00:06:30.520 --> 00:06:37.760
- suggestions. But this of course now doesn't make sense. Now you again might be getting different

76
00:06:37.760 --> 00:06:43.840
- suggestions but at least for me the suggestions I'm getting here don't make sense. I don't want to

77
00:06:43.840 --> 00:06:49.420
- backup the database and restore the database immediately thereafter whenever I run this

78
00:06:49.460 --> 00:06:56.780
- Python script. That's not what I want to do here. So here you can see the AI isn't really

79
00:06:56.780 --> 00:07:03.860
- understanding what I want to do with this overall script. Now let's take a look at the completions

80
00:07:03.860 --> 00:07:10.539
- panel here. Maybe we got more useful suggestions here. After all it is taking more time here

81
00:07:10.780 --> 00:07:19.880
- but no this is also not what I want. So instead again it's my developer skills that are needed

82
00:07:19.880 --> 00:07:26.400
- here and I'll actually add another function here and I'll name it main and in that function I also

83
00:07:26.400 --> 00:07:31.919
- don't want to backup and restore the database. Instead I want to evaluate the user input

84
00:07:32.920 --> 00:07:40.000
- and for that first of all I want to tell the user what their options are. Now just by typing print

85
00:07:40.480 --> 00:07:48.000
- GitHub Copilot kind of catches up and understands that I maybe want to print some options and the

86
00:07:48.000 --> 00:07:54.159
- first option could be to backup the database. I'll accept this. Then restore the database

87
00:07:55.560 --> 00:08:03.880
- and then here I want to get the the user choice with the input function. Makes sense. So I'll

88
00:08:03.919 --> 00:08:11.340
- hit tab again and then thereafter it also correctly estimates and suggests that I want to

89
00:08:11.340 --> 00:08:19.000
- check which choice the user made. One or two and then invoke the appropriate function up there

90
00:08:19.000 --> 00:08:23.240
- or else I want to tell the user that the choice is invalid.

91
00:08:25.540 --> 00:08:30.900
- Now actually I also want to allow the user to exit the program so I'll add another print here

92
00:08:32.120 --> 00:08:39.460
- and smartly it suggests this option and I'll add another else if block in here

93
00:08:39.460 --> 00:08:48.860
- all with GitHub Copilot and then I want to print exiting and thereafter it will exit the program

94
00:08:48.860 --> 00:08:56.840
- since I'm not invoking any other code. Now inside of my code down here I now want to call this main

95
00:08:56.900 --> 00:09:01.440
- function. It did not suggest it here for me so I'll just type it manually. It's not too much work

96
00:09:01.440 --> 00:09:08.580
- and that's also important. You shouldn't wait for suggestions if it takes some time or if they

97
00:09:08.580 --> 00:09:15.180
- don't show up for some reason. If you know the code you need just type it. Maybe you'll get

98
00:09:15.180 --> 00:09:19.860
- suggestions along the way at some point then but even if you don't if it's not a lot of code like

99
00:09:19.860 --> 00:09:25.460
- this just type it. Don't sit there and wait for the suggestions because that is a trap you can

100
00:09:25.540 --> 00:09:32.180
- fall into. When using these AI tools you can feel inclined to use them for everything but

101
00:09:32.180 --> 00:09:39.400
- don't forget that you can type code as well. You have more than just the tab key on your keyboard

102
00:09:39.400 --> 00:09:50.500
- so use it. And with that I get this program here. Let's give it a try I'd say. I'll run it

103
00:09:51.240 --> 00:09:58.980
- like this. I get my choices. I can exit of course. Yeah that works but now let's run it again and

104
00:09:58.980 --> 00:10:07.800
- let's backup the database and you see this backup db file is created. If I now run it again and

105
00:10:07.800 --> 00:10:14.600
- choose restore probably also worked. Didn't get an error. Looks like the database was restored.

106
00:10:15.120 --> 00:10:22.220
- We can test this by adding some text in there which is of course not valid sql light database

107
00:10:22.220 --> 00:10:29.360
- content but it's good for testing this. So I got the t and the appdb and the abc in the backup

108
00:10:29.360 --> 00:10:35.740
- and now if I again restore this you see I get the abc here in appdb as well.

109
00:10:36.860 --> 00:10:43.120
- So the script is working the way it should. Of course still a simple script but you saw how we

110
00:10:43.960 --> 00:10:49.319
- can use github copilot to generate it and you already learned about some potential pitfalls

111
00:10:49.319 --> 00:10:51.720
- and how to use github copilot efficiently.

