Mastering PyCharm Transcripts
Chapter: The Editor
Lecture: Concepts: The editor

Login or purchase this course to watch this video and the rest of the course contents.
0:01 The first thing you probably noticed when we opened up PyCharm
0:04 and it should be really no surprise,
0:06 is that we had nice syntax highlighting.
0:09 Of course, it highlights the keywords, it highlights the methods,
0:13 it highlights strings, and this is actually really configurable as you'll see.
0:17 You can pick different themes and so on,
0:20 but the syntax highlighting is super nice.
0:23 In fact, if you go to the preferences and go to appearance
0:26 you can see the theme that I'm using is Darcula,
0:30 but you can actually pick other themes
0:32 so here's Darcula, and on the right is just the I guess it's called default,
0:37 I don't know white, boring, who knows,
0:39 so there's another theme, this is another one built-in
0:41 but you can actually go and download a whole bunch of other themes
0:44 and import them and even create your own.
0:47 The other thing that you can control which is part of the theme
0:52 but is very fine grained, you can control it super easily
0:56 is the syntax highlighting colors.
1:00 Here you can see the path in the preferences
1:03 so you can go over here to the color scheme say Python
1:06 and change the color of decorators
1:09 or change the colors of strings or operators and all these things.
1:13 All you've got to do is like here we click decorator
1:15 and on the right where it says foreground it has some sort of yellow color
1:18 you click that color and a color we look comes up, and you can pick it,
1:22 or you can either take the sort of global definition,
1:26 I'm sure there is not one for decorators
1:28 but for things like strings that would be.
1:31 You can grab the global definition for that or for colors
1:34 or you can create your own basic style.
1:37 So, you can create a style that is exactly the way you want
1:40 by going into this part of the menu preferences and just really tweaking it,
1:45 it takes a long time actually to get it right,
1:48 but once you do it's super sweet
1:50 and you can see you can also do the same for CSS, for Javascript
1:53 for Cucumber test scripts you know, you name it,
1:56 you can mess with it down here,
1:59 so tons and tons of features around customizing the colors,
2:03 and you can export those for other people on your team
2:08 or on the internet to play with.
2:10 We saw that auto complete was a super important thing
2:13 and it really helps with discoverability for large code, new code,
2:18 code that you picked up but you don't really know super well, things like that,
2:22 even learning the standard library really well
2:24 because you get great auto complete on all of those things.
2:27 Here we have a wizard named Gandolf, level 75, we created him,
2:31 we want to do some stuff, so we say hero.
2:34 and right away we can see the wizard class defines an attack method
2:37 the wizard class derives from creature
2:40 which has a get defensive role a name and a level,
2:43 so we could work with that as well.
2:45 If we want to go way down to the Python data model
2:48 heck we could go and work with a __dict__
2:50 that actually comes from object which is the base class of creature.
2:53 So over on the right you can see the source
2:57 of actually where that method or that property or field is coming from.
3:02 Now, sometimes, it's not so amazing
3:05 here we have data access library, we're calling find user by email address
3:10 it's going to the database and it's doing a query
3:12 and it's returning this user say SQLAlchemy or MongoEngine
3:16 or any of the ORMs, is doing a query and it's pulling back these objects
3:20 and almost all of those has given us proper intellisense as you'll see
3:24 you're like why do you not know what comes back from this query
3:27 it's always a list of users or something like that.
3:30 There will be times, and you saw this in our demo
3:34 where adding a little bit of a hint just at the lowest level
3:38 usually is all that's required to help PyCharm
3:42 to help other linters really know what types you're working with.
3:45 So over here we are doing this query
3:48 that turns out to be a MongoEngine query
3:51 and it's totally fine and it works,
3:54 but it doesn't tell the editor enough information
3:57 to really give us the help that we might want.
3:59 So what do we do?
4:01 If we go and we add some types hints,
4:04 like it takes a string and it returns an optional user there might be none
4:08 or there is going to be one, it could be none or the actual user object
4:12 so it first does that's what we should have done in our demo actually
4:15 and once we do that— boom, PyCharm comes alive
4:18 and anywhere we use this object that came back from find user by email
4:22 is definitely a user you can see right there in the auto complete source
4:26 that thinks all these things come from user, and it's right.
4:29 So these type hints can dramatically improve auto complete
4:34 and discoverability as well as some of the linting, so use them judiciously
4:39 but when you're crossing major application boundaries
4:43 especially down to data access layer and lowest level of service layers,
4:46 these can be really, really useful.