Powerful VSCode Tips And Tricks For Python Development And Design

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's video i thought it'd be nice to share my vs code settings with you and the extensions that i use there's one in particular that i don't think you're using and you probably should i'm not the type of person that customizes every aspect of their setup i mean i didn't even change the desktop background on my mac but still i think you'll find some helpful tips and tricks in this video now if you want to become better at software design i have a guide for you it's totally free you can get it at ironcodes.com design guide contains my steps that i go through when i design and set up a new application so i hope it's going to be helpful for you as well contains really actionable stuff not too much to read just really practical stuff to help you get started so ariancodes.com design guide and the link is also in description of this video now let's dive into vs code if you've watched any of my earlier videos you probably know that i always use vs code for editing python files i don't think vs code is particularly the best editor for python what i heard is that a tool like pycharm is actually much better in terms of refactoring and other tools that are specific to python there are actually two reasons why i'm sticking with vs code the first reason is that in my company i do a lot of web development and vs code works actually really well for that it has great support for typescript react node.js etc etc so when i do my python videos i don't want to have to learn another ide because i feel like i'm going to screw up the keyboard shortcuts all the time and that's going to be really annoying to watch so sticking with the same ide even though it's not 100 perfect for python development is still the best choice for me the second reason i'm sticking with vs code is that i'm old i've been ordering the same food from the same restaurant for the last 20 years you think i'm going to change my code editor get off my lawn so i want to talk a bit about the settings that i use in vs code and the extensions that i've installed but before i do that i want to mention one thing and that's the terminal that i'm using so vs code has built in terminal but if you just install vs code on your machine like that this is not what it looks like so i'm using a mac by the way and mac uses the z shell terminal by default since a couple of years and there's a really nice extension that allows to change a lot of aspects of how the terminal works and what it looks like and that's called oh my z shell oh my gosh i have no idea how to pronounce it this is their website they have a lot of nice features you can add themes what i find the most useful thing of this extension is that it allows to show what git branch you're on in the terminal let me show you what i mean so here i'm in the folder where i store most of my code that i'm using for this channel so if i go for example in my work in progress folder that's where i work on any new examples then here you see that it automatically displays that this is a git repos story and also displays the branch so i find this really helpful and it uses color so it's very clear immediately what is what so i really like this a lot now it has lots of other features if you look at the documentation for example there is things like themes that you can install all kinds of plugins you can change a lot of aspects of how the terminal works so that's actually really nice what i also have installed in mac is item 2 this is a replacement for the built-in mac terminal that also has a lot of extra options like having split panels or lots of hotkeys that allow you to bring a terminal onto the screen from wherever you are in any application so i find that really useful as well now back to vs code if you install vs code from scratch then you're going to need to install a couple of extensions to really be able to use it with python so i'm going to the extension tab here and i'll show you what i have installed the main thing that you need to install is this and that's the python extension that's developed by microsoft and that includes actually a lot of the other things that you're going to need for example that also installs these jupyter extensions well i don't use jupyter notebooks a lot but that is pretty useful if you're a data scientist for example it also installs pylance which is the intellisense service that vs code uses to automatically help you write better python code and the python extension also installs a linter pylint which is also really helpful i'll talk about a few of these other extensions in a minute when you write a python program then basically the intellisense is going to help you auto suggest imports and things like that and pyland and the linting tool also help you identify issues in your code like this data class import that's not being used at the moment and there are a couple of other things that i'll also show you in a minute now i want to go to my settings quickly and i'll show you the settings that i'm using for this project so it's probably easier if i open this in the json format so that we can see it at the clouds and there's a couple of things here that are happening well one is that i'm putting the zoom level to 3 so it's actually big enough for the video normally when i do coding i put the zoom level to maybe one because i do have a relatively large screen but for recording these videos i like to make the font a little bit bigger so it's a bit easier to see for you then there are a couple of other things one is that there is a type checking mode that i set to strict now this is not always a good idea a strict basically gives you an error for any issue that happens with typing i'll show you what i mean so let me go back to this file and now let me create a function here let's call this function something because i have no inspiration whatsoever and we have a variable that's of type ins and we're simply printing that variable here so nothing special and then here i'm going to call that function with a string like so now obviously in terms of typing you shouldn't do this because it expects an instance so you see we get a type error here if i switch off the type checking mode like so then that error is gone so that's what the typing system helps you with that's really useful and there are three levels you have off which does no type checking whatsoever you have basic which does basic type checking and you have strict type checking which well that's very strict type checking so what's the difference between basic and strict well they have a bunch of different rules that are switched on or off based on whether you're on basic level on the strict level depending on the project that you work on you can choose different type checking mode i notice especially if you work with external libraries like pandas or numpy actually most of these libraries don't really have proper typing so when you put this to strict then you're going to get a lot of typing errors until recently i've always put this too strict in my videos but i do notice it kind of makes the code harder to read so i might actually switch to basic soon and see if that works a bit better and there's a few difference for example let me put this back to basic now if i go into the hello file again and if i import something let's say i do this from string import everything normally you shouldn't do this right don't use wildcard imports because it clusters the global namespace so you see now you get a warning here and if i switch this to strict this changes into an error so those are the kinds of things that you see when you switch between basic and strict type checking mode and the nice thing is in these settings you can actually change them per workspace per folder your user preferences so that means that you could create a project which is really standalone so you have full control of the types then you can put type check into strict so you get the maximum help from the type checking system but if you're using a lot of external libraries then you can put it to basic or even off in some cases if there is really a lot of issues so really helpful now back to the settings i have a couple of other things that i do one is that i have the editor set so that it formats my code when i save the file and that's basically what's happening in these two top lines and i also have a formatting provider and that's black in this case you can choose a couple of different ones there is also auto pep8 and a couple that you can choose i do like black i think it's really simple it's really opinionated it results in me not having to think about style anymore which i really enjoy so i normally use black for this and what this does is that if i'm typing something here like whatever and then i save the file it's going to automatically format the file for me when i save it so that i always know that the formatting is okay and then what you also do is this and this organizes the imports from me basically if you have a bunch of imports at the top of your file it's going to organize them for you so they'll put them in a preferred order it will combine imports if that's possible for example if i do something like this from enum import enum and i have another import from enum import auto which you often use when you're creating enumerated types and then i save this then it's going to combine this import into a single line for me without me having to do anything so that's pretty useful so then there's this part which is the linter so i'm generally enabling linting and in particular pyland because that's the linter that's installed when you install the python extension that microsoft provides and then i have a few other things here so one thing is this and that's actually related to the vim extension so vim is an extension you see i have it installed here this is an emulation of the vim editor for vs code that's pretty useful i'm not a vim expert at all like really not at all i've started using it basically based on recommendations from you guys when watching some of my videos and watching how crappy my refactoring and editing skills were so i installed vim and i thought it would be nice to explore whether this is going to work for me i actually do really like it i think it's a really powerful editor what i really like about it is that it is a kind of editing language so it allows you to do things like specifying that you should change an entire word or replace or whatever so i think that's that's really useful i'm still struggling a bit in particular with navigation in vim so i tend to stick to the mouse for the moment so that's for me the main challenge to still learn i'm able to to edit quite easily you know quite a few of the commands now so that's works out pretty well but navigation through larger code files and copying things pasting things in different places that's still a bit unintuitive to me i mean i still have to learn that i'm sure i'll get better at it but it's going to take a while so that's the vim emulation that i have installed here i won't talk too much about all the possibilities of vim there's lots of tutorials out there if you'd like me to i can also do a tutorial at some point but i want to play around with it a bit more before i do that so i can actually provide you with something valuable so vim emulation and now for vim i use this setting in particular because i think this is actually really useful and what the setting does is it gives the effect that you see here on the left so if i navigate you see that it displays line numbers relative to the current line that you're at so it does show which line we're at this is line 16 but you also see the relative line numbers up and down and that's actually really useful for example if you want to move down to this line so you see that it's 12 lines down so then you just type 12 j and then you're at that particular line so you don't have to compute those things in your mind so that makes moving to different lines in the code actually really easy and when you go to insert mode in vim then you see the line numbers that you used so really really useful feature this another tip which is what i also like to do a lot is color customization so you can basically change the color of anything in the interface in vs code but what i like to do often is that when i have a project i change the color of the title bar so that's the bar that you see here on the top so you see it's kind of like an earthy orangey kind of color this is a slightly darker version of the color of my iron coats brand and i like to do this because if i have multiple things that i'm working on so i might have a workspace for my company i might have one for the videos on this channel i might have another side project and by choosing different colors for the header bar i can very easily see where i am at the moment just by looking at the color so for me that just helps me navigate through the things that i'm doing much more easily and if you add this setting you can basically change the color here it even has a kind of built-in color editor here so you don't even have to remember the hex code you just change it to an appropriate color and that's really useful there's a few more things that i want to talk about and one in particular i think you're gonna like a lot so first i've been playing around with ai tools for auto completion and one of those tools is github co-pilots i've also done quite a few videos where i've shown tab 9 so i think both of these are actually really great tools they're certainly not perfect but i do find them quite helpful actually now i generally don't switch them on when i do the video recordings because i want to focus on the refactoring aspect of the code and not so much on what the ai suggests but when i'm doing web development for my company actually i find both github co-pilot and tab 9 really useful and they both have the pros and cons i think github co-pilot is a bit more limited in that you have very few settings that you can change and it also only works in vs code whereas tab 9 supports lots and lots of ides and has more team focused capability so i think overall tabloids is a more complete product at the moment co-pilot on the other hand use the most modern ai model so the predictions are slightly more accurate but i feel the difference is not even that big if you want to check out that nine i've put a link in the description of this video now there's one more thing i've recently discovered this and i think this is a really cool extension and that's this one this is a markdown preview that supports mermaids so what's mermaid mermaid is tool that allows you to create diagrams visualizations using text this is the website so it allows to generate all kinds of different diagrams including for example class diagrams which is really useful so you just type text like this and then it's going to generate a diagram from that i really like using mermaid to create my diagrams because it's really cumbersome to draw these kinds of diagrams in traditional graphical applications and often you may already have an outline of the classes that you're going to have so then you can just copy paste them and change the syntax a bit and then you have your class diagram written in text and what this extension does is that it adds support for mermaids to markdown files in vs code so you can write your mermaid code in vs code in a markdown file as a natural part of your text so you can use it to create your design documents or whatever you need and then it's going to display those diagrams for you and that's i think really cool let me show you how it works so here i have an example where i have a markdown file that has a couple of different diagrams so i made two examples here one is a strategy pattern diagram another one is the bridge pattern let me switch to the full screen for this and then i'm going to open the preview window and then you see that it automatically generates these diagrams and now if i change something here like so then it will automatically update the diagram and now of course if i want this to make any sense i also gonna have to change the name here and now you see that it's generated like this and then this one as well obviously i've been basically using this all the time the last few weeks because it just allows me to really quickly draw out a couple of diagrams and that helps me structure my thought about the kinds of designs that i'm thinking about and it can do pretty complicated stuff now obviously you're not in complete control of what the organization of the diagram is going to be like where the blocks are going to be placed mermaid decides that for you but it's a limitation that i'm happy to accept because it's so easy to use so that's a quick overview of how i set up my vs code development environment i hope you found it useful i hope it gave you some ideas of how to improve your own development environment as well if you enjoyed this video give it a like consider subscribing to my channel if you want to watch more of my content thanks for watching take care see you soon
Info
Channel: ArjanCodes
Views: 165,154
Rating: undefined out of 5
Keywords: vscode, visual studio code, vs code, python programming, python vscode, python visual studio code, vscode python, vs code extensions, vscode extensions, visual studio code tutorial, vscode tutorial, visual studio code extensions, vs code extension, visual studio code setup, vscode setup, vscode python setup, python programming projects, python vscode setup, python vscode tutorial, python vscode mac, python vscode tips, visual studio code python, Vs code python setup
Id: fj2tuTIcUys
Channel Id: undefined
Length: 15min 50sec (950 seconds)
Published: Fri Dec 31 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.