How To Write Cleaner Code - A Practical Example

Sdílet
Vložit
  • čas přidán 12. 07. 2024
  • 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 CZcams 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

Komentáře • 151

  • @fabiosabbion4930
    @fabiosabbion4930 Před 3 lety +65

    9:40 you forgot to replace newx and newy at line 33

  • @jamessmith4229
    @jamessmith4229 Před 6 měsíci +2

    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.

  • @coderanger7708
    @coderanger7708 Před 3 lety +69

    Tim, the general rule of thumb is to never touch a finished project code which is working fine.

    • @coderanger7708
      @coderanger7708 Před 3 lety +8

      @@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 Před rokem

      @@coderanger7708 Now you ruined the joke.

    • @coderanger7708
      @coderanger7708 Před rokem +3

      @@geoafrikana sorry mate, there was a dude who took this seriously, so I had to explain him/her the real thing to do

  • @HappyFlamingToaster
    @HappyFlamingToaster Před 2 měsíci

    I feel like there isn't enough content like this on CZcams, love the pace you go through all of these changes, it's really helpful for me. Thank you!

  • @elpython3471
    @elpython3471 Před 3 lety +11

    9:43-10:17 For line 35, it's supposed to be
    'return new_x, new_y'

    • @jordinkolman
      @jordinkolman Před 6 měsíci

      I was looking through the comments like “surely I’m not the only one who noticed he broke his code”😂😂😂 been there

  • @martimmartins6773
    @martimmartins6773 Před 3 lety +36

    You forget type hints!!, and I think if you had everything separated into functions it would be a little cleaner.

  • @AI-tg2by
    @AI-tg2by Před 3 lety +16

    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 Před 3 lety +3

      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 Před rokem +1

      ArjanCodes does code refactoring

  • @evagiacomello8696
    @evagiacomello8696 Před 3 lety +3

    This is on a whole new level of programming asmr

  • @MaximRovinsky
    @MaximRovinsky Před 3 lety +1

    Thanks Tim. Useful examples, especially for beginners like me

  • @davidiswhat
    @davidiswhat Před 3 lety

    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.

  • @hasnaouiacademy7899
    @hasnaouiacademy7899 Před 3 lety

    Tim, you are the best teacher on youtube.
    If you can make a data structure course, this will be helpful.
    thank you.

  • @zsobraal
    @zsobraal Před 3 lety +69

    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 Před 3 lety +1

      atan2 also allows to skip the quadrant selection below the atan call

    • @MrBanarium
      @MrBanarium Před 2 lety

      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 Před rokem

      @@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 Před rokem

      @@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 Před rokem

      @@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 Před 3 lety +8

    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.

  • @rishabhmishra2249
    @rishabhmishra2249 Před 3 lety +5

    Thanks Tim! I just realised how bad my code was :)

  • @itaychechik5125
    @itaychechik5125 Před 3 lety +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 :)

  • @rogercheng1294
    @rogercheng1294 Před 3 lety +9

    15:50 also forgot to pass golf_ball as parameter in redraw_window().
    btw, great video :)

  • @raghavareddychilakala657

    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 Před 3 lety

      Thank youtube Algorithms 😁 Tim had nothing to do with it

  • @chickenjoy
    @chickenjoy Před 3 lety +17

    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 Před 2 lety

      @@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 Před 2 lety +1

      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 Před rokem

    Loved the video and the resources! Thanks for sharing

  • @harshprajapati9686
    @harshprajapati9686 Před 3 lety

    Loved this man! Thanks🙌

  • @armsjarbc8597
    @armsjarbc8597 Před 3 lety

    Keep up the good work Mr. Tim

  • @atomgutan8064
    @atomgutan8064 Před 3 lety +1

    Very good video! Thanks!

  • @michielboswijk7260
    @michielboswijk7260 Před 3 lety +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.

  • @hamkoqaasim7177
    @hamkoqaasim7177 Před 3 lety

    Thanks you taught me a lot of things

  • @mahanaatma910
    @mahanaatma910 Před 3 lety

    thank you for this video it helped me a lot

  • @enriquellerena4779
    @enriquellerena4779 Před 3 lety

    Thanks for the vid, it helps a lot

  • @maxpoppe
    @maxpoppe Před 3 lety

    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.

  • @emaddeve20
    @emaddeve20 Před 3 lety

    This video is so helpful.

  • @FritsvanDoorn
    @FritsvanDoorn Před 2 lety

    Interesting. Thank you

  • @fredericoamigo
    @fredericoamigo Před 3 lety

    Super helpful vid!

  • @mohakbajaj4235
    @mohakbajaj4235 Před 3 lety +17

    Well on the context of cleaning the code he have to debug it too 😂😂 as he created some errors while cleaning

  • @markmadhukar9011
    @markmadhukar9011 Před 3 lety

    Gr8 vid as usual : )

  • @awwabasad1117
    @awwabasad1117 Před 3 lety

    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!😎😇👍✌️😸

  • @The0Koller
    @The0Koller Před 3 lety +1

    Wonderful video, I wonder if you can discuss a better way to address "if elif" and "if if" blocks

  • @muhammadmustafa3158
    @muhammadmustafa3158 Před 3 lety

    good stuff tim !

  • @paulosullivan3472
    @paulosullivan3472 Před 3 lety +1

    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 Před 2 lety

      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.

  • @juliansteden2980
    @juliansteden2980 Před 3 lety +9

    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.

  • @user-rz7mx8ns9n
    @user-rz7mx8ns9n Před 3 lety

    thanks bro 👍🙂

  • @TD-ph3wb
    @TD-ph3wb Před 3 lety +1

    Hey Tim, one question, what made you use Sublime Text instead of VS Code? Great video btw!

  • @cambridgebreaths3581
    @cambridgebreaths3581 Před 3 lety

    Excellent

  • @itsahmd295
    @itsahmd295 Před 3 lety +1

    You're like telling me i have clean code, Thanks man Lol

  • @eversonmay
    @eversonmay Před 2 lety

    More clean code videos!

  • @revolutionizer0099
    @revolutionizer0099 Před 3 lety

    fabulous

  • @Flashxyz123
    @Flashxyz123 Před 3 lety

    Yeah i put notifications on 😎

  • @BGxBlagiw
    @BGxBlagiw Před 3 lety

    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 🙃✌

  • @RomIlay
    @RomIlay Před 3 lety

    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

  • @injector6926
    @injector6926 Před 3 lety +4

    Best programming chanellll

  • @frankanon798
    @frankanon798 Před 3 lety

    Perhaps consider demonstrating mypy (with type hinting) and flake8 from the command line. These are very powerful tools.

    • @frankanon798
      @frankanon798 Před 3 lety

      But really great work giving some ideas about how to refractor code!

  • @bhavdeepsaragadam
    @bhavdeepsaragadam Před 3 lety +2

    Nice vid, Which video editor do you use??

  • @romandang3903
    @romandang3903 Před rokem

    Thanks for an explaination Tim. I like a theme you using in your vscode. Can you share a name of theme Tim?

  • @bigtymer4862
    @bigtymer4862 Před 3 lety +7

    Make some rust tutorials

  • @ibrahimkabeer5089
    @ibrahimkabeer5089 Před 3 lety

    Cool

  • @220SouthlandAve
    @220SouthlandAve Před 5 měsíci

    Beyond the Basic Stuff with Python: Best Practices for Writing Clean Code (by Al Sweigart) is a really good book for this.

  • @credoboyofficial
    @credoboyofficial Před 3 lety

    It works 100%

  • @gradientO
    @gradientO Před 3 lety +2

    Any book recommendations?

  • @dzbicegaming2583
    @dzbicegaming2583 Před 3 lety

    What text editor or ide are you using?

  • @leztat3183
    @leztat3183 Před 3 lety +3

    Yei ;)

  • @penn_asc
    @penn_asc Před 2 lety

    Beginner here. Is commenting on the code would be seen as bad coding practice? And if not necessarily, what is considered good commenting?

  • @wgalloPT
    @wgalloPT Před 3 lety

    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...

  • @Cookie-mv2hg
    @Cookie-mv2hg Před 3 lety

    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 Před 2 lety

      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.

  • @MatrixAbuz17
    @MatrixAbuz17 Před 10 měsíci

    9:50 doesnt multiple returned values already get returned as a tuple? I always assumed putting parenthesis was more for just prettier code.

  • @user-hd8tg4em2n
    @user-hd8tg4em2n Před 2 lety +1

    The return on line 33 wasn't changed to reflect the new variable names.

    • @antmitchell9930
      @antmitchell9930 Před 2 lety

      And the program was not run afterwards - Bad Tim, Bad. Love the channel

  • @binaprajapati7709
    @binaprajapati7709 Před 3 lety

    What's this new theme?
    It's cool!

  • @lakshyapandey7869
    @lakshyapandey7869 Před 3 lety +2

    Who is your illustrator who draws the thumbnails ?

    • @devb8820
      @devb8820 Před 3 lety +1

      they dont draw the thumbnails, they make it with software

  • @javierpadillah
    @javierpadillah Před rokem

    What program is he using to use python? For example, is it Spyder or what is it?

  • @shawnbeans7389
    @shawnbeans7389 Před 3 lety

    did you get a editor ?

  • @rubencid2575
    @rubencid2575 Před 3 lety +1

    One question: in the main loop, don't you need to see first events then movement and visualization?

  • @shawnbeans7389
    @shawnbeans7389 Před 3 lety

    you should try vim, trust me

  • @talkingbirb2808
    @talkingbirb2808 Před rokem

    I suppose all those missing white spaces and amount of empty lines between functions could be handled with something like autopep8, black or yapf

  • @aim2986
    @aim2986 Před 2 lety +3

    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 Před 2 lety

      @@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.

  • @hrushikeshthorat1075
    @hrushikeshthorat1075 Před 3 měsíci

    11:54 you forget to replace (0,0,0) by BLACK on line 21

  • @chrishaselden
    @chrishaselden Před 2 lety

    @20:27 could you do: and !shoot

  • @user-nc3rc7sk9p
    @user-nc3rc7sk9p Před rokem

    Why not use an ENUM for colours?

  • @user-wc1sm8cj8s
    @user-wc1sm8cj8s Před 3 lety

    I clicked this video and then..... "Do you wanna become a software engineer at Google?"
    Me: .....

  • @MrBoooniek
    @MrBoooniek Před 3 lety

    19:56 couldn't You put "if not shoot:" up in the "if event.type == pygame.MOUSEBUTTONDOWN and not shoot:" like that?

    • @elpython3471
      @elpython3471 Před 3 lety

      Yes, you could do that. He might have not done that because it's more confusing to read.

  • @mat4x
    @mat4x Před 3 lety +3

    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 Před rokem

      better to do a proper ternary operator one line if-else statement:
      greeting = 1
      print("Hello" if greeting else "Bye")

  • @willemvdk4886
    @willemvdk4886 Před 3 lety

    Tuple decomposition? Isn't it called unpacking? :)

  • @soupnoodles
    @soupnoodles Před 3 lety +2

    For most of these you couda just ran this in pycharm and it would have listed out all the format errors ;-;

  • @invizii2645
    @invizii2645 Před 3 lety

    This is why you need a linter.

  • @d3stinYwOw
    @d3stinYwOw Před 3 lety

    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 :)

  • @johannkrauter
    @johannkrauter Před 3 lety

    Check Out the Python black package which helps you to clean code automatically

  • @PaulTheEldritchCat
    @PaulTheEldritchCat Před 2 lety

    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).

  • @stephenaustin3026
    @stephenaustin3026 Před 3 lety +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.

  • @Soljarag5
    @Soljarag5 Před 3 lety +1

    I like camel case way better.... Not sure why python decided to use shake

  • @kinfi4836
    @kinfi4836 Před 3 lety

    `import math` should be before `import pygame`, just in case you wanna follow the PEP 8

  • @scriptles
    @scriptles Před 9 měsíci

    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  Před 9 měsíci

      its what's listed in the PEP8 style guide, not my opinion, pythons style guide...

    • @scriptles
      @scriptles Před 9 měsíci

      @@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.

  • @peddiyuvaraj688
    @peddiyuvaraj688 Před 3 lety +1

    In line 25 you did not change (0, 0, 0) to BLACK :D

  • @_L30N74
    @_L30N74 Před 2 lety

    You forgot to replace the (0,0,0) at line 25 with the constant BLACK you created.

  • @Skeap11
    @Skeap11 Před 3 lety

    redraw_window missing 2 positional arguments :)

  • @KeithKazamaFlick
    @KeithKazamaFlick Před rokem

    comments are useful

  • @vvhitevvabbit6479
    @vvhitevvabbit6479 Před rokem

    Forgot to pass the new golf_ball variable when calling the find_angle fuction.

  • @trillionthcousinofastone7024

    I will never leave camel and pascal case

  • @michealhall7776
    @michealhall7776 Před 3 lety

    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.

  • @georges.9545
    @georges.9545 Před 3 lety +1

    Great and helpful video, could you do a series on creating dapps on the ethereum blockchain?

  • @dpxprhulc4xkl
    @dpxprhulc4xkl Před rokem

    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 Před 3 lety

    Hi

  • @IndellableHatesHandles

    Snake case for functions? That looks a bit ugly.

  • @adarshsaurabh7871
    @adarshsaurabh7871 Před 3 lety

    You just made it harder for a begineer to understand 😂

  • @tcgvsocg1458
    @tcgvsocg1458 Před 3 lety

    Well i just finish 12 hour video when is the new one?