For such a versatile, and useful language, many of Python's conventions are absolutely assinine.
@sylvainprive17549 ай бұрын
😱😱😱 how dare you ! (Joking)
@micahwright15785 ай бұрын
100% agree. Hinders' readability significantly. Idk why go hard at is None vs == None to kill programmer's efficiency with petty semantics
@huantian3 жыл бұрын
Random things: order of imports is recommended to be future imports, builtin packages, 3rd party modules, project specific imports, each separated with a newline. When you have a keyword argument with a typehint, you add the extra spaces: def foo(str: arugment = “hi”):
@ex0stasis723 жыл бұрын
I love the way that snake case looks in PEP-8. At first I was not excited about having to reach my fingers to do the awkward _ characters, but really, I only need to type those when I first declare the variable. Every other time I use that variable, I can just use my editor's autocomplete and just skip all the underscore characters and then just hit tab to accept the autocomplete.
@ncmathsadist2 жыл бұрын
If you use if foo[3:] == "bar" and you subsequently change "bar" to "barf", your code is broken unless you also edit the slice size. This is brittle. That's why Guido recommends endswith and startswith.
@BartWillems19693 жыл бұрын
Irony: in an article title "write proper python code" using "from os import path" as an example when Pathlib is by far the preferred solution for handling file paths
@yourdadsbestfriend71013 жыл бұрын
glad im not the only one who thought about that
@evanhagen70843 жыл бұрын
Is pathlib built in?
@pierre-manchon3 жыл бұрын
@@evanhagen7084 yes
@BartWillems19693 жыл бұрын
@@evanhagen7084 it’s in the standard library, just like `os` - no pip install required.
@nguyenanhquan44313 жыл бұрын
You missed the point. He was just giving an example that if you import multiple things from the same module then you should put them on the same line according to PEP8.
@sumitpatidar31433 жыл бұрын
Unconsciously I follow all pep8 style guide you have discussed in this video 😄
@danub55513 жыл бұрын
same lmao i thought i was the only one
@satyampatel37133 жыл бұрын
ah yes pycharm does annoy with those squiggly lines
@Markyroson3 жыл бұрын
Camel case: aka how you spot people who started in other programming languages and have a hard time breaking the habit in Python 😂
@sucman16843 жыл бұрын
actually, i started in python and started with camelcase because that’s how i used to write my usernames in games.
@เมทินีคํามี-ข8ป2 жыл бұрын
Glyyy Yvvbg G Yep
@Jay_06052 жыл бұрын
Me because I started with java and javascript
@FADHsquared2 жыл бұрын
This is why you need a linter
@Iuigi_t Жыл бұрын
Camel case: How to future-proof your code, when you learn another programming language
@tadiwashangwa49313 жыл бұрын
I was actually researching on this thank you Tim
@SajidAli-wy1zs3 жыл бұрын
your channel is best. From bangladesh.
@tahirahmed963 жыл бұрын
Tim I'm beginner at python and overall new to programming your videos are helping me a lot. I'm really interested in data analysis can you please make some videos on this topic
@Cpt_Diabetes Жыл бұрын
Hi Tim, i'm very new to tech and a career changer, i just want to say that the content here is one of the best explanations i've found scouring the interwebs!
@zulucharlie524411 ай бұрын
Excellent, to-the-point summary of PEP8 convention. Thank you.
@ankitaburman54063 жыл бұрын
You are right now my most favourite person on this planet...❤️ Thanks a ton for all the learning videos
@Rachinter2 жыл бұрын
This video should have millions of views 💯❤️🔥
@typeterson83763 жыл бұрын
Unexpected banger. As the expression (roughly) goes: "any fool can write code that a computer can understand, the challenge is to write code that a human can understand"
@Landon_Hughes3 жыл бұрын
I swear every time I look something up, you release a new video on the subject lol Thanks!
@mohbkhaled6051 Жыл бұрын
The autoformat feature on save is just a life saver my code instantly looked X10 better by just saving the file
@akira_asahi2 жыл бұрын
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
@Richard_GIS Жыл бұрын
I do programming in python on a daily basis and i really do not follow most of the pep Guidelines as python itself is not really following their own standards too. The best tip you also mention is, consistency. I do camelcase for normal var, for class and function i follow the pep with the underscore.
@pietheijn-vo1gt Жыл бұрын
What do you mean python is not following their own standards? Maybe you can deviate from PEP if you work on projects by yourself, but if you work in a team you really all have to follow the same styleguide otherwise the codebase becomes a mess. So why not follow PEP. Most IDE's can automatically check for it as well.
@Richard_GIS Жыл бұрын
@@pietheijn-vo1gt no you missed the point, I do follow the pep, as in some cases it could cause follow up issues if you do not. But considering Naming vars and defs it is not that important but consistency through out the script. When you write camel case var instead of underscore, no Big deal. In bigger projects you do follow the standard AND what the team deside, if there is a preference to write vars like this and that. I am really only referring to naming, nothing more ore less. If a programmer cannot read that, he /she is maybe not a programmer. The key word is consistency. Regarding there own standards, when you read the peps its sometimes a mess what is proposed and what not, what is adopted what not, sometimes it changes..i found it quit hard to read. I read one pep where python itself was not consitent - but sorry i cant remember what was it exactly.
@pietheijn-vo1gt Жыл бұрын
@@Richard_GIS I missed the point? You literally said "i really do not follow most of the pep Guidelines". Maybe you missed the point? I think every team should follow PEP and only deviate if there is a very good reason to do so, everybody agrees and the code linters validate the deviation too. I have contributed to a few open source projects and they tend to use linters that simply reject your commits if it doesn't pass PEP. I haven't found anything inconsistent in PEP so I wouldnt know what you are talking about. But on the other hand PEP is very comprehensive and humans can make mistakes so it wouldn't be weird if there were a few inconsistencies. If you spot them, just report it.
@therzook3 жыл бұрын
Yep, defo show it in work tomorrow... our team's coding is like NY subway wall, snake here, camel there, pascal on top and indentation may vary a lot.... Not to mention those long strings punching through the sides of 2 screens...
@zachfenton6083 жыл бұрын
this is awesome and explained well why these rules are used
@roydadancegod3 жыл бұрын
Also could you cover what to do for parameter and return type and the spacing for it? For example def function(a:int, b:list) -> list
@peschebichsu3 жыл бұрын
Amazing video, was wishing for a while you talk about it! One thing about the comments (ca. 21:55): Is there a convention, when the comment should be on the same line as the code and when it should be on a new line above it?
@paulzupan37322 жыл бұрын
There's no real convention for it, you basically just have to use your own discretion. One way that I decide which one to do is that if I'm trying to write a comment about a block of code, I put the comment above the block of code, but if there's something I want to say about a specific line of code, then I just put it on the same line.
@sergiomendoza68332 жыл бұрын
Great vid! Tim!
@goodmanshawnhuang3 ай бұрын
thanks a lot Tim for sharing this, I nearly broke all the rules😅, will apply to my next project though.
@richardcasey443911 ай бұрын
This is so important for readability
@therabidpancake1 Жыл бұрын
Just some random information I find that when I use double quotes that it allows me to use words like in or is . For example print("spike is a good dog ") . Indentation in python doesn't make a lot of sense to me . I know everything after the colon is indented but what I am talking about is why . I tried to have a buddy of mine explain it to me but it is still clear as mud . He says that it executes each line of code in order of the indentation . While that may be true it does not make a tone of sense . So what does the computer recognize def blank(): it would throw an error if I didn't write pass .
@bartugonulalan3 жыл бұрын
when he says "is not not not is " my 5 years old brain: **giggles**
@FADHsquared3 жыл бұрын
It is what it is
@andregarvin5529 Жыл бұрын
If x is false then the if statement will not trigger. only if the value is True or True equivalent
@melissaleigh30133 жыл бұрын
Amazing and Tim you are glowing
@Schnieker3 жыл бұрын
What about numbers? Can i name my variable test_1 or should i name it test_one?
@georgeseese2 жыл бұрын
Thanks for your expertise. At 22:35 it appears that you're saying if x = False or if x = 0, "if x:" will trigger. Isn't it the opposite? The shorthand "if x:" refers to True or something > 0, depending on the object reference.
@markoburak654910 ай бұрын
that's right, it should be if not x:
@emaddeve203 жыл бұрын
Wow this is vedio is so useful. Thank You Tim
@Queso7913 жыл бұрын
Thank god, a list of my fav youtuber 😎👌, keep up Tim.
@Lunolux3 жыл бұрын
nice i try to use more often convention name when i'm programming now, not very easy
@codingcrashkurse64293 жыл бұрын
Won´t get as many views as normally, but this is such an important topic!. I always get crazy when I see people coding x == None or even worse: try: x() except: pass
@Chemasaurus3 жыл бұрын
Wait, what's wrong with if x == None:
@mmbaguette15203 жыл бұрын
@@Chemasaurus It's faster to do *if (type(x) is int)* for example.
@Chemasaurus3 жыл бұрын
@@mmbaguette1520 But is there anything wrong with if x == None? Is it any different than if x is None?
@Joe-zg9eq3 жыл бұрын
whats wrong with try: [CODE] except: pass I use that a lot
@inakiarias74653 жыл бұрын
@@Joe-zg9eq If you are trying something and it fails, you should handle the errors, ideally. At least you would log or state what's the error that happened. But passing after failing in a try block is considered very bad because of that.
@umeshlab9873 жыл бұрын
This is useful for timathon
@nickvledder3 жыл бұрын
How about: pip install pycodestyle?
@AI-tg2by3 жыл бұрын
Love your vids! Could you do any about when you would use classes because I do get confused slightly.. maybe through doing a project - that would be ace!
@Dante-nu5cn3 жыл бұрын
Yes please! Great idea, I was just thinking about that!
@alagappank12423 жыл бұрын
Tim , some Tutorial for Data Science please....
@inselmanu3 жыл бұрын
Danke Tim und Grüße aus Deutschland
@TheFootballPlaya3 жыл бұрын
i didn't know about the startswith thing either, good to know. i've seen it around used a lot. question though, for function names that are multiple words, do these act similarly to variable names as in they are snake case as well, or is there some other way of denoting functions as opposed to variables? also, do we treat lambda functions any differently in this regard if they are stored in a variable?
@ismahelo3 жыл бұрын
What theme and font do you use for VS Code? By the way, very useful tutorial!
@aduomas59723 жыл бұрын
Following.
@luul46833 жыл бұрын
.
@kekkaigenkei3 жыл бұрын
Theme: Monokai Font: I think it's the default Consolas The theme enables the font italicizing on function / class declaration
@wongkingshun2 жыл бұрын
I think it is much more easier for viewers to follow a 25 to 30 mins videos long video rather than a 6 videos long video. And subdivide them into different small topics
@bijeshmohan3 жыл бұрын
How should I order my imports?
@fastrockstar17053 жыл бұрын
Imports should be grouped in the following order: 1. Standard library imports. 2. Related third party imports. 3. Local application/library specific imports.
@bijeshmohan3 жыл бұрын
@@fastrockstar1705 should I order each section alphabetically?
@fastrockstar17053 жыл бұрын
@@bijeshmohan That's up to your liking.
@captain_trips9943 жыл бұрын
awesome video. thank you
@AfshinDavoudy2 жыл бұрын
Black formatter changes "x = x*2 + 1" to "x = x * 2 + 1". So, it is not based on PEP8. am I right?
@Louis16261 Жыл бұрын
The PEP8 maximum line length is 79 chars, not 80.
@rubaokiller8 ай бұрын
what about if __name__ == "__main__": using double equal signs ?
@terrisquire19403 жыл бұрын
Thanks for this!
@DefWorlds3 жыл бұрын
It would be great to see some best practices re how best to break long lines and line up chains of method calls.
@kinghenry2385 ай бұрын
Whats wrong wirh the open exceptions in try?... Its kind of nice to catch exceptions that you dont know about sometimes.
@muhammadanique22563 жыл бұрын
Hey Tim ! Please do a react and Django project , please 🥺
@greg_pizzatower Жыл бұрын
code is code
@baptistearnould23132 жыл бұрын
What text color is he using on VCStudio ?
@orangecoat38482 жыл бұрын
Monokai, very popular
@omar729993 жыл бұрын
Hey man, this is random but what chair is that? I have the exact same desk as yours (the table top and Alex from IKEA) and have been struggling to find a chair that fits them for a while now. Is your chair comfortable? if so do you mind giving me a link so I can get a similar one?
@TechWithTim3 жыл бұрын
It’s a great chair, absolutely love it. It’s called a Herman Miller Aeron chair, I have the classic version but they now have an updated one with ever more features. I also have a head rest which I bought separately
@omar729993 жыл бұрын
@@TechWithTim alright thanks a lot man!
@Nordlys0 Жыл бұрын
The new updated chair's head rest can be moved by a 4spaces/tab distance each time to fit the correct indentation of the head rest angle.. hehhe
@santoshkumargouda60333 жыл бұрын
From where i get the code?
@SavorkoTime3 жыл бұрын
Thank you, after this video almost all bugs on my project were closed! And they fire me, coz they dont need python dev anymore...
@adithmanu37153 жыл бұрын
You can use Ctrl + J to hide the terminal
@ThEBengaliFriEnDz3 жыл бұрын
can anyone tell me wich theme tim uses in vs code?
@luul46833 жыл бұрын
which font is it?
@Noone-lw6ge3 жыл бұрын
You should be using spaces for indentation. Me who just uses the default auto-indent from sublime
@omerfi3 жыл бұрын
I think you should make a playlist about clean code and add this video to the playlist
@Klannahar3 жыл бұрын
What about class variables? Same as normal variables? Is this style used in any language? "myVariableName"
@sherluck_code3 жыл бұрын
The class variables should still be the same as the normal variables, in this case snake case, but if you mean the class name the class name should be a pascal case like class ClassName
@Klannahar3 жыл бұрын
@@sherluck_code I ment like self.my_variable, and the question part is just in general. Idk i remember somewhere i saw that type, but not sure it was just a user preference or it was specific to other programing language.
@sgt3913 жыл бұрын
When I break code conventions I know I'm writing shitty buggy code that I'm going to rewrite in the future
@virgile89573 жыл бұрын
the name for the all-caps snake case is screaming snake case.
@stivunnikolov59413 жыл бұрын
Is someone really pressing 4 spaces instead of tab?
@lemmyboy41073 жыл бұрын
Just make a makro that 1 tab = 4 spaces xd.
@stivunnikolov59413 жыл бұрын
@@lemmyboy4107 you are very smart boy.... I hope smart enough to feel the irony...
@lemmyboy41073 жыл бұрын
@@stivunnikolov5941 i mean i can send that back. Most ides would brake without a dedicated tab.
@adrielbradley66773 жыл бұрын
I always use single quotes for single words 'hello' and then double quotes for longer strings.
@Sciencedoneright3 жыл бұрын
It saves time
@kristjanbradac89313 жыл бұрын
Can someone tell me what colorsheme is this, pls? It's like in sublime text3. :D
@orangecoat38482 жыл бұрын
Interviewer: "Why were you fired from your previous job?" Me: "Something i did at work" Interviewer: "Which was ?" Me: "Indent camel case with tabs in python in lines with more than 80 lines" Interviewer: "Next please"
@eyal43 жыл бұрын
pleas more open cv :)
@AngelicaGoodwin-d4e11 ай бұрын
cool video)
@Kay-qg1vn2 жыл бұрын
That's why i use pycharm 😌
@pietheijn-vo1gt Жыл бұрын
Guido is pronounced Gi-do not Gwi-do
@albertojlorenzorosario27592 жыл бұрын
camelCaseIsKing change my mind
@0x007A3 жыл бұрын
The most annoying Python code, regardless of its potential usefulness, is poorly (or completely abscent) commented source code.
@ΑνώνυμοςΧρήστης-ρ9ζ3 жыл бұрын
Self-explanatory code does not require comments
@ed-xs3pu3 жыл бұрын
@@ΑνώνυμοςΧρήστης-ρ9ζ required... No. But comments on WHY the code is there is quite useful. And comments are much easier for your brain to parse.
@sscapture Жыл бұрын
@@ΑνώνυμοςΧρήστης-ρ9ζ It does
@reda29100 Жыл бұрын
17:17 I'm sorry for the mayhem I'm gonna stir, but my woke professor says white spaces are always problematic.
@JorgeLuis-ts6qp3 жыл бұрын
One of the things I hate the most from Python y how much you must trust the developers. It's incredible there is no way of making a variable constantant!!
@ed-xs3pu3 жыл бұрын
I'm new to python and coding. Is there value to having it defined as a constant vs. just capitalizing it. If it's capitalized then you should know not to change its value right? Or is there something else to it?
@ayushganguli13593 жыл бұрын
I am still a noob but in my limited experience its best not to use black in case of a collaborative project with git. Goodluck merging commits on using black. Auto format makes your life hell on merge
@harrypotter68943 жыл бұрын
mans holding onto that hair for dear life. time for a shave bro!!
@alexneigh70895 ай бұрын
It is called SCREEMING_SNAKE.
@dimitriosdesmos46993 жыл бұрын
thanks very nice
@soulninjadev3 жыл бұрын
@Hethat take notes :mhm:
@tablenkov49933 жыл бұрын
Thanks.
@herojedrus25673 жыл бұрын
you did not tell what to do when `from module import thing1, thing2, thing3, thing4, ...` is too long :(
@ivernik3 жыл бұрын
Thank god for pycharm. 😅
@christianemden76373 жыл бұрын
The rules on the use of white spaces seems to be rather inconsistent.
@omanavarghess68473 жыл бұрын
If you want to break the rules, break them consistently.
@codingboy22543 жыл бұрын
Is this guy reading minds, I was literally watching a seminar by uncle Bob on writing clean code , and he posts this video . CREEPY!!!!!!!!!!!!!!!!!!!!!!!!
@RoyalTutorial3 жыл бұрын
Anyone here uses Pydev with Eclipse? Should I make the move to Visual Studio?
@tooru3 жыл бұрын
bruh
@Raja-tt4ll2 жыл бұрын
Nice
@demerion3 жыл бұрын
Can we name a variable "var1"? Or would snake_case be "var_1" in this case? What is the convention when using numbers?
@chilly1113 жыл бұрын
I would use more descriptive names and if I needed variables of the same name indexed I would prob store them as a list instead: vars = ['x', 'y', 'z'] and access them like print(vars[2])
@meloman709411 ай бұрын
Thank you very much for the Russian subtitles!)
@donwald343610 ай бұрын
lol 80 columns, 19976 called they want their teletype terminals back.
@Sabre5106 Жыл бұрын
Looks like I severely disagree with convention. camelCase is supreme, underscores are ugly and I will never use them.
@eylonemuskson41773 жыл бұрын
_Once you go Black, do you don't...ever, have to worry about messy Python code again...._ I'm a poet.