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