5 tips for CLEAN Python code

Sdílet
Vložit
  • čas přidán 22. 08. 2024

Komentáře • 16

  • @pythonwithjames
    @pythonwithjames Před 2 měsíci +1

    I really agree with the idea of splitting up complex functions, makes testing a lot easier too!

    • @Carberra
      @Carberra  Před 2 měsíci +1

      Oh yeah testing for sure. There is actually something called cyclomatic complexity that can be used to measure the complexity of a piece of code. I intentionally chose to not mention it, but now kinda wish I had. Oh well lmao.

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

    Good stuff, one rule I have is to never use classes unless you have mutable data where you need to track it's state. Even then you may not need a class. It's easier to test, debug, and maintain function vs classes.

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

      Thank you! Honestly that's a pretty good rule.

    • @largewallofbeans9812
      @largewallofbeans9812 Před 2 měsíci +1

      I must disagree with you on this. Using classes means that you can handle a bunch of objects that have predefined operations rather than big if-elif trees with the same operations that may take a while to select. It's hard to explain in writing but in the project I'm working on, it makes performance slightly better.

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

      @@largewallofbeans9812if you are worried about performance you are using the wrong language

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

      Classes allow for dependency inflection, and therefore better testing

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

    Thanks, I like your practicality!

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

    Good stuff and you got me idea on how to write the clean code. I have a request, can you make a view on your VS code setup/cnfiguration?

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

      Thank you! And I already have! There's a link in the description.

  • @KavyanshKhaitan
    @KavyanshKhaitan Před 2 měsíci +1

    At 3:16
    In my opinion, shifting the return False to the next line makes it less readable, and it should stay in an else block.
    BUT, the part after that makes it more readable.

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

      Yeah it wasn't the best example for that specifically, but I just wanted to show off that's generally how it would work. It would work best where there were multiple negative cases you needed to pick off.

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

      @@squishy-tomato yeah thats prob why.
      Since I never read code in that manner, it looks wierd.

  • @synchro-dentally1965
    @synchro-dentally1965 Před 2 měsíci

    "y" no love?