Mastering PyCharm Transcripts
Chapter: The Editor
Lecture: Code formatting for teams

Login or purchase this course to watch this video and the rest of the course contents.
0:01 The code formatting fixes that we saw before,
0:03 those were actually based on the coding style
0:06 that we told PyCharm to follow,
0:08 and chances are they were the default,
0:11 but not everybody follows the default,
0:13 and normally that's not really a big thing
0:15 unless you're working in a team and you have version control
0:19 and you both reformat a file,
0:22 what are you going to get— you're going to at best get
0:25 this file is changed, this line is changed, it was indented,
0:28 this line is changed, it was unintended,
0:30 this line is changed, it was indented, back and forth like the fighting
0:33 every time somebody reformats a file,
0:35 every difference in that formatting style is going to surface
0:39 and show up as a difference.
0:40 And in a worst-case scenario, these are going to be merge conflicts.
0:45 This can be a super pain in the rear if you are working in a team.
0:49 Luckily there is a fix for that,
0:51 so if we go to preferences, go to code style
0:54 and we'll just focus on PyCharm but notice
0:56 we could do this for Haml or Javascript or whatever.
0:58 Notice across the top, there are 6 tabs up there
1:04 and each tab has a ton of options
1:07 like for method call arguments, where do you align them if it's multi-line and so on.
1:12 You can go through and you can configure all of these
1:15 or you could import or export a file, so this is really cool
1:19 so you could basically configure everyone on the team say,
1:22 this is the style we're going to use, you configure it here,
1:24 export it, everyone imports it.
1:26 However, that's great, if you are on a single team
1:29 like say work machine and we're only writing code against our one project;
1:34 what if you are multiple teams, with different styles,
1:36 what if you're contributing to an open source project that has one style
1:39 and you're also working on your project at work
1:42 which is a different style like that's a super pain, right.
1:47 You can also fix that.
1:49 Over here, you can say you can set up some styles
1:52 and copy it to a project or export it to a file,
1:55 so I could export this to a file and share with my team
1:59 and give it a name and you could pick the style
2:02 and things like that that's really great.
2:04 You can also say for this particular project
2:07 store the formatting settings in source control,
2:10 so there'll be a hidden .idea folder with a few files that talk about the project,
2:15 and one of those can describe things like
2:19 what is the formatting style around method arguments
2:22 so you can actually store the settings for the format inside the project
2:26 so you open up different projects, run CMD alt L, reformat the file
2:30 that might mean different things based on that particular projects style choices
2:35 so here's a couple of things you can do
2:37 in terms of helping team members end up on the same style page
2:43 because as I outlined in the beginning,
2:45 if you don't that makes version control a real pain.