How To Write Cleaner Code - A Practical Example

  Рет қаралды 84,684

Tech With Tim

Tech With Tim

Күн бұрын

Welcome back to another video! In this video, I'll be showing you how to write cleaner code. I'll be going through some script that I wrote a few years ago and clean it up. We'll just be doing some basic things to make the code look cleaner and easier to read.
💻 AlgoExpert is the coding interview prep platform that I used to ace my Microsoft and Shopify interviews. Check it out and get a discount on the platform using the code "techwithtim" algoexpert.io/techwithtim
📄 Resources 📄
Pygame Projectile Motion Tutorial: • Pygame Tutorial - Proj...
Original Code: github.com/techwithtim/Projec...
⭐️ Timestamps ⭐️
00:00 | Introduction & Context
01:26 | Code Output Demo
01:57 | Writing Clean Code!
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
💰 Courses & Merch 💰
💻 The Fundamentals of Programming w/ Python: tech-with-tim.teachable.com/p...
👕 Merchandise: teespring.com/stores/tech-wit...
🔗 Social Medias 🔗
📸 Instagram: / tech_with_tim
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-ruscica-82631b179
🌎 Website: techwithtim.net
📂 GitHub: github.com/techwithtim
🔊 Podcast: anchor.fm/tech-with-tim
🎬 My KZbin Gear 🎬
🎥 Main Camera (EOS Canon 90D): amzn.to/3cY23y9
🎥 Secondary Camera (Panasonic Lumix G7): amzn.to/3fl2iEV
📹 Main Lens (EFS 24mm f/2.8): amzn.to/2Yuol5r
🕹 Tripod: amzn.to/3hpSprv
🎤 Main Microphone (Rode NT1): amzn.to/2HrZxXc
🎤 Secondary Microphone (Synco Wireless Lapel System): amzn.to/3e07Swl
🎤 Third Microphone (Rode NTG4+): amzn.to/3oi0v8Z
☀️ Lights: amzn.to/2ApeiXr
⌨ Keyboard (Daskeyboard 4Q): amzn.to/2YpN5vm
🖱 Mouse (Logitech MX Master): amzn.to/2HsmRDN
📸 Webcam (Logitech 1080p Pro): amzn.to/2B2IXcQ
📢 Speaker (Beats Pill): amzn.to/2XYc5ef
🎧 Headphones (Bose Quiet Comfort 35): amzn.to/2MWbl3e
🌞 Lamp (BenQ E-reading Lamp): amzn.to/3e0UCr8
🌞 Secondary Lamp (BenQ Screenbar Plus): amzn.to/30Dtafi
💻 Monitor (BenQ EX2780Q): amzn.to/2HsmUPZ
💻 Monitor (LG Ultrawide 34WN750): amzn.to/3dSD7tS
🎙 Mic Boom Arm (Rode PSA 1): amzn.to/30EZw9m
🎚 Audio Interface (Focusrite Scarlet 4i4): amzn.to/2TjXsih
💸 Donations 💸
💵 One-Time Donations: www.paypal.com/donate?hosted_...
💰 Patreon: / techwithtim
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
⭐️ Tags ⭐️
- Tech With Tim
- Clean Code
- Write Clean Code
- Coding
- How To Write Clean Code
⭐️ Hashtags ⭐️
#TechWithTim #CleanCode

Пікірлер: 151
@fabiosabbion4930
@fabiosabbion4930 2 жыл бұрын
9:40 you forgot to replace newx and newy at line 33
@jamessmith4229
@jamessmith4229 6 ай бұрын
I appreciate code being refactored to a more readable/maintainable state. I am a retired mainframer and once had to maintain a COBOL program written by one with an incomplete understanding of the language. I removed 5,000 (yes, 5,000) lines of unneeded code. The initial program was 50,000 lines. removing those lines improved to maintainability quite a bit. Then doing the other concepts you illustrate made a huge difference.
@HappyFlamingToaster
@HappyFlamingToaster Ай бұрын
I feel like there isn't enough content like this on KZbin, love the pace you go through all of these changes, it's really helpful for me. Thank you!
@coderanger7708
@coderanger7708 2 жыл бұрын
Tim, the general rule of thumb is to never touch a finished project code which is working fine.
@coderanger7708
@coderanger7708 2 жыл бұрын
@@8koi139 I just meant it as a joke. You should visit your old code to make optimizations if you are confident you can do it without repercussions and you know what you are doing. But just make sure you have a back up of that code base.
@geoafrikana
@geoafrikana Жыл бұрын
@@coderanger7708 Now you ruined the joke.
@coderanger7708
@coderanger7708 Жыл бұрын
@@geoafrikana sorry mate, there was a dude who took this seriously, so I had to explain him/her the real thing to do
@AI-tg2by
@AI-tg2by 2 жыл бұрын
This video was exactly what I needed! Nobody else is doing this. Could you make a similar video about why code needs to be updated, how often etc, with practical examples
@jarrodburns6339
@jarrodburns6339 2 жыл бұрын
He's simply grown as a developer. Updating this code was a great way to showcase some of the tips he has learned in the years since creating the video(allowing you to avoid the pitfalls he fell victim to.) In short, I would say, update your code if you believe it needs to be updated.
@talkingbirb2808
@talkingbirb2808 Жыл бұрын
ArjanCodes does code refactoring
@davidiswhat
@davidiswhat 2 жыл бұрын
I need to look at your backlog of videos. I found this educational and I didn't get as bored as usual. I sometimes can't focus when learning about programming topics.
@MaximRovinsky
@MaximRovinsky 2 жыл бұрын
Thanks Tim. Useful examples, especially for beginners like me
@elpython3471
@elpython3471 2 жыл бұрын
9:43-10:17 For line 35, it's supposed to be 'return new_x, new_y'
@jordinkolman
@jordinkolman 5 ай бұрын
I was looking through the comments like “surely I’m not the only one who noticed he broke his code”😂😂😂 been there
@evagiacomello8696
@evagiacomello8696 2 жыл бұрын
This is on a whole new level of programming asmr
@hasnaouiacademy7899
@hasnaouiacademy7899 2 жыл бұрын
Tim, you are the best teacher on youtube. If you can make a data structure course, this will be helpful. thank you.
@rishabhmishra2249
@rishabhmishra2249 2 жыл бұрын
Thanks Tim! I just realised how bad my code was :)
@zsobraal
@zsobraal 2 жыл бұрын
13:46 the problem here is a ZeroDivisionError because it's dividing by (x - pos[0]). It can be changed to the function math.atan2(), which handles the division and zero division errors, like so: angle = math.atan2(y-pos[1], x-pos[0])
@totalermist
@totalermist 2 жыл бұрын
atan2 also allows to skip the quadrant selection below the atan call
@MrBanarium
@MrBanarium 2 жыл бұрын
Also noting than while the except should have explicitly mentioned the ZeroDivisionError, using a try-except block rather than an if-else block is perfectly fine and pythonic here, and definitively the recommanded way to handle such situations. As one says, "it's easier to ask for forgiveness than permission".
@tiagodagostini
@tiagodagostini Жыл бұрын
@@MrBanarium But in real world it is not, that has a HUGE performance hit when you are using performance oriented languages. It is a BAD practice to use exceptions for something you could have easily testes. I would NOT hire someone that do it. The "ask for forgiveness" is only good on HIGHER level abstractions, i.e out of the inner loops of the code.
@MrBanarium
@MrBanarium Жыл бұрын
@@tiagodagostini Yes, but we're talking about Python here, which *is* a high level language. In Python, using exceptions like this is recommanded and considered best practice. Exceptions in python are cheap performance-wise specifically because of this. If you need to hire a python programmer, they need to know the language-specific best practices and features, not just the general dogma, and understand why it's different here. Ignoring python best practice will indeed result in performance loss.
@tiagodagostini
@tiagodagostini Жыл бұрын
@@MrBanarium true but unfortunatelly the developers take a practice sometimes too much to the heart and do nto stop to think WHY in such a language it makes sense, so they apply it blindly.
@somitragupta2721
@somitragupta2721 2 жыл бұрын
Good explaination Tim, though I just wish to share that we can also use black and Flake8 for beautification of code, such as identation, spacing, or unncessary imports. But still defining global variables and function arguments is still someting the programmer has to do.
@raghavareddychilakala657
@raghavareddychilakala657 2 жыл бұрын
Nice, yesterday I was looking for something about selenium and I seen your playlist about selenium. and then within fraction of seconds I am a subscriber to you.
@gvikram18
@gvikram18 2 жыл бұрын
Thank youtube Algorithms 😁 Tim had nothing to do with it
@martimmartins6773
@martimmartins6773 2 жыл бұрын
You forget type hints!!, and I think if you had everything separated into functions it would be a little cleaner.
@chickenjoy
@chickenjoy 2 жыл бұрын
In our company, in naming variables, we use l (local) or g (global) for variables, plus c/n/d/l (character/number/date/logical type). E.g. lcName, lnAge, ldBirthday, glActive, gcCompany so it will be easier to distinguish what data type a variable is.
@chickenjoy
@chickenjoy 2 жыл бұрын
@@mxmdabeast6047 I use vfp though, not python but I think logical and boolean are pretty much the same. The choice of naming convention is yours, depends on what you think suits you best.
@danielismyhandle
@danielismyhandle 2 жыл бұрын
A more pythonic version would be to just use the typing system like this instead. name: str, age: int, etc and don't use globals. There is almost always another way.
@octobotdev
@octobotdev Жыл бұрын
Loved the video and the resources! Thanks for sharing
@harshprajapati9686
@harshprajapati9686 2 жыл бұрын
Loved this man! Thanks🙌
@itaychechik5125
@itaychechik5125 2 жыл бұрын
The try-except case is a really good one to demonstrate the importance of clean code - had you used a more specific exception (ZeroDivisionError), you would have easily known what the error could be there, without having to remember trigonometry! :) In my opinion the point there might have been slightly missed - it isn't about sticking to best practices with an if-else statement, it's about making the code easier to handle, especially when returning to it after several years Anyway great vid, love the uploads lately :)
@michielboswijk7260
@michielboswijk7260 2 жыл бұрын
Might be fun to do a type of competition where you ask your viewers to refactor a piece of code like that. Then we could all learn from the best out of those.
@armsjarbc8597
@armsjarbc8597 2 жыл бұрын
Keep up the good work Mr. Tim
@hamkoqaasim7177
@hamkoqaasim7177 2 жыл бұрын
Thanks you taught me a lot of things
@atomgutan8064
@atomgutan8064 2 жыл бұрын
Very good video! Thanks!
@mahanaatma910
@mahanaatma910 2 жыл бұрын
thank you for this video it helped me a lot
@enriquellerena4779
@enriquellerena4779 2 жыл бұрын
Thanks for the vid, it helps a lot
@The0Koller
@The0Koller 2 жыл бұрын
Wonderful video, I wonder if you can discuss a better way to address "if elif" and "if if" blocks
@rogercheng1294
@rogercheng1294 2 жыл бұрын
15:50 also forgot to pass golf_ball as parameter in redraw_window(). btw, great video :)
@emaddeve20
@emaddeve20 2 жыл бұрын
This video is so helpful.
@maxpoppe
@maxpoppe 2 жыл бұрын
even though you forgot like 5 things, you made your point clear and that's what this video is about, so great video Maybe you could've pointed out that making comments is good practice, also maybe could've said that if you've a lot of and's that you can put them below each other instead of next to eachother and maybe try and avoid if statements, they're not efficiënt and also in a lot of situations not the cleanest solution.
@FritsvanDoorn
@FritsvanDoorn 2 жыл бұрын
Interesting. Thank you
@paulosullivan3472
@paulosullivan3472 2 жыл бұрын
I am not so bothered by convention but I totally agree with being consistent whatever you decide to use. I would also prefer to have separate functions for the various code blocks personally but as long as others and of course _you_ can understand your code when you have to revisit it to make changes months or even years later that's what matters most.
@Kebabrulle4869
@Kebabrulle4869 2 жыл бұрын
I agree. I use snake_case for functions and methods, Pascal_Case for classes, just like convention, but I use camelCase for variables. Imo makes it easy to see what everything is, and it also feels natural to me to keep variable names short.
@awwabasad1117
@awwabasad1117 2 жыл бұрын
Hey this is great, your code is A++, but another thing to make your code even better is to add a little more comments throughout your exceptional code!😎😇👍✌️😸
@fredericoamigo
@fredericoamigo 2 жыл бұрын
Super helpful vid!
@muhammadmustafa3158
@muhammadmustafa3158 2 жыл бұрын
good stuff tim !
@itsahmd295
@itsahmd295 2 жыл бұрын
You're like telling me i have clean code, Thanks man Lol
@TD-ph3wb
@TD-ph3wb 2 жыл бұрын
Hey Tim, one question, what made you use Sublime Text instead of VS Code? Great video btw!
@juliansteden2980
@juliansteden2980 2 жыл бұрын
Great video as always! =) However, I do not like the color refactoring (BLACK, GREY, WHITE). I would much prefer semantic colors like: COLOR_PRIMARY, COLOR_SECONDARY, COLOR_ACCENT or alternatively COLOR_BACKGROUND, COLOR_LINE, COLOR_BALL. Imagine you want to update your app’s color scheme and use a green ball. You would have to either change the value of variable WHITE to green (lol) or introduce a new variable GREEN and find all places in your code where you color the ball.
@cambridgebreaths3581
@cambridgebreaths3581 2 жыл бұрын
Excellent
@RomIlay
@RomIlay 2 жыл бұрын
Would to see how to write suitable comments to the code. Also I have been looking alot recently for ways to improve the look of the code so thanks for that. It didn't show me much new but still stuff to improve
@eversonmay
@eversonmay 2 жыл бұрын
More clean code videos!
@injector6926
@injector6926 2 жыл бұрын
Best programming chanellll
@mohakbajaj4235
@mohakbajaj4235 2 жыл бұрын
Well on the context of cleaning the code he have to debug it too 😂😂 as he created some errors while cleaning
@markmadhukar9011
@markmadhukar9011 2 жыл бұрын
Gr8 vid as usual : )
@user-rz7mx8ns9n
@user-rz7mx8ns9n 2 жыл бұрын
thanks bro 👍🙂
@Flashxyz123
@Flashxyz123 2 жыл бұрын
Yeah i put notifications on 😎
@frankanon798
@frankanon798 2 жыл бұрын
Perhaps consider demonstrating mypy (with type hinting) and flake8 from the command line. These are very powerful tools.
@frankanon798
@frankanon798 2 жыл бұрын
But really great work giving some ideas about how to refractor code!
@revolutionizer0099
@revolutionizer0099 2 жыл бұрын
fabulous
@BGxBlagiw
@BGxBlagiw 2 жыл бұрын
Dude you are gold for this sphere very very well explained 👍👍 for the young guys don't worry your brain can't take too much unless you are giny who is rare, but who knows anyway gg Timaty 🙃✌
@romandang3903
@romandang3903 Жыл бұрын
Thanks for an explaination Tim. I like a theme you using in your vscode. Can you share a name of theme Tim?
@gradientO
@gradientO 2 жыл бұрын
Any book recommendations?
@aim2986
@aim2986 2 жыл бұрын
21:14 I wouldnt put spaces between operators which have priority when other operators present in the same line. So that you can visualize operator priorities. You decide, which one looks better: b = 2*a + 3 b = 2 * a + 3
@aim2986
@aim2986 2 жыл бұрын
@@mxmdabeast6047 In large assignments you can use paranthesis so they dont look strange. Which one looks better: b = (3**5 * 2) + 7 b = 3 ** 5 * 2 + 7 In the latter one, doesn't "5 * 2" stand out? If you focus on "3 ** 5", doesn't "2 + 7" stand out? If the assignment is even larger and requires nested paranthesis, maybe you should seperate the assignment to a few lines: b = 3**5 * 2 b = b + 7 I think these approaches are pretty straightforward. So you wouldn't really think much about whether you should use a space or not. Also, for large assignments, being explicit is always better.
@penn_asc
@penn_asc 2 жыл бұрын
Beginner here. Is commenting on the code would be seen as bad coding practice? And if not necessarily, what is considered good commenting?
@credoboyofficial
@credoboyofficial 2 жыл бұрын
It works 100%
@bhavdeepsaragadam
@bhavdeepsaragadam 2 жыл бұрын
Nice vid, Which video editor do you use??
@shridumanish3506
@shridumanish3506 2 жыл бұрын
😂
@samuelhulme8347
@samuelhulme8347 2 жыл бұрын
@@ibijon sublime text is a code editor not a video editor lol
@ibrahimkabeer5089
@ibrahimkabeer5089 2 жыл бұрын
Cool
@user-hd8tg4em2n
@user-hd8tg4em2n 2 жыл бұрын
The return on line 33 wasn't changed to reflect the new variable names.
@antmitchell9930
@antmitchell9930 2 жыл бұрын
And the program was not run afterwards - Bad Tim, Bad. Love the channel
@gfjwgldwzqfdkgdhdfdjledkdd9856
@gfjwgldwzqfdkgdhdfdjledkdd9856 2 жыл бұрын
nice
@bigtymer4862
@bigtymer4862 2 жыл бұрын
Make some rust tutorials
@user-wc1sm8cj8s
@user-wc1sm8cj8s 2 жыл бұрын
agreed with this guy
@220SouthlandAve
@220SouthlandAve 4 ай бұрын
Beyond the Basic Stuff with Python: Best Practices for Writing Clean Code (by Al Sweigart) is a really good book for this.
@willemvdk4886
@willemvdk4886 2 жыл бұрын
Tuple decomposition? Isn't it called unpacking? :)
@dzbicegaming2583
@dzbicegaming2583 2 жыл бұрын
What text editor or ide are you using?
@MatrixAbuz17
@MatrixAbuz17 9 ай бұрын
9:50 doesnt multiple returned values already get returned as a tuple? I always assumed putting parenthesis was more for just prettier code.
@leztat3183
@leztat3183 2 жыл бұрын
Yei ;)
@shawnbeans7389
@shawnbeans7389 2 жыл бұрын
you should try vim, trust me
@talkingbirb2808
@talkingbirb2808 Жыл бұрын
I suppose all those missing white spaces and amount of empty lines between functions could be handled with something like autopep8, black or yapf
@binaprajapati7709
@binaprajapati7709 2 жыл бұрын
What's this new theme? It's cool!
@frankanon798
@frankanon798 2 жыл бұрын
Looks a bit like "one dark pro"?
@binaprajapati7709
@binaprajapati7709 2 жыл бұрын
@@frankanon798 ohk, thanks!
@wgalloPT
@wgalloPT 2 жыл бұрын
Do you think you could help me with a pycharm opencv project? im not a coder and the code is ready but I dont know how to put it together to run it...
@javierpadillah
@javierpadillah Жыл бұрын
What program is he using to use python? For example, is it Spyder or what is it?
@chrishaselden
@chrishaselden 2 жыл бұрын
@20:27 could you do: and !shoot
@hrushikeshthorat1075
@hrushikeshthorat1075 2 ай бұрын
11:54 you forget to replace (0,0,0) by BLACK on line 21
@user-nc3rc7sk9p
@user-nc3rc7sk9p Жыл бұрын
Why not use an ENUM for colours?
@Skeap11
@Skeap11 2 жыл бұрын
redraw_window missing 2 positional arguments :)
@Cookie-mv2hg
@Cookie-mv2hg 2 жыл бұрын
I'm currently working on a puzzle game, which users can grab the element pieces to fill in a grid. Using the Tetris method to create grid and interface, so far so good, but I cant find any tutorial where I can grab an object (NOT an image) on screen. How can I drag elements that is in pygame?
@Kebabrulle4869
@Kebabrulle4869 2 жыл бұрын
I’m not very experienced in pygame, but if there isn’t some fancy way to do it, I’d probably just use the pygame.mouse.get_buttons() method, and move the piece to the mouse’s position while the left mouse button is pressed. Additionally, you could give the piece a center variable that you update when the left mouse button is pressed (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1) so that it doesn’t snap unnaturally when you press it. If you need it to snap in place when you release the button, you can do that while handling events: event.type == pygame.MOUSEBUTTONUP and event.button == 1.
@PaulTheEldritchCat
@PaulTheEldritchCat 2 жыл бұрын
Sorry, but the first striking thing that this code needs is comments. You can embellish your code all you like with spacing and snake casing, but comments will make it more readable and easy to understand (and refactor).
@shawnbeans7389
@shawnbeans7389 2 жыл бұрын
did you get a editor ?
@lakshyapandey7869
@lakshyapandey7869 2 жыл бұрын
Who is your illustrator who draws the thumbnails ?
@devb8820
@devb8820 2 жыл бұрын
they dont draw the thumbnails, they make it with software
@stephenaustin3026
@stephenaustin3026 2 жыл бұрын
Great video, but it might have been a good idea to run the refactored code at the end to show that it still worked. I'm pretty sure you introduced some errors - for example you didn't change all the instances of newx and newy to snake case.
@soupnoodles
@soupnoodles 2 жыл бұрын
For most of these you couda just ran this in pycharm and it would have listed out all the format errors ;-;
@rubencid2575
@rubencid2575 2 жыл бұрын
One question: in the main loop, don't you need to see first events then movement and visualization?
@johannkrauter
@johannkrauter 2 жыл бұрын
Check Out the Python black package which helps you to clean code automatically
@invizii2645
@invizii2645 2 жыл бұрын
This is why you need a linter.
@vvhitevvabbit6479
@vvhitevvabbit6479 Жыл бұрын
Forgot to pass the new golf_ball variable when calling the find_angle fuction.
@peddiyuvaraj688
@peddiyuvaraj688 2 жыл бұрын
In line 25 you did not change (0, 0, 0) to BLACK :D
@d3stinYwOw
@d3stinYwOw 2 жыл бұрын
It's better most of the times to use try/except, because of "easier to ask for forgivness than for permission" or something it was going around :)
@kinfi4836
@kinfi4836 2 жыл бұрын
`import math` should be before `import pygame`, just in case you wanna follow the PEP 8
@champ_revolutionizer9924
@champ_revolutionizer9924 2 жыл бұрын
what is PEP 8?
@skyricq
@skyricq 2 жыл бұрын
@@champ_revolutionizer9924 pemdas
@MrBoooniek
@MrBoooniek 2 жыл бұрын
19:56 couldn't You put "if not shoot:" up in the "if event.type == pygame.MOUSEBUTTONDOWN and not shoot:" like that?
@elpython3471
@elpython3471 2 жыл бұрын
Yes, you could do that. He might have not done that because it's more confusing to read.
@georges.9545
@georges.9545 2 жыл бұрын
Great and helpful video, could you do a series on creating dapps on the ethereum blockchain?
@user-wc1sm8cj8s
@user-wc1sm8cj8s 2 жыл бұрын
I clicked this video and then..... "Do you wanna become a software engineer at Google?" Me: .....
@Soljarag5
@Soljarag5 2 жыл бұрын
I like camel case way better.... Not sure why python decided to use shake
@mat4x
@mat4x 2 жыл бұрын
If I have a single line after an if statement I write it as: greeting = 1 if (greeting) : print("Hello") else: print("Bye") Is this a good practice?
@Leo-er1up
@Leo-er1up Жыл бұрын
better to do a proper ternary operator one line if-else statement: greeting = 1 print("Hello" if greeting else "Bye")
@scriptles
@scriptles 9 ай бұрын
So you say camel case is wrong. Interesting facts about "snake case" as you call it. That's just unix style coding and its also used in other languages not just python. The reason it's not so popular is because the _ character on some monitors showed up as a " " character which looks like a space. I used to have a monitor even a few yeaers ago that was new and modern flat screen that did this as well. Using HDMI + tv also can make _ not show at times. So to prevent confusion it's usually avoided.
@TechWithTim
@TechWithTim 9 ай бұрын
its what's listed in the PEP8 style guide, not my opinion, pythons style guide...
@scriptles
@scriptles 9 ай бұрын
@@TechWithTimWhat I am saying is that calling it snake case is just renaming something that already exists rather then creating something unique of it's own. In programming, we often have different names for the same thing as people come from other languages. but style isnt exclusively owned by the language itself. I also noticed the video was lacking other big topics like gaurd clauses verses nesting which have more importance for readability. i may not be an expert but I have been programming for about 23 years now. i know a thing or 2 because I have seen a thing or 2.
@trillionthcousinofastone7024
@trillionthcousinofastone7024 2 жыл бұрын
I will never leave camel and pascal case
@_L30N74
@_L30N74 2 жыл бұрын
You forgot to replace the (0,0,0) at line 25 with the constant BLACK you created.
@KeithKazamaFlick
@KeithKazamaFlick Жыл бұрын
comments are useful
@dpxprhulc4xkl
@dpxprhulc4xkl Жыл бұрын
Instead of doing all this, why not just use a linter like flake8 / black which will fix a lot of the issues you fixed manually
@radhekrishn702
@radhekrishn702 2 жыл бұрын
Hi
@michealhall7776
@michealhall7776 2 жыл бұрын
More things Always add comments to your methods functions ball_path should be called path because you are repeating yourself when calling it Win, pos, vec are not obvious you need to state what these are and how they are used Your try block should have except Exception as e: print(e) so you know when an error happens golf_ball could be just ball, as you don't have any other types of balls on the field. Always copy and paste very names to avoid mistakes Tim made Always make a backup copy of the file before you refacter Add comments to complex logic so you can just read why its happening rather than how it happening run variable is uneeded as you are only using it once Add comments at the top to what this program does, potential issue and future ideas and also add links to common documents like pygame docs Your continue block was unneeded and will cause issues later when you have other mouse actions Add type checks using assert as a sanity check to make sure everything is the excepted type of thing. Especially using tuple deconstruction you will have add errors if pos happened to have a length of three for example. I typically write all of the function names in the document at the top of the page in a comment so I know what I'm dealing with when I open the project after a long time. Pretend you are writing the code for a future more retarded version of yourself.
@tcgvsocg1458
@tcgvsocg1458 2 жыл бұрын
Well i just finish 12 hour video when is the new one?
@binaprajapati7709
@binaprajapati7709 2 жыл бұрын
And why using atom here?
@IndellableHatesHandles
@IndellableHatesHandles 2 жыл бұрын
Snake case for functions? That looks a bit ugly.
Write Python Code Properly!
25:46
Tech With Tim
Рет қаралды 141 М.
Junior Vs Senior Code - How To Write Better Code
22:13
Web Dev Simplified
Рет қаралды 1,1 МЛН
Каха инструкция по шашлыку
01:00
К-Media
Рет қаралды 8 МЛН
Climbing to 18M Subscribers 🎉
00:32
Matt Larose
Рет қаралды 25 МЛН
Универ. 10 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:04:59
Комедии 2023
Рет қаралды 1,3 МЛН
5 RULES to Write Better Code
16:36
Andy Sterkowitz
Рет қаралды 44 М.
Cleaner Code: 3 Ways You Can Write Cleaner Code
7:41
Coding with Lewis
Рет қаралды 74 М.
CSS Anchor Is The Best New CSS Feature Since Flexbox
15:39
Web Dev Simplified
Рет қаралды 356 М.
10 Python Shortcuts You Need To Know
27:27
Tech With Tim
Рет қаралды 291 М.
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,3 МЛН
8 Python Coding Tips - From The Google Python Style Guide
17:12
ArjanCodes
Рет қаралды 153 М.
How To Actually Make $10k A Month Coding
14:54
Tech With Tim
Рет қаралды 78 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,5 МЛН
Don't Write Comments
5:55
CodeAesthetic
Рет қаралды 770 М.
Python Generators Explained
28:37
Tech With Tim
Рет қаралды 144 М.
Каха инструкция по шашлыку
01:00
К-Media
Рет қаралды 8 МЛН